diff options
-rw-r--r-- | project2/common/variables.cpp | 57 | ||||
-rw-r--r-- | project2/common/variables.h | 31 |
2 files changed, 68 insertions, 20 deletions
diff --git a/project2/common/variables.cpp b/project2/common/variables.cpp index 74bdecd..a3669aa 100644 --- a/project2/common/variables.cpp +++ b/project2/common/variables.cpp @@ -8,6 +8,7 @@ #include "rowSet.h" #include <libxml++/nodes/textnode.h> #include <stdexcept> +#include <boost/numeric/conversion/cast.hpp> #include <boost/foreach.hpp> #include <boost/algorithm/string/predicate.hpp> #include <boost/function.hpp> @@ -24,6 +25,10 @@ Null::operator<(const Null &) const return false; } +Boolean::Boolean(bool v) : value(v) +{ +} + bool Boolean::operator<(const Boolean & b) const { @@ -118,15 +123,53 @@ VariableType::VariableType() : { } -VariableType::VariableType(char * t) : - _VT(Glib::ustring(t)), - convertCache(NULL), - freer(NULL) -{ +#define VTCONS(Source) \ +VariableType::VariableType(const Source & t) : \ + _VT(t), \ + convertCache(NULL), \ + freer(NULL) \ +{ \ +} +#define VTCONSD(Source, Store) \ +VariableType::VariableType(const Source & t) : \ + _VT(Store(t)), \ + convertCache(NULL), \ + freer(NULL) \ +{ \ +} +#define VTCONSC(Source, Store, Cast) \ +VariableType::VariableType(const Source & t) : \ + _VT(Store((Cast)t)), \ + convertCache(NULL), \ + freer(NULL) \ +{ \ } +#define VTCONSN(Source, Store) \ +VariableType::VariableType(const Source & t) : \ + _VT(boost::numeric_cast<Store>(t)), \ + convertCache(NULL), \ + freer(NULL) \ +{ \ +} + +VTCONS(Null); +VTCONS(boost::posix_time::ptime); +VTCONS(Glib::ustring); +VTCONSD(bool, Boolean); +VTCONSN(float, double); +VTCONSN(double, double); +VTCONSN(int, int64_t); +VTCONSN(unsigned int, int64_t); +VTCONSN(long int, int64_t); +VTCONSN(long unsigned int, int64_t); +VTCONSN(long long int, int64_t); +VTCONSN(long long unsigned int, int64_t); +VTCONSD(std::string, Glib::ustring); +VTCONSD(char * const, Glib::ustring); +VTCONSC(unsigned char * const, Glib::ustring, const char * const); -VariableType::VariableType(const char * t) : - _VT(Glib::ustring(t)), +VariableType::VariableType(const struct tm & vt) : + _VT(boost::posix_time::ptime_from_tm(vt)), convertCache(NULL), freer(NULL) { diff --git a/project2/common/variables.h b/project2/common/variables.h index 84715d4..e42de0c 100644 --- a/project2/common/variables.h +++ b/project2/common/variables.h @@ -25,6 +25,7 @@ class Boolean { operator bool() const; bool value; }; + std::basic_ostream<char> & operator<<(std::basic_ostream<char> &, const Boolean &); std::basic_ostream<unsigned char> & operator<<(std::basic_ostream<unsigned char> &, const Boolean &); @@ -35,16 +36,8 @@ typedef boost::variant< // Strings Glib::ustring, // Numbers - long long unsigned int, - long unsigned int, - unsigned int, - short unsigned int, - long long int, - long int, - int, - short int, + int64_t, double, - float, // Date and Times boost::posix_time::ptime > _VT; @@ -52,10 +45,22 @@ typedef boost::variant< class VariableType : public _VT { public: typedef void(*Freer)(const void*); - VariableType(char * t); - VariableType(const char * t); - template<typename T> - VariableType(const T & t) : _VT(t), convertCache(NULL), freer(NULL) { } + VariableType(const unsigned char * const & t); + VariableType(const char * const & t); + VariableType(const std::string &); + VariableType(const Glib::ustring &); + VariableType(const struct tm &); + VariableType(const boost::posix_time::ptime &); + VariableType(const Null &); + VariableType(const bool &); + VariableType(const int &); + VariableType(const unsigned int &); + VariableType(const long int &); + VariableType(const long unsigned int &); + VariableType(const long long int &); + VariableType(const long long unsigned int &); + VariableType(const float &); + VariableType(const double &); VariableType(); VariableType(const VariableType &); ~VariableType(); |