]> git.donarmstrong.com Git - lilypond.git/blob - flower/lib/include/text-db.hh
3535a84f8f42de1f0b1ffefe45e93017702fe232
[lilypond.git] / flower / lib / include / text-db.hh
1 #ifndef TEXTDB_HH
2 #define TEXTDB_HH
3
4 #include "data-file.hh"
5
6 /**a "const" Array. Contents can't be changed. do "#" comments, read quote enclosed  fields */
7
8 class Text_record : Array<String>  
9 {
10     int line_no;
11     String filename;
12     
13 public:
14     Text_record() { } // needed because of other ctor
15
16     /// report an error in this line.
17     message(String s) {
18         cerr << '\n'<< filename << ": "<< line_no << s << "\n";
19     }          
20     String operator[](int j) {
21         return Array<String>::operator[](j);
22     }
23
24     Text_record(Array<String> s, String fn, int j) : Array<String>(s) { 
25         filename = fn; line_no = j; 
26     }
27     Array<String>::size;           
28 };
29
30 /** abstraction for a datafile.
31     add a subrec/fieldsep/record separator
32     */
33
34 class Text_db : private Data_file
35 {
36     void gobble_leading_white();
37 public:
38     /// get a line with records
39     Text_record    get_record();
40
41     Text_db(String fn):Data_file(fn) { }
42     Data_file::error;
43     bool eof();
44
45     /// get next line.
46     Text_record operator++(int) {
47         return get_record();
48     }
49     /// are we done yet?
50     operator bool() {
51         return !eof();
52     }
53 };
54
55 #endif