]> git.tdb.fi Git - libs/datafile.git/blob - source/statement.h
Move the definition of Input's operator bool to the header
[libs/datafile.git] / source / statement.h
1 #ifndef MSP_DATAFILE_STATEMENT_H_
2 #define MSP_DATAFILE_STATEMENT_H_
3
4 #include <list>
5 #include "mspdatafile_api.h"
6 #include "value.h"
7
8 namespace Msp {
9 namespace DataFile {
10
11 struct Token;
12
13 struct MSPDATAFILE_API Statement
14 {
15         typedef std::vector<Value> Arguments;
16
17         std::string keyword;
18         Arguments args;
19         bool valid = false;
20         bool control = false;
21         std::string source;
22         unsigned line = 0;
23         std::list<Statement> sub;
24
25         Statement() = default;
26         Statement(const std::string &);
27         std::string get_location() const;
28         std::string get_signature() const;
29         
30         template<typename T>
31         Statement &append(const T &v)
32         {
33                 args.push_back(v);
34                 return *this;
35         }
36
37         Statement &append_from_token(const Token &);
38
39         template<typename T>
40         Statement &operator,(const T &v)
41         { return append(v); }
42 };
43
44 struct StatementKey
45 {
46         std::string keyword;
47         std::string signature;
48
49         StatementKey() = default;
50         StatementKey(const std::string &k, const std::string &s): keyword(k), signature(s) { }
51
52         bool operator<(const StatementKey &o) const
53         { return keyword<o.keyword || (keyword==o.keyword && signature<o.signature); }
54 };
55
56 struct StatementInfo
57 {
58         StatementKey key;
59         std::size_t args_size = 0;
60         std::vector<std::size_t> arg_offsets;
61
62         StatementInfo() = default;
63         StatementInfo(const std::string &, const std::string &);
64 };
65
66 } // namespace DataFile
67 } // namespace Msp
68
69 #endif