ARB
parser.h
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : parser.h //
4 // Purpose : //
5 // //
6 // =============================================================== //
7 
8 #ifndef PARSER_H
9 #define PARSER_H
10 
11 #ifndef READER_H
12 #include "reader.h"
13 #endif
14 
15 
16 class Parser : virtual Noncopyable {
17 protected:
19  Seq& seq;
21 
22 public:
23  Parser(Seq& seq_, Reader& reader_)
24  : state(ENTRY_NONE),
25  seq(seq_),
26  reader(reader_)
27  {}
28  virtual ~Parser() {}
29 
31  state = ENTRY_NONE;
32 
33  for (; reader.line() && state != ENTRY_COMPLETED;) {
34  if (!has_content(reader.line())) { ++reader; continue; } // skip empty lines
35 
36  parse_section();
37  }
38 
39  if (state == ENTRY_STARTED) throw_incomplete_entry();
40  ++reader;
41 
42  seq.set_id(get_data().get_id());
43  return state == ENTRY_COMPLETED;
44  }
45 
46  virtual void parse_section() = 0;
47  virtual const InputFormat& get_data() const = 0;
48 };
49 
50 
51 #else
52 #error parser.h included twice
53 #endif // PARSER_H
Definition: reader.h:21
virtual ~Parser()
Definition: parser.h:28
EntryState state
Definition: parser.h:18
void throw_incomplete_entry()
Definition: fconv.cxx:43
CONSTEXPR_INLINE bool has_content(const char *field)
Definition: global.h:127
Parser(Seq &seq_, Reader &reader_)
Definition: parser.h:23
Seq & seq
Definition: parser.h:19
Definition: seq.h:43
EntryState
Definition: defs.h:35
Reader & reader
Definition: parser.h:20
virtual const InputFormat & get_data() const =0
virtual void parse_section()=0
#define __ATTR__USERESULT
Definition: attributes.h:58
bool parse_entry() __ATTR__USERESULT
Definition: parser.h:30
const char * line() const
Definition: reader.h:43
void set_id(const char *id_)
Definition: seq.h:84