ARB
FileContent.h
Go to the documentation of this file.
1 // ============================================================= //
2 // //
3 // File : FileContent.h //
4 // Purpose : //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in April 2012 //
7 // Institute of Microbiology (Technical University Munich) //
8 // http://www.arb-home.de/ //
9 // //
10 // ============================================================= //
11 
12 #ifndef FILECONTENT_H
13 #define FILECONTENT_H
14 
15 #ifndef ARB_STRARRAY_H
16 #include "arb_strarray.h"
17 #endif
18 
19 class FileBuffer;
20 
21 class FileContent : virtual Noncopyable {
22  // provides simple load/modify/save for textfiles
23  // (accepts any LF-variant)
24 
25  char *path;
26  GB_ERROR error;
27  StrArray Lines;
28 
29  void init();
30 
31 public:
32  FileContent(const char *path_) : path(ARB_strdup(path_)), error(NULp) { init(); }
33  ~FileContent() { free(path); }
34 
35  GB_ERROR has_error() const { return error; }
36 
37  StrArray& lines() { // intended to be modified
39  return Lines;
40  }
41 
42  GB_ERROR save();
43  GB_ERROR saveAs(const char *path_) { freedup(path, path_); return save(); }
44 };
45 
46 
47 #else
48 #error FileContent.h included twice
49 #endif // FILECONTENT_H
50 
#define arb_assert(cond)
Definition: arb_assert.h:245
const char * GB_ERROR
Definition: arb_core.h:25
StrArray & lines()
Definition: FileContent.h:37
GB_ERROR saveAs(const char *path_)
Definition: FileContent.h:43
char * ARB_strdup(const char *str)
Definition: arb_string.h:27
GB_ERROR save()
Definition: FileContent.cxx:35
FileContent(const char *path_)
Definition: FileContent.h:32
GB_ERROR has_error() const
Definition: FileContent.h:35
#define NULp
Definition: cxxforward.h:116