]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/value.h
Add files
[libs/datafile.git] / source / value.h
diff --git a/source/value.h b/source/value.h
new file mode 100644 (file)
index 0000000..dc117e0
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+This file is part of libmspparser
+Copyright © 2006 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+#ifndef MSP_PARSER_VALUE_H_
+#define MSP_PARSER_VALUE_H_
+
+#include <sstream>
+#include <string>
+#include <vector>
+
+namespace Msp {
+namespace Parser {
+
+class Value
+{
+public:
+       enum Type
+       {
+               INTEGER,
+               FLOAT,
+               STRING,
+               BOOLEAN
+       };
+
+       Value(Type t, const std::string &d): type(t), data(d) { }
+       template<typename T>
+       T get() const
+       {
+               std::istringstream ss(data);
+               T result;
+               ss>>result;
+               if(ss.fail())
+                       throw TypeError("Type mismatch");
+               return result;
+       }
+private:
+       Type type;
+       std::string data;
+};
+typedef std::vector<Value> ValueArray;
+
+} // namespace Parser
+} // namespace Msp
+
+#endif