]> git.tdb.fi Git - libs/datafile.git/blob - source/statement.cpp
More efficient way of loading binary files
[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         line(0)
13 { }
14
15 Statement::Statement(const string &kw):
16         keyword(kw),
17         valid(true),
18         line(0)
19 { }
20
21 string Statement::get_location() const
22 {
23         string result = source;
24         if(line)
25                 result += format(":%d", line);
26         return result;
27 }
28
29 string Statement::get_signature() const
30 {
31         string result;
32         for(Arguments::const_iterator i = args.begin(); i!=args.end(); ++i)
33                 result += i->get_signature();
34         return result;
35 }
36
37
38 StatementInfo::StatementInfo():
39         args_size(0)
40 { }
41
42 StatementInfo::StatementInfo(const string &k, const string &s):
43         key(k, s),
44         args_size(0)
45 {
46         for(string::const_iterator i=key.signature.begin(); i!=key.signature.end(); ++i)
47         {
48                 arg_offsets.push_back(args_size);
49                 switch(*i)
50                 {
51                 case IntType::signature:
52                         args_size += sizeof(IntType::Store);
53                         break;
54                 case FloatType::signature:
55                         args_size += sizeof(FloatType::Store);
56                         break;
57                 case BoolType::signature:
58                         args_size += sizeof(BoolType::Store);
59                         break;
60                 case StringType::signature:
61                         args_size += sizeof(StringType::Store);
62                         break;
63                 case SymbolType::signature:
64                         args_size += sizeof(SymbolType::Store);
65                         break;
66                 }
67         }
68 }
69
70 } // namespace DataFile
71 } // namespace Msp