From f91220c715b481999a6381b9c61b682719904457 Mon Sep 17 00:00:00 2001 From: tastytea Date: Tue, 10 Apr 2018 09:40:26 +0200 Subject: [PATCH] Found out about the mutable keyword! :-D --- src/easy/easy.hpp | 4 +--- src/easy/entity.cpp | 29 ++++++++++++++--------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/easy/easy.hpp b/src/easy/easy.hpp index 9ad425b..7018c6c 100644 --- a/src/easy/easy.hpp +++ b/src/easy/easy.hpp @@ -307,9 +307,7 @@ public: private: Json::Value _tree; bool _valid; - bool _was_set; - // TODO: Look up if this is such a good idea - bool *_ptr_was_set; + mutable bool _was_set; }; class Account; diff --git a/src/easy/entity.cpp b/src/easy/entity.cpp index a0907a1..e26cab6 100644 --- a/src/easy/entity.cpp +++ b/src/easy/entity.cpp @@ -30,7 +30,6 @@ Easy::Entity::Entity(const string &json) : _tree(Json::nullValue) , _valid(false) ,_was_set(false) -,_ptr_was_set(&_was_set) { from_string(json); } @@ -118,13 +117,13 @@ const Json::Value Easy::Entity::get(const string &key) const if (!node->isNull()) { - *_ptr_was_set = true; + _was_set = true; return *node; } error: ttdebug << "Could not get data: " << key << '\n'; - *_ptr_was_set = false; + _was_set = false; return Json::Value(); } @@ -134,11 +133,11 @@ const string Easy::Entity::get_string(const string &key) const if (node.isString()) { - *_ptr_was_set = true; + _was_set = true; return node.asString(); } - *_ptr_was_set = false; + _was_set = false; return ""; } @@ -148,11 +147,11 @@ const uint_fast64_t Easy::Entity::get_uint64(const string &key) const if (node.isUInt64()) { - *_ptr_was_set = true; + _was_set = true; return node.asUInt64(); } - *_ptr_was_set = false; + _was_set = false; return 0; } @@ -162,11 +161,11 @@ const double Easy::Entity::get_double(const string &key) const if (node.isDouble()) { - *_ptr_was_set = true; + _was_set = true; return node.asDouble(); } - *_ptr_was_set = false; + _was_set = false; return 0.0; } @@ -176,11 +175,11 @@ const bool Easy::Entity::get_bool(const string &key) const if (node.isBool()) { - *_ptr_was_set = true; + _was_set = true; return node.asBool(); } - *_ptr_was_set = false; + _was_set = false; return false; } @@ -195,11 +194,11 @@ const system_clock::time_point struct std::tm tm = {0}; sstime >> std::get_time(&tm, "%Y-%m-%dT%T"); std::time_t time = timegm(&tm); - *_ptr_was_set = true; + _was_set = true; return system_clock::from_time_t(time); } - *_ptr_was_set = false; + _was_set = false; // Return clocks epoch return system_clock::time_point(); } @@ -215,10 +214,10 @@ const std::vector Easy::Entity::get_vector(const string &key) const { vec.push_back(value.asString()); } - *_ptr_was_set = true; + _was_set = true; return vec; } - *_ptr_was_set = false; + _was_set = false; return {}; }