summaryrefslogtreecommitdiff
path: root/project2/variables.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/variables.cpp')
-rw-r--r--project2/variables.cpp91
1 files changed, 77 insertions, 14 deletions
diff --git a/project2/variables.cpp b/project2/variables.cpp
index 32a1a15..c5907ed 100644
--- a/project2/variables.cpp
+++ b/project2/variables.cpp
@@ -3,7 +3,6 @@
#include "appEngine.h"
#include "session.h"
#include "rowUser.h"
-#include "genericVisitor.h"
#include <libxml++/nodes/textnode.h>
#include <stdexcept>
#include <boost/tokenizer.hpp>
@@ -11,30 +10,94 @@
#include <boost/algorithm/string/predicate.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
class UnknownVariableType : public std::exception { };
class UnknownVariableSource : public std::exception { };
class NoVariableDefinition : public std::exception { };
+enum VT_typeID {
+ DefaultType,
+ StringPtr,
+ String,
+ Int,
+ UInt,
+ LInt,
+ LUInt,
+ LLInt,
+ LLUInt,
+ Float,
+ Double,
+ DateTime,
+ DateTimePtr,
+};
+
static
VariableType
-makeVariableType(const Glib::ustring & src, const std::string & type, const std::string & format = std::string())
+makeVariableType(const Glib::ustring & src, const std::string & type, const VT_typeID format = DefaultType)
{
- if (type == "stringptr" || type.empty()) return boost::shared_ptr<Glib::ustring>(new Glib::ustring(src));
- if (type == "string") return src;
- if (type == "int") return boost::lexical_cast<int>(src);
- if (type == "uint") return boost::lexical_cast<unsigned int>(src);
- if (type == "lint") return boost::lexical_cast<long int>(src);
- if (type == "luint") return boost::lexical_cast<long unsigned int>(src);
- if (type == "llint") return boost::lexical_cast<long long int>(src);
- if (type == "lluint") return boost::lexical_cast<long long unsigned int>(src);
- if (type == "float") return boost::lexical_cast<float>(src);
- if (type == "double") return boost::lexical_cast<double>(src);
- if (type == "datetime") return boost::posix_time::time_from_string(src);
- if (type == "datetimeptr") return boost::shared_ptr<boost::posix_time::ptime>(new boost::posix_time::ptime(boost::posix_time::time_from_string(src)));
+ switch (format) {
+ case DefaultType:
+ case StringPtr:
+ return boost::shared_ptr<Glib::ustring>(new Glib::ustring(src));
+ case String:
+ return src;
+ case Int:
+ return boost::lexical_cast<int>(src);
+ case UInt:
+ return boost::lexical_cast<unsigned int>(src);
+ case LInt:
+ return boost::lexical_cast<long int>(src);
+ case LUInt:
+ return boost::lexical_cast<long unsigned int>(src);
+ case LLInt:
+ return boost::lexical_cast<long long int>(src);
+ case LLUInt:
+ return boost::lexical_cast<long long unsigned int>(src);
+ case Float:
+ return boost::lexical_cast<float>(src);
+ case Double:
+ return boost::lexical_cast<double>(src);
+ case DateTime:
+ return boost::posix_time::time_from_string(src);
+ case DateTimePtr:
+ return boost::shared_ptr<boost::posix_time::ptime>(new boost::posix_time::ptime(boost::posix_time::time_from_string(src)));
+ }
throw UnknownVariableType();
}
+VariableType::VariableType() :
+ _VT(),
+ convertCache(NULL),
+ freer(NULL)
+{
+}
+
+VariableType::VariableType(const VariableType & vt) :
+ _VT(*((const _VT *)&vt)),
+ convertCache(NULL),
+ freer(NULL)
+{
+}
+
+VariableType::~VariableType()
+{
+ if (freer && convertCache) {
+ freer(convertCache);
+ }
+}
+
+void
+VariableType::operator=(const VariableType & vt)
+{
+ if (freer && convertCache) {
+ freer(convertCache);
+ }
+ freer = NULL;
+ convertCache = NULL;
+ _VT::operator=(*((const _VT *)&vt));
+}
+
class VariableLiteral : public VariableImpl {
public:
VariableLiteral(const Glib::ustring & src, const std::string & type = std::string()) :