From 81d06ece0d59bdae5b68b4673336e2b9a0a882a3 Mon Sep 17 00:00:00 2001 From: randomdan Date: Fri, 2 Dec 2011 11:43:52 +0000 Subject: Remove excessive number of numeric type and correct implicit creation of booleans --- project2/common/variables.cpp | 57 +++++++++++++++++++++++++++++++++++++------ 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 #include +#include #include #include #include @@ -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(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 & operator<<(std::basic_ostream &, const Boolean &); std::basic_ostream & operator<<(std::basic_ostream &, 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 - 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(); -- cgit v1.2.3