Skip to content

Commit 43c3152

Browse files
authored
chore: Update naming for Value to be PascalCase (#77)
1 parent 219b9f8 commit 43c3152

File tree

15 files changed

+227
-232
lines changed

15 files changed

+227
-232
lines changed

libs/client-sdk/src/api.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ EvaluationDetail<T> Client::VariationInternal(FlagKey const& key,
168168
auto const& flag = *(desc->flag);
169169
auto const& detail = flag.detail();
170170

171-
if (check_type && default_value.type() != Value::Type::kNull &&
172-
detail.value().type() != default_value.type()) {
171+
if (check_type && default_value.Type() != Value::Type::kNull &&
172+
detail.value().Type() != default_value.Type()) {
173173
auto error_reason =
174174
EvaluationReason(EvaluationReason::ErrorKind::kWrongType);
175175
if (eval_reasons_available_) {

libs/client-sdk/tests/flag_updater_test.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ TEST(FlagUpdaterEventTests, SecondInitWithUpdateProducesEvents) {
196196
"flagA", [&got_event](std::shared_ptr<FlagValueChangeEvent> event) {
197197
got_event.store(true);
198198

199-
EXPECT_EQ("test", event->OldValue().as_string());
200-
EXPECT_EQ("potato", event->NewValue().as_string());
199+
EXPECT_EQ("test", event->OldValue().AsString());
200+
EXPECT_EQ("potato", event->NewValue().AsString());
201201
EXPECT_EQ("flagA", event->FlagName());
202202
EXPECT_FALSE(event->Deleted());
203203
});
@@ -231,8 +231,8 @@ TEST(FlagUpdaterEventTests, SecondInitWithNewFlagProducesEvents) {
231231
"flagB", [&got_event](std::shared_ptr<FlagValueChangeEvent> event) {
232232
got_event.store(true);
233233

234-
EXPECT_TRUE(event->OldValue().is_null());
235-
EXPECT_EQ("potato", event->NewValue().as_string());
234+
EXPECT_TRUE(event->OldValue().IsNull());
235+
EXPECT_EQ("potato", event->NewValue().AsString());
236236
EXPECT_EQ("flagB", event->FlagName());
237237
EXPECT_FALSE(event->Deleted());
238238
});
@@ -266,8 +266,8 @@ TEST(FlagUpdaterDataTests, PatchWithUpdateProducesEvent) {
266266
"flagA", [&got_event](std::shared_ptr<FlagValueChangeEvent> event) {
267267
got_event.store(true);
268268

269-
EXPECT_EQ("test", event->OldValue().as_string());
270-
EXPECT_EQ("second", event->NewValue().as_string());
269+
EXPECT_EQ("test", event->OldValue().AsString());
270+
EXPECT_EQ("second", event->NewValue().AsString());
271271
EXPECT_EQ("flagA", event->FlagName());
272272
EXPECT_FALSE(event->Deleted());
273273
});
@@ -299,8 +299,8 @@ TEST(FlagUpdaterEventTests, PatchWithNewFlagProducesEvent) {
299299
"flagB", [&got_event](std::shared_ptr<FlagValueChangeEvent> event) {
300300
got_event.store(true);
301301

302-
EXPECT_TRUE(event->OldValue().is_null());
303-
EXPECT_EQ("second", event->NewValue().as_string());
302+
EXPECT_TRUE(event->OldValue().IsNull());
303+
EXPECT_EQ("second", event->NewValue().AsString());
304304
EXPECT_EQ("flagB", event->FlagName());
305305
EXPECT_FALSE(event->Deleted());
306306
});
@@ -389,8 +389,8 @@ TEST(FlagUpdaterEventTests, DeleteProducesAnEvent) {
389389
"flagA", [&got_event](std::shared_ptr<FlagValueChangeEvent> event) {
390390
got_event.store(true);
391391

392-
EXPECT_EQ("test", event->OldValue().as_string());
393-
EXPECT_TRUE(event->NewValue().is_null());
392+
EXPECT_EQ("test", event->OldValue().AsString());
393+
EXPECT_TRUE(event->NewValue().IsNull());
394394
EXPECT_EQ("flagA", event->FlagName());
395395
EXPECT_TRUE(event->Deleted());
396396
});
@@ -418,8 +418,8 @@ TEST(FlagUpdaterEventTests, FlagMissingFromSecondInitTreatedAsDelete) {
418418
"flagB", [&got_event](std::shared_ptr<FlagValueChangeEvent> event) {
419419
got_event.store(true);
420420

421-
EXPECT_EQ("test-b", event->OldValue().as_string());
422-
EXPECT_TRUE(event->NewValue().is_null());
421+
EXPECT_EQ("test-b", event->OldValue().AsString());
422+
EXPECT_TRUE(event->NewValue().IsNull());
423423
EXPECT_EQ("flagB", event->FlagName());
424424
EXPECT_TRUE(event->Deleted());
425425
});
@@ -458,8 +458,8 @@ TEST(FlagUpdaterEventTests, InitWithoutEvaluationResultTreatedAsDelete) {
458458
"flagB", [&got_event](std::shared_ptr<FlagValueChangeEvent> event) {
459459
got_event.store(true);
460460

461-
EXPECT_EQ("test-b", event->OldValue().as_string());
462-
EXPECT_TRUE(event->NewValue().is_null());
461+
EXPECT_EQ("test-b", event->OldValue().AsString());
462+
EXPECT_TRUE(event->NewValue().IsNull());
463463
EXPECT_EQ("flagB", event->FlagName());
464464
EXPECT_TRUE(event->Deleted());
465465
});
@@ -497,8 +497,8 @@ TEST(FlagUpdaterEventTests, DeletedFlagStillDeletedInit) {
497497
"flagB", [&got_event](std::shared_ptr<FlagValueChangeEvent> event) {
498498
got_event.store(true);
499499

500-
EXPECT_EQ("test-b", event->OldValue().as_string());
501-
EXPECT_TRUE(event->NewValue().is_null());
500+
EXPECT_EQ("test-b", event->OldValue().AsString());
501+
EXPECT_TRUE(event->NewValue().IsNull());
502502
EXPECT_EQ("flagB", event->FlagName());
503503
EXPECT_TRUE(event->Deleted());
504504
});
@@ -545,8 +545,8 @@ TEST(FlagUpdaterEventTests, SecondDeleteNoEventPatch) {
545545
"flagA", [&got_event](std::shared_ptr<FlagValueChangeEvent> event) {
546546
got_event.store(true);
547547

548-
EXPECT_EQ("test", event->OldValue().as_string());
549-
EXPECT_TRUE(event->NewValue().is_null());
548+
EXPECT_EQ("test", event->OldValue().AsString());
549+
EXPECT_TRUE(event->NewValue().IsNull());
550550
EXPECT_EQ("flagA", event->FlagName());
551551
EXPECT_TRUE(event->Deleted());
552552
});
@@ -578,8 +578,8 @@ TEST(FlagUpdaterDataTests, CanDisconnectEventAndStopGettingEvents) {
578578
"flagA", [&got_event](std::shared_ptr<FlagValueChangeEvent> event) {
579579
got_event.store(true);
580580

581-
EXPECT_EQ("test", event->OldValue().as_string());
582-
EXPECT_EQ("second", event->NewValue().as_string());
581+
EXPECT_EQ("test", event->OldValue().AsString());
582+
EXPECT_EQ("second", event->NewValue().AsString());
583583
EXPECT_EQ("flagA", event->FlagName());
584584
EXPECT_FALSE(event->Deleted());
585585
});
@@ -621,12 +621,12 @@ TEST(FlagUpdaterEventTests, UndeletedFlagProducesEvent) {
621621
got_event.store(true);
622622

623623
if (event->Deleted()) {
624-
EXPECT_EQ("test", event->OldValue().as_string());
625-
EXPECT_TRUE(event->NewValue().is_null());
624+
EXPECT_EQ("test", event->OldValue().AsString());
625+
EXPECT_TRUE(event->NewValue().IsNull());
626626
EXPECT_EQ("flagA", event->FlagName());
627627
} else {
628-
EXPECT_EQ("second", event->NewValue().as_string());
629-
EXPECT_TRUE(event->OldValue().is_null());
628+
EXPECT_EQ("second", event->NewValue().AsString());
629+
EXPECT_TRUE(event->OldValue().IsNull());
630630
EXPECT_EQ("flagA", event->FlagName());
631631
}
632632
});
@@ -664,8 +664,8 @@ TEST(FlagUpdaterEventTests, CanListenToMultipleFlags) {
664664
[&got_event_b](std::shared_ptr<FlagValueChangeEvent> const& event) {
665665
got_event_b.store(true);
666666

667-
EXPECT_EQ("test-b", event->OldValue().as_string());
668-
EXPECT_EQ("second-b", event->NewValue().as_string());
667+
EXPECT_EQ("test-b", event->OldValue().AsString());
668+
EXPECT_EQ("second-b", event->NewValue().AsString());
669669
EXPECT_EQ("flagB", event->FlagName());
670670
});
671671

@@ -674,8 +674,8 @@ TEST(FlagUpdaterEventTests, CanListenToMultipleFlags) {
674674
[&got_event_a](std::shared_ptr<FlagValueChangeEvent> const& event) {
675675
got_event_a.store(true);
676676

677-
EXPECT_EQ("test-a", event->OldValue().as_string());
678-
EXPECT_EQ("second-a", event->NewValue().as_string());
677+
EXPECT_EQ("test-a", event->OldValue().AsString());
678+
EXPECT_EQ("second-a", event->NewValue().AsString());
679679
EXPECT_EQ("flagA", event->FlagName());
680680
});
681681

libs/common/include/attributes.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ class Attributes final {
5757
launchdarkly::AttributeReference const& ref) const {
5858
if (!ref.valid()) {
5959
// Cannot index by invalid references.
60-
return launchdarkly::Value::null();
60+
return launchdarkly::Value::Null();
6161
}
6262
if (ref.is_kind()) {
6363
// Cannot access kind.
64-
return launchdarkly::Value::null();
64+
return launchdarkly::Value::Null();
6565
}
6666

6767
if (ref.depth() == 1) {
@@ -81,9 +81,9 @@ class Attributes final {
8181
bool found = true;
8282
for (size_t index = 0; index < ref.depth(); index++) {
8383
auto const& component = ref.component(index);
84-
if (node->is_object()) {
85-
auto const& map = node->as_object();
86-
if (auto search = map.find(component); search != map.end()) {
84+
if (node->IsObject()) {
85+
auto const& map = node->AsObject();
86+
if (auto search = map.Find(component); search != map.end()) {
8787
node = &search->second;
8888
} else {
8989
found = false;
@@ -94,7 +94,7 @@ class Attributes final {
9494
}
9595
}
9696
if (!found) {
97-
return launchdarkly::Value::null();
97+
return launchdarkly::Value::Null();
9898
}
9999
return *node;
100100
}

libs/common/include/value.hpp

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class Value final {
106106

107107
Value const& operator[](std::size_t index) const;
108108

109-
[[nodiscard]] std::size_t size() const;
109+
[[nodiscard]] std::size_t Size() const;
110110

111111
[[nodiscard]] Iterator begin() const;
112112

@@ -187,16 +187,14 @@ class Value final {
187187
* The number of items in the Object.
188188
* @return The number of items in the Object.
189189
*/
190-
[[nodiscard]] std::size_t size() const;
190+
[[nodiscard]] std::size_t Size() const;
191191

192192
/**
193193
* Get the number of items with the given key. Will be 1 or 0.
194194
* @param key The key to get a count for.
195195
* @return The count of items with the given key.
196196
*/
197-
[[nodiscard]] std::size_t count(std::string const& key) const {
198-
return map_.count(key);
199-
}
197+
[[nodiscard]] std::size_t Count(std::string const& key) const;
200198

201199
[[nodiscard]] Iterator begin() const;
202200

@@ -207,7 +205,7 @@ class Value final {
207205
* @param key The key to find a value for.
208206
* @return The value, or the end iterator.
209207
*/
210-
[[nodiscard]] Iterator find(std::string const& key) const;
208+
[[nodiscard]] Iterator Find(std::string const& key) const;
211209

212210
private:
213211
std::map<std::string, Value> map_;
@@ -288,7 +286,7 @@ class Value final {
288286
/**
289287
* Get the type of the attribute.
290288
*/
291-
[[nodiscard]] Type type() const;
289+
[[nodiscard]] Type Type() const;
292290

293291
/**
294292
* Returns true if the value is a null.
@@ -297,14 +295,14 @@ class Value final {
297295
* value from this function as a marker.
298296
* @return True if the value is null.
299297
*/
300-
[[nodiscard]] bool is_null() const;
298+
[[nodiscard]] bool IsNull() const;
301299

302300
/**
303301
* Returns true if the value is a boolean.
304302
*
305303
* @return
306304
*/
307-
[[nodiscard]] bool is_bool() const;
305+
[[nodiscard]] bool IsBool() const;
308306

309307
/**
310308
* Returns true if the value is a number.
@@ -313,78 +311,78 @@ class Value final {
313311
* an int or double for convenience.
314312
* @return True if the value is a number.
315313
*/
316-
[[nodiscard]] bool is_number() const;
314+
[[nodiscard]] bool IsNumber() const;
317315

318316
/**
319317
* Returns true if the value is a string.
320318
*
321319
* @return True if the value is a string.
322320
*/
323-
[[nodiscard]] bool is_string() const;
321+
[[nodiscard]] bool IsString() const;
324322

325323
/**
326324
* Returns true if the value is an array.
327325
*
328326
* @return True if the value is an array.
329327
*/
330-
[[nodiscard]] bool is_array() const;
328+
[[nodiscard]] bool IsArray() const;
331329

332330
/**
333331
* Returns true if the value is an object.
334332
*
335333
* @return True if the value is an object.
336334
*/
337-
[[nodiscard]] bool is_object() const;
335+
[[nodiscard]] bool IsObject() const;
338336

339337
/**
340338
* If the value is a boolean, then return the boolean, otherwise return
341339
* false.
342340
*
343341
* @return The value of the boolean, or false.
344342
*/
345-
[[nodiscard]] bool as_bool() const;
343+
[[nodiscard]] bool AsBool() const;
346344

347345
/**
348346
* If the value is a number, then return the internal double value as an
349347
* integer, otherwise return 0.
350348
*
351349
* @return The value as an integer, or 0.
352350
*/
353-
[[nodiscard]] int as_int() const;
351+
[[nodiscard]] int AsInt() const;
354352

355-
[[nodiscard]] double as_double() const;
353+
[[nodiscard]] double AsDouble() const;
356354

357355
/**
358356
* If the value is a string, then return a reference to that string,
359357
* otherwise return a reference to an empty string.
360358
*
361359
* @return The value as a string, or an empty string.
362360
*/
363-
[[nodiscard]] std::string const& as_string() const;
361+
[[nodiscard]] std::string const& AsString() const;
364362

365363
/**
366364
* If the value is an array type, then return a reference to that array as a
367365
* vector, otherwise return a reference to an empty vector.
368366
*
369367
* @return The value as a vector, or an empty vector.
370368
*/
371-
[[nodiscard]] Array const& as_array() const;
369+
[[nodiscard]] Array const& AsArray() const;
372370

373371
/**
374372
* if the value is an object type, then return a reference to that object
375373
* as a map, otherwise return a reference to an empty map.
376374
*
377375
* @return The value as a map, or an empty map.
378376
*/
379-
[[nodiscard]] Object const& as_object() const;
377+
[[nodiscard]] Object const& AsObject() const;
380378

381379
~Value() = default;
382380

383381
/**
384382
* Get a null value.
385383
* @return The null value.
386384
*/
387-
static Value const& null();
385+
static Value const& Null();
388386

389387
friend std::ostream& operator<<(std::ostream& out, Value const& value) {
390388
switch (value.type_) {
@@ -413,17 +411,17 @@ class Value final {
413411
return out;
414412
}
415413

416-
operator bool() const { return as_bool(); }
414+
operator bool() const { return AsBool(); }
417415

418-
operator std::string() const { return as_string(); }
416+
operator std::string() const { return AsString(); }
419417

420-
operator double() const { return as_double(); }
418+
operator double() const { return AsDouble(); }
421419

422-
operator int() const { return as_int(); }
420+
operator int() const { return AsInt(); }
423421

424422
private:
425423
boost::variant<bool, double, std::string, Array, Object> storage_;
426-
Type type_;
424+
enum Type type_;
427425

428426
// Empty constants used when accessing the wrong type.
429427
inline static const std::string empty_string_;

libs/common/src/attributes.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
namespace launchdarkly {
44

55
std::string const& Attributes::key() const {
6-
return key_.as_string();
6+
return key_.AsString();
77
}
88

99
std::string const& Attributes::name() const {
10-
return name_.as_string();
10+
return name_.AsString();
1111
}
1212

1313
bool Attributes::anonymous() const {
14-
return anonymous_.as_bool();
14+
return anonymous_.AsBool();
1515
}
1616

1717
Value const& Attributes::custom_attributes() const {

0 commit comments

Comments
 (0)