]> git.tdb.fi Git - libs/datafile.git/blob - source/statement.cpp
b1ff05826e314441fd3e93ced8c5117f295b5824
[libs/datafile.git] / source / statement.cpp
1 #include <msp/strings/format.h>
2 #include "statement.h"
3 #include "type.h"
4
5 using namespace std;
6
7 namespace Msp {
8 namespace DataFile {
9
10 Statement::Statement():
11         valid(false),
12         control(false),
13         line(0)
14 { }
15
16 Statement::Statement(const string &kw):
17         keyword(kw),
18         valid(true),
19         control(!kw.compare(0, 2, "__")),
20         line(0)
21 { }
22
23 string Statement::get_location() const
24 {
25         string result = source;
26         if(line)
27                 result += format(":%d", line);
28         return result;
29 }
30
31 string Statement::get_signature() const
32 {
33         string result;
34         for(Arguments::const_iterator i = args.begin(); i!=args.end(); ++i)
35                 result += i->get_signature();
36         return result;
37 }
38
39
40 StatementInfo::StatementInfo():
41         args_size(0)
42 { }
43
44 StatementInfo::StatementInfo(const string &k, const string &s):
45         key(k, s),
46         args_size(0)
47 {
48         for(string::const_iterator i=key.signature.begin(); i!=key.signature.end(); ++i)
49         {
50                 arg_offsets.push_back(args_size);
51                 switch(*i)
52                 {
53                 case IntType::signature:
54                         args_size += sizeof(IntType::Store);
55                         break;
56                 case FloatType::signature:
57                         args_size += sizeof(FloatType::Store);
58                         break;
59                 case BoolType::signature:
60                         args_size += sizeof(BoolType::Store);
61                         break;
62                 case StringType::signature:
63                         args_size += sizeof(StringType::Store);
64                         break;
65                 case SymbolType::signature:
66                         args_size += sizeof(SymbolType::Store);
67                         break;
68                 }
69         }
70 }
71
72 } // namespace DataFile
73 } // namespace Msp