]> git.tdb.fi Git - libs/datafile.git/blob - source/statement.h
184ef9955cbc78af80231eabda307bb45605be54
[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         bool control;
19         std::string source;
20         unsigned line;
21         std::list<Statement> sub;
22
23         Statement();
24         Statement(const std::string &);
25         std::string get_location() const;
26         std::string get_signature() const;
27         
28         template<typename T>
29         Statement &append(const T &v)
30         {
31                 args.push_back(v);
32                 return *this;
33         }
34
35         template<typename T>
36         Statement &operator,(const T &v)
37         { return append(v); }
38 };
39
40 struct StatementKey
41 {
42         std::string keyword;
43         std::string signature;
44
45         StatementKey() { }
46         StatementKey(const std::string &k, const std::string &s): keyword(k), signature(s) { }
47
48         bool operator<(const StatementKey &o) const
49         { return keyword<o.keyword || (keyword==o.keyword && signature<o.signature); }
50 };
51
52 struct StatementInfo
53 {
54         StatementKey key;
55         unsigned args_size;
56         std::vector<unsigned> arg_offsets;
57
58         StatementInfo();
59         StatementInfo(const std::string &, const std::string &);
60 };
61
62 } // namespace DataFile
63 } // namespace Msp
64
65 #endif