Add methods for creating boolean simple values
Add helper methods and static factory methods for creating/accessing
boolean CBOR simple values.
Bug: 803648
Change-Id: If0297d149ee1b58022fcf6b92e521b28e5f9faff
Reviewed-on: https://chromium-review.googlesource.com/875196
Commit-Queue: Jun Choi <[email protected]>
Reviewed-by: Balazs Engedy <[email protected]>
Reviewed-by: Jan Wilken Dörrie <[email protected]>
Reviewed-by: Kim Paulhamus <[email protected]>
Cr-Commit-Position: refs/heads/master@{#530958}
diff --git a/components/cbor/cbor_values.h b/components/cbor/cbor_values.h
index 53eea21..af752f9 100644
--- a/components/cbor/cbor_values.h
+++ b/components/cbor/cbor_values.h
@@ -6,6 +6,7 @@
#define COMPONENTS_CBOR_CBOR_VALUES_H_
#include <stdint.h>
+
#include <string>
#include <tuple>
#include <vector>
@@ -96,6 +97,10 @@
CBORValue() noexcept; // A NONE value.
explicit CBORValue(Type type);
+
+ explicit CBORValue(SimpleValue in_simple);
+ explicit CBORValue(bool boolean_value);
+
explicit CBORValue(int integer_value);
explicit CBORValue(int64_t integer_value);
explicit CBORValue(uint64_t integer_value) = delete;
@@ -113,8 +118,6 @@
explicit CBORValue(const MapValue& in_map);
explicit CBORValue(MapValue&& in_map) noexcept;
- explicit CBORValue(SimpleValue in_simple);
-
CBORValue& operator=(CBORValue&& that) noexcept;
~CBORValue();
@@ -129,6 +132,11 @@
// Returns true if the current object represents a given type.
bool is_type(Type type) const { return type == type_; }
bool is_none() const { return type() == Type::NONE; }
+ bool is_simple() const { return type() == Type::SIMPLE_VALUE; }
+ bool is_bool() const {
+ return is_simple() && (simple_value_ == SimpleValue::TRUE_VALUE ||
+ simple_value_ == SimpleValue::FALSE_VALUE);
+ }
bool is_unsigned() const { return type() == Type::UNSIGNED; }
bool is_negative() const { return type() == Type::NEGATIVE; }
bool is_integer() const { return is_unsigned() || is_negative(); }
@@ -136,10 +144,10 @@
bool is_string() const { return type() == Type::STRING; }
bool is_array() const { return type() == Type::ARRAY; }
bool is_map() const { return type() == Type::MAP; }
- bool is_simple() const { return type() == Type::SIMPLE_VALUE; }
// These will all fatally assert if the type doesn't match.
SimpleValue GetSimpleValue() const;
+ bool GetBool() const;
const int64_t& GetInteger() const;
const int64_t& GetUnsigned() const;
const int64_t& GetNegative() const;