summaryrefslogtreecommitdiff
path: root/flower/textdb.hh
blob: bea0c4521e449189a749571a7817722a45b8ae7b (about) (plain)
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
51
52
53
54
55
56
57
#ifndef TEXTDB_HH
#define TEXTDB_HH

#include "textstr.hh"

/**: do "#" comments, read quote enclosed  fields */

/// a "const" svec. Contents can't be changed.
class Text_record : svec<String>  
{
    int line_no;
    String filename;
    
public:
    Text_record() { } // needed because of other ctor

    /// report an error in this line.
    message(String s) {
	cerr << '\n'<< filename << ": "<< line_no << s << "\n";
    }	       
    String operator[](int j) {
	return svec<String>::operator[](j);
    }

    Text_record(svec<String> s, String fn, int j) : svec<String>(s) { 
	filename = fn; line_no = j; 
    }
    svec<String>::sz;           
};

/// abstraction for a datafile
class Text_db : private Data_file
{
    void gobble_leading_white();
public:
    /// get a line with records
    Text_record    get_record();

    Text_db(String fn):Data_file(fn) { }
    Data_file::error;
    bool eof();

    /// get next line.
    Text_record operator++(int) {
	return get_record();
    }
    /// are we done yet?
    operator bool() {
	return !eof();
    }
};


/**
    add a subrec/fieldsep/record separator
    */
#endif