@@ -15,8 +15,8 @@ Value::Value(double value) : inner_value_(value) {}
1515
1616Value::Value (std::string value) : inner_value_(std::move(value)) {}
1717
18- Value::Value (const char * value) : inner_value_() {
19- if (value) {
18+ Value::Value (const char * value) {
19+ if (value != nullptr ) {
2020 inner_value_ = std::string (value);
2121 }
2222}
@@ -32,12 +32,12 @@ Value::Value(std::chrono::system_clock::time_point value)
3232
3333Value::Value (const Value& other) {
3434 if (other.IsStructure ()) {
35- auto & ptr = std::get<std::unique_ptr<std::map<std::string, Value>>>(
35+ const auto & ptr = std::get<std::unique_ptr<std::map<std::string, Value>>>(
3636 other.inner_value_ );
3737 inner_value_ = ptr ? std::make_unique<std::map<std::string, Value>>(*ptr)
3838 : std::unique_ptr<std::map<std::string, Value>>(nullptr );
3939 } else if (other.IsList ()) {
40- auto & ptr =
40+ const auto & ptr =
4141 std::get<std::unique_ptr<std::vector<Value>>>(other.inner_value_ );
4242 inner_value_ = ptr ? std::make_unique<std::vector<Value>>(*ptr)
4343 : std::unique_ptr<std::vector<Value>>(nullptr );
@@ -57,7 +57,9 @@ Value::Value(const Value& other) {
5757}
5858
5959Value& Value::operator =(const Value& other) {
60- if (this == &other) return *this ;
60+ if (this == &other) {
61+ return *this ;
62+ }
6163 Value temp (other);
6264 std::swap (this ->inner_value_ , temp.inner_value_ );
6365 return *this ;
@@ -90,76 +92,98 @@ bool Value::IsDateTime() const {
9092}
9193
9294std::optional<bool > Value::AsBool () const {
93- if (auto * v = std::get_if<bool >(&inner_value_)) return *v;
95+ if (const auto * val = std::get_if<bool >(&inner_value_)) {
96+ return *val;
97+ }
9498 return std::nullopt ;
9599}
96100
97101std::optional<std::string> Value::AsString () const {
98- if (auto * v = std::get_if<std::string>(&inner_value_)) return *v;
102+ if (const auto * val = std::get_if<std::string>(&inner_value_)) {
103+ return *val;
104+ }
99105 return std::nullopt ;
100106}
101107
102108std::optional<int64_t > Value::AsInt () const {
103- if (auto * v = std::get_if<int64_t >(&inner_value_)) return *v;
104- if (auto * v = std::get_if<double >(&inner_value_))
105- return static_cast <int64_t >(std::floor (*v + 0.5 ));
109+ if (const auto * val = std::get_if<int64_t >(&inner_value_)) {
110+ return *val;
111+ }
112+ if (const auto * val = std::get_if<double >(&inner_value_)) {
113+ constexpr double kRoundingOffset = 0.5 ;
114+ return static_cast <int64_t >(std::floor (*val + kRoundingOffset ));
115+ }
106116 return std::nullopt ;
107117}
108118
109119std::optional<double > Value::AsDouble () const {
110- if (auto * v = std::get_if<double >(&inner_value_)) return *v;
111- if (auto * v = std::get_if<int64_t >(&inner_value_))
112- return static_cast <double >(*v);
120+ if (const auto * val = std::get_if<double >(&inner_value_)) {
121+ return *val;
122+ }
123+ if (const auto * val = std::get_if<int64_t >(&inner_value_)) {
124+ return static_cast <double >(*val);
125+ }
113126 return std::nullopt ;
114127}
115128
116129std::optional<std::chrono::system_clock::time_point> Value::AsDateTime () const {
117- if (auto * v =
118- std::get_if<std::chrono::system_clock::time_point>(&inner_value_))
119- return *v;
130+ if (const auto * val =
131+ std::get_if<std::chrono::system_clock::time_point>(&inner_value_)) {
132+ return *val;
133+ }
120134 return std::nullopt ;
121135}
122136
123137const std::map<std::string, Value>* Value::AsStructure () const {
124- if (auto * v = std::get_if<std::unique_ptr<std::map<std::string, Value>>>(
125- &inner_value_)) {
126- return v->get ();
138+ if (const auto * val =
139+ std::get_if<std::unique_ptr<std::map<std::string, Value>>>(
140+ &inner_value_)) {
141+ return val->get ();
127142 }
128143 return nullptr ;
129144}
130145
131146const std::vector<Value>* Value::AsList () const {
132- if (auto * v =
147+ if (const auto * val =
133148 std::get_if<std::unique_ptr<std::vector<Value>>>(&inner_value_)) {
134- return v ->get ();
149+ return val ->get ();
135150 }
136151 return nullptr ;
137152}
138153
139154bool operator ==(const Value& lhs, const Value& rhs) {
140- if (lhs.IsBool () && rhs.IsBool ()) return lhs.AsBool () == rhs.AsBool ();
155+ if (lhs.IsBool () && rhs.IsBool ()) {
156+ return lhs.AsBool () == rhs.AsBool ();
157+ }
141158
142- if (lhs.IsString () && rhs.IsString ()) return lhs.AsString () == rhs.AsString ();
159+ if (lhs.IsString () && rhs.IsString ()) {
160+ return lhs.AsString () == rhs.AsString ();
161+ }
143162
144- if (lhs.IsNumber () && rhs.IsNumber ()) return lhs.AsDouble () == rhs.AsDouble ();
163+ if (lhs.IsNumber () && rhs.IsNumber ()) {
164+ return lhs.AsDouble () == rhs.AsDouble ();
165+ }
145166
146- if (lhs.IsNull () && rhs.IsNull ()) return true ;
167+ if (lhs.IsNull () && rhs.IsNull ()) {
168+ return true ;
169+ }
147170
148- if (lhs.IsDateTime () && rhs.IsDateTime ())
171+ if (lhs.IsDateTime () && rhs.IsDateTime ()) {
149172 return lhs.AsDateTime () == rhs.AsDateTime ();
173+ }
150174
151175 if (lhs.IsStructure () && rhs.IsStructure ()) {
152176 const auto * lhs_struct = lhs.AsStructure ();
153177 const auto * rhs_struct = rhs.AsStructure ();
154- if (lhs_struct && rhs_struct) {
178+ if (lhs_struct != nullptr && rhs_struct != nullptr ) {
155179 return *lhs_struct == *rhs_struct;
156180 }
157181 return lhs_struct == rhs_struct;
158182 }
159183 if (lhs.IsList () && rhs.IsList ()) {
160184 const auto * lhs_list = lhs.AsList ();
161185 const auto * rhs_list = rhs.AsList ();
162- if (lhs_list && rhs_list) {
186+ if (lhs_list != nullptr && rhs_list != nullptr ) {
163187 return *lhs_list == *rhs_list;
164188 }
165189 return lhs_list == rhs_list;
@@ -170,4 +194,4 @@ bool operator==(const Value& lhs, const Value& rhs) {
170194
171195bool operator !=(const Value& lhs, const Value& rhs) { return !(lhs == rhs); }
172196
173- } // namespace openfeature
197+ } // namespace openfeature
0 commit comments