File: FileContent.h

package info (click to toggle)
arb 6.0.6-8
  • links: PTS, VCS
  • area: non-free
  • in suites: sid, trixie
  • size: 66,204 kB
  • sloc: ansic: 394,911; cpp: 250,290; makefile: 19,644; sh: 15,879; perl: 10,473; fortran: 6,019; ruby: 683; xml: 503; python: 53; awk: 32
file content (50 lines) | stat: -rw-r--r-- 1,479 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// ============================================================= //
//                                                               //
//   File      : FileContent.h                                   //
//   Purpose   :                                                 //
//                                                               //
//   Coded by Ralf Westram (coder@reallysoft.de) in April 2012   //
//   Institute of Microbiology (Technical University Munich)     //
//   http://www.arb-home.de/                                     //
//                                                               //
// ============================================================= //

#ifndef FILECONTENT_H
#define FILECONTENT_H

#ifndef ARB_STRARRAY_H
#include "arb_strarray.h"
#endif

class FileBuffer;

class FileContent : virtual Noncopyable {
    // provides simple load/modify/save for textfiles
    // (accepts any LF-variant)
    
    char     *path;
    GB_ERROR  error;
    StrArray  Lines;

    void init();

public:
    FileContent(const char *path_) : path(strdup(path_)), error(NULL) { init(); }
    ~FileContent() { free(path); }

    GB_ERROR has_error() const { return error; }

    StrArray& lines() { // intended to be modified
        arb_assert(!has_error());
        return Lines;
    }

    GB_ERROR save();
    GB_ERROR saveAs(const char *path_) { freedup(path, path_); return save(); }
};


#else
#error FileContent.h included twice
#endif // FILECONTENT_H