| Line | |
|---|
| 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 |
|---|
| 38 | arb_assert(!has_error()); |
|---|
| 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 | |
|---|
Note: See
TracBrowser
for help on using the repository browser.