]> git.tdb.fi Git - libs/datafile.git/blob - source/value.h
Add files
[libs/datafile.git] / source / value.h
1 /*
2 This file is part of libmspparser
3 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
4 Distributed under the LGPL
5 */
6 #ifndef MSP_PARSER_VALUE_H_
7 #define MSP_PARSER_VALUE_H_
8
9 #include <sstream>
10 #include <string>
11 #include <vector>
12
13 namespace Msp {
14 namespace Parser {
15
16 class Value
17 {
18 public:
19         enum Type
20         {
21                 INTEGER,
22                 FLOAT,
23                 STRING,
24                 BOOLEAN
25         };
26
27         Value(Type t, const std::string &d): type(t), data(d) { }
28         template<typename T>
29         T get() const
30         {
31                 std::istringstream ss(data);
32                 T result;
33                 ss>>result;
34                 if(ss.fail())
35                         throw TypeError("Type mismatch");
36                 return result;
37         }
38 private:
39         Type type;
40         std::string data;
41 };
42 typedef std::vector<Value> ValueArray;
43
44 } // namespace Parser
45 } // namespace Msp
46
47 #endif