]> git.tdb.fi Git - libs/datafile.git/blob - source/statement.h
Use a common StatementKey structure for Loader and BinaryParser/Writer
[libs/datafile.git] / source / statement.h
1 #ifndef MSP_DATAFILE_STATEMENT_H_
2 #define MSP_DATAFILE_STATEMENT_H_
3
4 #include <list>
5 #include "value.h"
6
7 namespace Msp {
8 namespace DataFile {
9
10 class Statement
11 {
12 public:
13         typedef std::vector<Value> Arguments;
14
15         std::string keyword;
16         Arguments args;
17         bool valid;
18         std::string source;
19         unsigned line;
20         std::list<Statement> sub;
21
22         Statement();
23         Statement(const std::string &);
24         std::string get_location() const;
25         std::string get_signature() const;
26         
27         template<typename T>
28         Statement &append(const T &v)
29         {
30                 args.push_back(v);
31                 return *this;
32         }
33
34         template<typename T>
35         Statement &operator,(const T &v)
36         { return append(v); }
37 };
38
39 struct StatementKey
40 {
41         std::string keyword;
42         std::string signature;
43
44         StatementKey() { }
45         StatementKey(const std::string &k, const std::string &s): keyword(k), signature(s) { }
46
47         bool operator<(const StatementKey &o) const
48         { return keyword<o.keyword || (keyword==o.keyword && signature<o.signature); }
49 };
50
51 } // namespace DataFile
52 } // namespace Msp
53
54 #endif