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