Viam C++ SDK current
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
viam::sdk::ProtoValue Class Reference

Type-erased value for storing google::protobuf::Value types. A ProtoValue can be nullptr, bool, int, double, std::string, or, recursively, a vector or string-map of ProtoValue. This type is used at API/ABI boundaries for interfacing with grpc/proto code. More...

#include <proto_value.hpp>

Public Types

enum  Kind {
  k_null = 0 , k_bool = 1 , k_double = 2 , k_string = 3 ,
  k_list = 4 , k_struct = 5
}
 Type discriminator constants for possible values stored in a ProtoValue.
 

Public Member Functions

 ProtoValue () noexcept
 Construct a null object.
 
 ProtoValue (ProtoValue &&other) noexcept(proto_value_details::all_moves_noexcept{})
 Move construct this from other, leaving other in its unspecified-but-valid moved from state.
 
 ProtoValue (const ProtoValue &other)
 
ProtoValueoperator= (ProtoValue &&other) noexcept(proto_value_details::all_moves_noexcept{})
 Move assignment from other, leaving other in its unspecified-but-valid moved from state.
 
ProtoValueoperator= (const ProtoValue &other)
 
void swap (ProtoValue &other) noexcept(proto_value_details::all_moves_noexcept{})
 
template<typename T >
T const * get () const
 
Value constructors.

Constructors which initialize a ProtoValue holding its argument.

 ProtoValue (std::nullptr_t) noexcept
 
 ProtoValue (bool b) noexcept
 
 ProtoValue (int i) noexcept
 Construct a double object upcast from constructor argument.
 
 ProtoValue (double d) noexcept
 
 ProtoValue (std::string s) noexcept
 
 ProtoValue (const char *str)
 Deduction helper constructor for string from string literal.
 
template<typename Val = ProtoValue, typename = std::enable_if_t<std::is_same<Val, ProtoValue>{}>>
 ProtoValue (std::vector< Val >) noexcept(std::is_nothrow_move_constructible< std::vector< Val > >{})
 Construct from a ProtoList.
 
template<typename Val = ProtoValue, typename = std::enable_if_t<std::is_same<Val, ProtoValue>{}>>
 ProtoValue (std::unordered_map< std::string, Val >) noexcept(std::is_nothrow_move_constructible< std::unordered_map< std::string, Val > >{})
 Construct from a ProtoStruct.
 
Value access API
Kind kind () const
 Obtain enumerator constant representing the stored data type.
 
template<typename T >
bool is_a () const
 Checks whether this ProtoT is an instance of type T.
 
bool is_null () const
 Convenience version of is_a<T> to check if the value is nullptr.
 
template<typename T >
T * get ()
 Return a T pointer if this is_a<T>(), else return nullptr.
 
template<typename T >
T const * get () const
 Return a T pointer if this is_a<T>(), else return nullptr.
 
template<typename T >
std::enable_if_t< std::is_scalar< T >{}, T & > get_unchecked ()
 Return a reference to the underlying T, without checking.
 
template<typename T >
std::enable_if_t< std::is_scalar< T >{}, T > get_unchecked () const
 Return the underlying T by value, without checking.
 
template<typename T >
std::enable_if_t<!std::is_scalar< T >{}, T & > get_unchecked () &
 Return a mutable reference to the underlying T, without checking.
 
template<typename T >
std::enable_if_t<!std::is_scalar< T >{}, T const & > get_unchecked () const &
 Return an immutable reference to the underlying T, without checking.
 
template<typename T >
std::enable_if_t<!std::is_scalar< T >{}, T && > get_unchecked () &&
 Return an rvalue reference to the underlying T, without checking.
 

Static Public Member Functions

template<typename Value = google::protobuf::Value>
static ProtoValue from_proto (const Value &v)
 Construct from proto value.
 

Friends

bool operator== (const ProtoValue &lhs, const ProtoValue &rhs)
 Test equality of two types.
 
void to_proto (const ProtoValue &t, google::protobuf::Value *v)
 

Detailed Description

Type-erased value for storing google::protobuf::Value types. A ProtoValue can be nullptr, bool, int, double, std::string, or, recursively, a vector or string-map of ProtoValue. This type is used at API/ABI boundaries for interfacing with grpc/proto code.

Remarks
The (special) member function templates below all operate on a closed subset of types, so we provide explicit instantiations for all valid template types. See below the class definition.

Member Function Documentation

◆ from_proto()

template<typename Value = google::protobuf::Value>
static ProtoValue viam::sdk::ProtoValue::from_proto ( const Value & v)
static

Construct from proto value.

Note
This method is trivially templated to insulate google::protobuf::Value from our API/ABI. It is meant to be called with no template parameters in a translation unit which includes <google/protobuf/struct.pb.h>

◆ get_unchecked() [1/5]

template<typename T >
template double & viam::sdk::ProtoValue::get_unchecked< double > ( )

Return a reference to the underlying T, without checking.

Template Parameters
Ta bool or double

◆ get_unchecked() [2/5]

template<typename T >
template ProtoStruct & viam::sdk::ProtoValue::get_unchecked< ProtoStruct > ( ) &

Return a mutable reference to the underlying T, without checking.

Template Parameters
Ta std::string, ProtoList, or ProtoStruct.

◆ get_unchecked() [3/5]

template<typename T >
template ProtoStruct && viam::sdk::ProtoValue::get_unchecked< ProtoStruct > ( ) &&

Return an rvalue reference to the underlying T, without checking.

Template Parameters
Ta std::string, ProtoList, or ProtoStruct.

◆ get_unchecked() [4/5]

template<typename T >
template double viam::sdk::ProtoValue::get_unchecked< double > ( ) const

Return the underlying T by value, without checking.

Template Parameters
Ta bool or double.

◆ get_unchecked() [5/5]

template<typename T >
template ProtoStruct const & viam::sdk::ProtoValue::get_unchecked< ProtoStruct > ( ) const &

Return an immutable reference to the underlying T, without checking.

Template Parameters
Ta std::string, ProtoList, or ProtoStruct.

Friends And Related Symbol Documentation

◆ operator==

bool operator== ( const ProtoValue & lhs,
const ProtoValue & rhs )
friend

Test equality of two types.

Note
"Intuitive" arithmetic equality is not supported, but could be. Thus, bool{false}, int{0}, and double{0.0} do not compare equal.

The documentation for this class was generated from the following file: