]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/value.cpp
Add files
[libs/datafile.git] / source / value.cpp
diff --git a/source/value.cpp b/source/value.cpp
new file mode 100644 (file)
index 0000000..8cb1af0
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+This file is part of libmspparser
+Copyright © 2006 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+#include <msp/error.h>
+#include <msp/strconv.h>
+#include "value.h"
+
+namespace Msp {
+namespace Parser {
+
+/*template<>
+unsigned Value::get<unsigned long>() const
+{
+       if(type!=INTEGER)
+               throw TypeError("Value is not an integer");
+       errno=0;
+       unsigned long result=strtoul(data);
+       if(errno==ERANGE
+       return result;
+}
+
+template<>
+unsigned Value::get<unsigned>() const
+{
+       if(type!=INTEGER)
+               throw TypeError("Value is not an integer");
+       return strtoul(data);
+}
+
+template<>
+unsigned Value::get<unsigned short>() const
+{
+       if(type!=INTEGER)
+               throw TypeError("Value is not an integer");
+       return strtoul(data);
+}
+
+template<>
+float Value::get<float>() const
+{
+       if(type!=FLOAT && type!=INTEGER)
+               throw TypeError("Value is not a float");
+       return strtod(data);
+}*/
+
+template<>
+std::string Value::get<std::string>() const
+{
+       if(type!=STRING)
+               throw TypeError("Value is not a string");
+       return data;
+}
+
+template<>
+const std::string &Value::get<const std::string&>() const
+{
+       if(type!=STRING)
+               throw TypeError("Value is not a string");
+       return data;
+}
+
+} // namespace Msp
+} // namespace Parser