diff --git a/src/viam/sdk/common/proto_value.cpp b/src/viam/sdk/common/proto_value.cpp index 8446ae2b1..ee5b43c78 100644 --- a/src/viam/sdk/common/proto_value.cpp +++ b/src/viam/sdk/common/proto_value.cpp @@ -101,7 +101,7 @@ ProtoValue::Kind ProtoValue::kind() const { } bool ProtoValue::is_null() const { - return kind() == Kind::null; + return kind() == Kind::k_null; } template diff --git a/src/viam/sdk/common/proto_value.hpp b/src/viam/sdk/common/proto_value.hpp index 87236ce76..44bb24822 100644 --- a/src/viam/sdk/common/proto_value.hpp +++ b/src/viam/sdk/common/proto_value.hpp @@ -53,7 +53,15 @@ struct all_moves_noexcept class ProtoValue { public: /// @brief Type discriminator constants for possible values stored in a ProtoValue. - enum Kind { null, bool_, int_, double_, string, list, struct_ }; + enum Kind { + k_null = 0, + k_bool = 1, + k_double = 2, + k_string = 3, + k_list = 4, + k_struct = 5, + k_int = 6 + }; /// @brief Construct a null object. ProtoValue() noexcept; @@ -355,37 +363,37 @@ using KindConstant = std::integral_constant; template <> struct kind { - using type = KindConstant; + using type = KindConstant; }; template <> struct kind { - using type = KindConstant; + using type = KindConstant; }; template <> struct kind { - using type = KindConstant; + using type = KindConstant; }; template <> struct kind { - using type = KindConstant; + using type = KindConstant; }; template <> struct kind { - using type = KindConstant; + using type = KindConstant; }; template <> struct kind { - using type = KindConstant; + using type = KindConstant; }; template <> struct kind { - using type = KindConstant; + using type = KindConstant; }; } // namespace proto_value_details diff --git a/src/viam/sdk/common/proto_value_visit.hpp b/src/viam/sdk/common/proto_value_visit.hpp index 113785f00..1a658a2fa 100644 --- a/src/viam/sdk/common/proto_value_visit.hpp +++ b/src/viam/sdk/common/proto_value_visit.hpp @@ -22,19 +22,19 @@ template auto visit(Visitor&& visitor, ProtoValue& value) -> decltype(std::forward(visitor)(std::declval())) { switch (value.kind()) { - case ProtoValue::Kind::bool_: + case ProtoValue::Kind::k_bool: return std::forward(visitor)(value.get_unchecked()); - case ProtoValue::Kind::int_: + case ProtoValue::Kind::k_int: return std::forward(visitor)(value.get_unchecked()); - case ProtoValue::Kind::double_: + case ProtoValue::Kind::k_double: return std::forward(visitor)(value.get_unchecked()); - case ProtoValue::Kind::string: + case ProtoValue::Kind::k_string: return std::forward(visitor)(value.get_unchecked()); - case ProtoValue::Kind::list: + case ProtoValue::Kind::k_list: return std::forward(visitor)(value.get_unchecked()); - case ProtoValue::Kind::struct_: + case ProtoValue::Kind::k_struct: return std::forward(visitor)(value.get_unchecked()); - case ProtoValue::Kind::null: { + case ProtoValue::Kind::k_null: { auto np = nullptr; return std::forward(visitor)(np); } @@ -45,19 +45,19 @@ template auto visit(Visitor&& visitor, const ProtoValue& value) -> decltype(std::forward(visitor)(std::declval())) { switch (value.kind()) { - case ProtoValue::Kind::bool_: + case ProtoValue::Kind::k_bool: return std::forward(visitor)(value.get_unchecked()); - case ProtoValue::Kind::int_: + case ProtoValue::Kind::k_int: return std::forward(visitor)(value.get_unchecked()); - case ProtoValue::Kind::double_: + case ProtoValue::Kind::k_double: return std::forward(visitor)(value.get_unchecked()); - case ProtoValue::Kind::string: + case ProtoValue::Kind::k_string: return std::forward(visitor)(value.get_unchecked()); - case ProtoValue::Kind::list: + case ProtoValue::Kind::k_list: return std::forward(visitor)(value.get_unchecked()); - case ProtoValue::Kind::struct_: + case ProtoValue::Kind::k_struct: return std::forward(visitor)(value.get_unchecked()); - case ProtoValue::Kind::null: { + case ProtoValue::Kind::k_null: { const auto np = nullptr; return std::forward(visitor)(np); } @@ -68,19 +68,19 @@ template auto visit(Visitor&& visitor, ProtoValue&& value) -> decltype(std::forward(visitor)(std::declval())) { switch (value.kind()) { - case ProtoValue::Kind::bool_: + case ProtoValue::Kind::k_bool: return std::forward(visitor)(std::move(value.get_unchecked())); - case ProtoValue::Kind::int_: + case ProtoValue::Kind::k_int: return std::forward(visitor)(std::move(value.get_unchecked())); - case ProtoValue::Kind::double_: + case ProtoValue::Kind::k_double: return std::forward(visitor)(std::move(value.get_unchecked())); - case ProtoValue::Kind::string: + case ProtoValue::Kind::k_string: return std::forward(visitor)(std::move(value.get_unchecked())); - case ProtoValue::Kind::list: + case ProtoValue::Kind::k_list: return std::forward(visitor)(std::move(value.get_unchecked())); - case ProtoValue::Kind::struct_: + case ProtoValue::Kind::k_struct: return std::forward(visitor)(std::move(value.get_unchecked())); - case ProtoValue::Kind::null: + case ProtoValue::Kind::k_null: return std::forward(visitor)(std::nullptr_t()); } } diff --git a/src/viam/sdk/tests/test_proto_value.cpp b/src/viam/sdk/tests/test_proto_value.cpp index 1b6487c9d..7373fd17b 100644 --- a/src/viam/sdk/tests/test_proto_value.cpp +++ b/src/viam/sdk/tests/test_proto_value.cpp @@ -44,10 +44,10 @@ BOOST_AUTO_TEST_CASE(test_object_equality) { { ProtoValue i5(5); auto int_roundtrip = ProtoValue::from_proto(to_proto(i5)); - BOOST_CHECK(i5.kind() == ProtoValue::Kind::int_); + BOOST_CHECK(i5.kind() == ProtoValue::Kind::k_int); BOOST_CHECK(i5.is_a()); - BOOST_CHECK(int_roundtrip.kind() == ProtoValue::Kind::double_); + BOOST_CHECK(int_roundtrip.kind() == ProtoValue::Kind::k_double); BOOST_CHECK(int_roundtrip.is_a()); BOOST_CHECK(!(i5 == int_roundtrip)); diff --git a/src/viam/sdk/tests/test_proto_value_visit.cpp b/src/viam/sdk/tests/test_proto_value_visit.cpp index 84d20809a..0a723921e 100644 --- a/src/viam/sdk/tests/test_proto_value_visit.cpp +++ b/src/viam/sdk/tests/test_proto_value_visit.cpp @@ -89,30 +89,30 @@ struct rvalue_visitor { // reference. Thus we spell out the overloads. bool operator()(std::nullptr_t&&) && { - return kind == ProtoValue::Kind::null; + return kind == ProtoValue::Kind::k_null; } bool operator()(bool&&) && { - return kind == ProtoValue::Kind::bool_; + return kind == ProtoValue::Kind::k_bool; } bool operator()(int&&) && { - return kind == ProtoValue::Kind::int_; + return kind == ProtoValue::Kind::k_int; } bool operator()(double&&) && { - return kind == ProtoValue::Kind::double_; + return kind == ProtoValue::Kind::k_double; } bool operator()(std::string&&) && { - return kind == ProtoValue::Kind::string; + return kind == ProtoValue::Kind::k_string; } bool operator()(ProtoList&&) && { - return kind == ProtoValue::Kind::list; + return kind == ProtoValue::Kind::k_list; } bool operator()(ProtoStruct&&) && { - return kind == ProtoValue::Kind::struct_; + return kind == ProtoValue::Kind::k_struct; } bool operator()(...) && { @@ -131,13 +131,13 @@ struct rvalue_visitor { BOOST_AUTO_TEST_CASE(test_visitor) { auto test_cases = std::make_tuple( - std::make_pair(ProtoValue::Kind::null, nullptr), - std::make_pair(ProtoValue::Kind::bool_, true), - std::make_pair(ProtoValue::Kind::int_, 5), - std::make_pair(ProtoValue::Kind::double_, 12.345), - std::make_pair(ProtoValue::Kind::string, "meow"), - std::make_pair(ProtoValue::Kind::list, ProtoList({{ProtoValue(1), ProtoValue("woof")}})), - std::make_pair(ProtoValue::Kind::struct_, ProtoStruct({{"string", "str"}, {"int", 5}}))); + std::make_pair(ProtoValue::Kind::k_null, nullptr), + std::make_pair(ProtoValue::Kind::k_bool, true), + std::make_pair(ProtoValue::Kind::k_int, 5), + std::make_pair(ProtoValue::Kind::k_double, 12.345), + std::make_pair(ProtoValue::Kind::k_string, "meow"), + std::make_pair(ProtoValue::Kind::k_list, ProtoList({{ProtoValue(1), ProtoValue("woof")}})), + std::make_pair(ProtoValue::Kind::k_struct, ProtoStruct({{"string", "str"}, {"int", 5}}))); using visitors = mp_list;