From 96f04ffc25c45330b7a9a242711120c2d8e9fab0 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 3 Feb 2016 20:22:30 -0500 Subject: [PATCH] Variant: C++11 --- src/Variant.cpp | 87 ++++++++++--------------------------------------- src/Variant.h | 18 +++++----- 2 files changed, 26 insertions(+), 79 deletions(-) diff --git a/src/Variant.cpp b/src/Variant.cpp index e4e9d3b4a..c99b31525 100644 --- a/src/Variant.cpp +++ b/src/Variant.cpp @@ -41,107 +41,57 @@ std::string Variant::dateFormat = ""; bool Variant::searchCaseSensitive = 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) -: _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) : _type (Variant::type_boolean) , _bool (value) -, _integer (0) -, _real (0.0) -, _string ("") -, _date (0) -, _duration (0) -, _source ("") { } //////////////////////////////////////////////////////////////////////////////// Variant::Variant (const int value) : _type (Variant::type_integer) -, _bool (false) , _integer (value) -, _real (0.0) -, _string ("") -, _date (0) -, _duration (0) -, _source ("") { } //////////////////////////////////////////////////////////////////////////////// Variant::Variant (const double value) : _type (Variant::type_real) -, _bool (false) -, _integer (0) , _real (value) -, _string ("") -, _date (0) -, _duration (0) -, _source ("") { } //////////////////////////////////////////////////////////////////////////////// Variant::Variant (const std::string& value) : _type (Variant::type_string) -, _bool (false) -, _integer (0) -, _real (0.0) , _string (value) -, _date (0) -, _duration (0) -, _source ("") { } //////////////////////////////////////////////////////////////////////////////// Variant::Variant (const char* value) : _type (Variant::type_string) -, _bool (false) -, _integer (0) -, _real (0.0) -, _string (std::string (value)) -, _date (0) -, _duration (0) -, _source ("") +, _string (value) { } //////////////////////////////////////////////////////////////////////////////// Variant::Variant (const time_t value, const enum type new_type) : _type (new_type) -, _bool (false) -, _integer (0) -, _real (0.0) -, _string ("") -, _date (0) -, _duration (0) -, _source ("") { switch (new_type) { @@ -167,17 +117,14 @@ const std::string& Variant::source () const //////////////////////////////////////////////////////////////////////////////// Variant& Variant::operator= (const Variant& other) { - if (this != &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; return *this; } diff --git a/src/Variant.h b/src/Variant.h index 1d516ea67..6bd2f425f 100644 --- a/src/Variant.h +++ b/src/Variant.h @@ -42,7 +42,7 @@ public: enum type {type_boolean, type_integer, type_real, type_string, type_date, type_duration}; - Variant (); + Variant () = default; Variant (const Variant&); Variant (const bool); Variant (const int); @@ -106,15 +106,15 @@ public: time_t get_duration () const; private: - enum type _type; - bool _bool; - int _integer; - double _real; - std::string _string; - time_t _date; - time_t _duration; + enum type _type {type_boolean}; + bool _bool {false}; + int _integer {0}; + double _real {0.0}; + std::string _string {""}; + time_t _date {0}; + time_t _duration {0}; - std::string _source; + std::string _source {""}; }; #endif