Variant: C++11

This commit is contained in:
Paul Beckingham 2016-02-03 20:22:30 -05:00
parent f59e15185f
commit 96f04ffc25
2 changed files with 26 additions and 79 deletions

View file

@ -41,107 +41,57 @@ std::string Variant::dateFormat = "";
bool Variant::searchCaseSensitive = true; bool Variant::searchCaseSensitive = true;
bool Variant::searchUsingRegex = true; bool Variant::searchUsingRegex = true;
////////////////////////////////////////////////////////////////////////////////
Variant::Variant ()
: _type (type_boolean)
, _bool (false)
, _integer (0)
, _real (0.0)
, _string ("")
, _date (0)
, _duration (0)
, _source ("")
{
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Variant::Variant (const Variant& other) Variant::Variant (const Variant& other)
: _type (other._type)
, _bool (other._bool)
, _integer (other._integer)
, _real (other._real)
, _string (other._string)
, _date (other._date)
, _duration (other._duration)
, _source (other._source)
{ {
_type = other._type;
_bool = other._bool;
_integer = other._integer;
_real = other._real;
_string = other._string;
_date = other._date;
_duration = other._duration;
_source = other._source;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Variant::Variant (const bool value) Variant::Variant (const bool value)
: _type (Variant::type_boolean) : _type (Variant::type_boolean)
, _bool (value) , _bool (value)
, _integer (0)
, _real (0.0)
, _string ("")
, _date (0)
, _duration (0)
, _source ("")
{ {
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Variant::Variant (const int value) Variant::Variant (const int value)
: _type (Variant::type_integer) : _type (Variant::type_integer)
, _bool (false)
, _integer (value) , _integer (value)
, _real (0.0)
, _string ("")
, _date (0)
, _duration (0)
, _source ("")
{ {
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Variant::Variant (const double value) Variant::Variant (const double value)
: _type (Variant::type_real) : _type (Variant::type_real)
, _bool (false)
, _integer (0)
, _real (value) , _real (value)
, _string ("")
, _date (0)
, _duration (0)
, _source ("")
{ {
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Variant::Variant (const std::string& value) Variant::Variant (const std::string& value)
: _type (Variant::type_string) : _type (Variant::type_string)
, _bool (false)
, _integer (0)
, _real (0.0)
, _string (value) , _string (value)
, _date (0)
, _duration (0)
, _source ("")
{ {
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Variant::Variant (const char* value) Variant::Variant (const char* value)
: _type (Variant::type_string) : _type (Variant::type_string)
, _bool (false) , _string (value)
, _integer (0)
, _real (0.0)
, _string (std::string (value))
, _date (0)
, _duration (0)
, _source ("")
{ {
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Variant::Variant (const time_t value, const enum type new_type) Variant::Variant (const time_t value, const enum type new_type)
: _type (new_type) : _type (new_type)
, _bool (false)
, _integer (0)
, _real (0.0)
, _string ("")
, _date (0)
, _duration (0)
, _source ("")
{ {
switch (new_type) switch (new_type)
{ {
@ -167,8 +117,6 @@ const std::string& Variant::source () const
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Variant& Variant::operator= (const Variant& other) Variant& Variant::operator= (const Variant& other)
{ {
if (this != &other)
{
_type = other._type; _type = other._type;
_bool = other._bool; _bool = other._bool;
_integer = other._integer; _integer = other._integer;
@ -177,7 +125,6 @@ Variant& Variant::operator= (const Variant& other)
_date = other._date; _date = other._date;
_duration = other._duration; _duration = other._duration;
_source = other._source; _source = other._source;
}
return *this; return *this;
} }

View file

@ -42,7 +42,7 @@ public:
enum type {type_boolean, type_integer, type_real, type_string, type_date, type_duration}; enum type {type_boolean, type_integer, type_real, type_string, type_date, type_duration};
Variant (); Variant () = default;
Variant (const Variant&); Variant (const Variant&);
Variant (const bool); Variant (const bool);
Variant (const int); Variant (const int);
@ -106,15 +106,15 @@ public:
time_t get_duration () const; time_t get_duration () const;
private: private:
enum type _type; enum type _type {type_boolean};
bool _bool; bool _bool {false};
int _integer; int _integer {0};
double _real; double _real {0.0};
std::string _string; std::string _string {""};
time_t _date; time_t _date {0};
time_t _duration; time_t _duration {0};
std::string _source; std::string _source {""};
}; };
#endif #endif