-/*
-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>
+#ifndef MSP_DATAFILE_VALUE_H_
+#define MSP_DATAFILE_VALUE_H_
+
#include <vector>
+#include <msp/core/meta.h>
+#include <msp/core/variant.h>
+#include "type.h"
namespace Msp {
-namespace Parser {
+namespace DataFile {
class Value
{
+private:
+ char sig;
+ Variant data;
+
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;
- }
+ Value(T d):
+ sig(TypeInfo<T>::signature),
+ data(static_cast<typename TypeInfo<T>::Store>(d))
+ { }
+
+ Value(Symbol d): sig(TypeInfo<Symbol>::signature), data(d) { }
+
+ template<typename T>
+ typename RemoveReference<T>::Type get() const
+ { return get_<typename TypeInfo<T>::Store>(); }
+
+ char get_signature() const { return sig; }
private:
- Type type;
- std::string data;
+ template<typename T>
+ T get_() const;
};
-typedef std::vector<Value> ValueArray;
-} // namespace Parser
+typedef std::vector<Value> ValueArray __attribute__((deprecated));
+
+template<typename T>
+inline T Value::get_() const
+{
+ return data.value<typename TypeInfo<T>::Store>();
+}
+
+template<>
+inline FloatType::Store Value::get_<FloatType::Store>() const
+{
+ if(sig==IntType::signature)
+ return data.value<IntType::Store>();
+ else
+ return data.value<FloatType::Store>();
+}
+
+} // namespace DataFile
} // namespace Msp
#endif