8 #ifndef NTCORE_NETWORKTABLES_NETWORKTABLEVALUE_H_
9 #define NTCORE_NETWORKTABLES_NETWORKTABLEVALUE_H_
14 #include <initializer_list>
17 #include <type_traits>
21 #include <wpi/ArrayRef.h>
22 #include <wpi/StringRef.h>
23 #include <wpi/Twine.h>
38 struct private_init {};
71 uint64_t
time()
const {
return m_val.last_change; }
83 bool IsValid()
const {
return m_val.type != NT_UNASSIGNED; }
90 bool IsBoolean()
const {
return m_val.type == NT_BOOLEAN; }
97 bool IsDouble()
const {
return m_val.type == NT_DOUBLE; }
104 bool IsString()
const {
return m_val.type == NT_STRING; }
111 bool IsRaw()
const {
return m_val.type == NT_RAW; }
118 bool IsRpc()
const {
return m_val.type == NT_RPC; }
154 assert(m_val.type == NT_BOOLEAN);
155 return m_val.data.v_boolean != 0;
164 assert(m_val.type == NT_DOUBLE);
165 return m_val.data.v_double;
174 assert(m_val.type == NT_STRING);
184 assert(m_val.type == NT_RAW);
194 assert(m_val.type == NT_RPC);
204 assert(m_val.type == NT_BOOLEAN_ARRAY);
206 m_val.data.arr_boolean.size);
215 assert(m_val.type == NT_DOUBLE_ARRAY);
217 m_val.data.arr_double.size);
226 assert(m_val.type == NT_STRING_ARRAY);
227 return m_string_array;
246 auto val = std::make_shared<Value>(NT_BOOLEAN,
time, private_init());
247 val->m_val.data.v_boolean =
value;
260 auto val = std::make_shared<Value>(NT_DOUBLE,
time, private_init());
261 val->m_val.data.v_double =
value;
275 auto val = std::make_shared<Value>(NT_STRING,
time, private_init());
276 val->m_string =
value.str();
277 val->m_val.data.v_string.
str = const_cast<char*>(val->m_string.c_str());
278 val->m_val.data.v_string.len = val->m_string.size();
290 template <
typename T,
291 typename std::enable_if<std::is_same<T, std::string>::value>
::type>
293 auto val = std::make_shared<Value>(NT_STRING,
time, private_init());
294 val->m_string = std::move(
value);
295 val->m_val.data.v_string.str = const_cast<char*>(val->m_string.c_str());
296 val->m_val.data.v_string.len = val->m_string.size();
309 auto val = std::make_shared<Value>(NT_RAW,
time, private_init());
310 val->m_string =
value;
311 val->m_val.data.v_raw.
str = const_cast<char*>(val->m_string.c_str());
312 val->m_val.data.v_raw.len = val->m_string.size();
324 template <
typename T,
325 typename std::enable_if<std::is_same<T, std::string>::value>
::type>
327 auto val = std::make_shared<Value>(NT_RAW,
time, private_init());
328 val->m_string = std::move(
value);
329 val->m_val.data.v_raw.str = const_cast<char*>(val->m_string.c_str());
330 val->m_val.data.v_raw.len = val->m_string.size();
343 auto val = std::make_shared<Value>(NT_RPC,
time, private_init());
344 val->m_string =
value;
345 val->m_val.data.v_raw.
str = const_cast<char*>(val->m_string.c_str());
346 val->m_val.data.v_raw.len = val->m_string.size();
358 template <
typename T>
360 auto val = std::make_shared<Value>(NT_RPC,
time, private_init());
361 val->m_string = std::move(
value);
362 val->m_val.data.v_raw.str = const_cast<char*>(val->m_string.c_str());
363 val->m_val.data.v_raw.len = val->m_string.size();
387 std::initializer_list<bool>
value, uint64_t
time = 0) {
412 std::initializer_list<int>
value, uint64_t
time = 0) {
437 std::initializer_list<double>
value, uint64_t
time = 0) {
461 std::initializer_list<std::string>
value, uint64_t
time = 0) {
476 std::vector<std::string>&&
value, uint64_t
time = 0);
482 friend bool operator==(
const Value& lhs,
const Value& rhs);
486 std::string m_string;
487 std::vector<std::string> m_string_array;
490 bool operator==(
const Value& lhs,
const Value& rhs);
491 inline bool operator!=(
const Value& lhs,
const Value& rhs) {
492 return !(lhs == rhs);
503 #endif // NTCORE_NETWORKTABLES_NETWORKTABLEVALUE_H_
bool IsStringArray() const
Determine if entry value contains a string array.
Definition: NetworkTableValue.h:139
char * str
String contents (UTF-8).
Definition: ntcore_c.h:113
static std::shared_ptr< Value > MakeBoolean(bool value, uint64_t time=0)
Creates a boolean entry value.
Definition: NetworkTableValue.h:245
bool IsBooleanArray() const
Determine if entry value contains a boolean array.
Definition: NetworkTableValue.h:125
StringRef GetRaw() const
Get the entry's raw value.
Definition: NetworkTableValue.h:183
bool IsRpc() const
Determine if entry value contains a rpc definition.
Definition: NetworkTableValue.h:118
static std::shared_ptr< Value > MakeString(const Twine &value, uint64_t time=0)
Creates a string entry value.
Definition: NetworkTableValue.h:273
Value NetworkTableValue
NetworkTable Value alias for similarity with Java.
Definition: NetworkTableValue.h:499
static std::shared_ptr< Value > MakeRpc(StringRef value, uint64_t time=0)
Creates a rpc entry value.
Definition: NetworkTableValue.h:342
static std::shared_ptr< Value > MakeBooleanArray(ArrayRef< bool > value, uint64_t time=0)
Creates a boolean array entry value.
NT_Type type() const
Get the data type.
Definition: NetworkTableValue.h:50
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:42
ArrayRef< double > GetDoubleArray() const
Get the entry's double array value.
Definition: NetworkTableValue.h:214
static std::shared_ptr< Value > MakeBooleanArray(std::initializer_list< bool > value, uint64_t time=0)
Creates a boolean array entry value.
Definition: NetworkTableValue.h:386
static std::shared_ptr< Value > MakeBooleanArray(std::initializer_list< int > value, uint64_t time=0)
Creates a boolean array entry value.
Definition: NetworkTableValue.h:411
ArrayRef< int > GetBooleanArray() const
Get the entry's boolean array value.
Definition: NetworkTableValue.h:203
NetworkTables Entry Value.
Definition: ntcore_c.h:123
static std::shared_ptr< Value > MakeDouble(double value, uint64_t time=0)
Creates a double entry value.
Definition: NetworkTableValue.h:259
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:447
bool IsValid() const
Determine if entry value contains a value or is unassigned.
Definition: NetworkTableValue.h:83
static std::shared_ptr< Value > MakeRaw(T &&value, uint64_t time=0)
Creates a raw entry value.
Definition: NetworkTableValue.h:326
uint64_t time() const
Get the creation time of the value.
Definition: NetworkTableValue.h:71
static std::shared_ptr< Value > MakeRpc(T &&value, uint64_t time=0)
Creates a rpc entry value.
Definition: NetworkTableValue.h:359
StringRef GetRpc() const
Get the entry's rpc definition value.
Definition: NetworkTableValue.h:193
bool IsDoubleArray() const
Determine if entry value contains a double array.
Definition: NetworkTableValue.h:132
static std::shared_ptr< Value > MakeString(T &&value, uint64_t time=0)
Creates a string entry value.
Definition: NetworkTableValue.h:292
bool IsDouble() const
Determine if entry value contains a double.
Definition: NetworkTableValue.h:97
uint64_t last_change() const
Get the creation time of the value.
Definition: NetworkTableValue.h:64
static std::shared_ptr< Value > MakeStringArray(std::initializer_list< std::string > value, uint64_t time=0)
Creates a string array entry value.
Definition: NetworkTableValue.h:460
bool GetBoolean() const
Get the entry's boolean value.
Definition: NetworkTableValue.h:153
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
double GetDouble() const
Get the entry's double value.
Definition: NetworkTableValue.h:163
bool IsBoolean() const
Determine if entry value contains a boolean.
Definition: NetworkTableValue.h:90
bool IsRaw() const
Determine if entry value contains a raw.
Definition: NetworkTableValue.h:111
ArrayRef< std::string > GetStringArray() const
Get the entry's string array value.
Definition: NetworkTableValue.h:225
static std::shared_ptr< Value > MakeRaw(StringRef value, uint64_t time=0)
Creates a raw entry value.
Definition: NetworkTableValue.h:308
bool IsString() const
Determine if entry value contains a string.
Definition: NetworkTableValue.h:104
StringRef GetString() const
Get the entry's string value.
Definition: NetworkTableValue.h:173
A network table entry value.
Definition: NetworkTableValue.h:37
static std::shared_ptr< Value > MakeStringArray(ArrayRef< std::string > value, uint64_t time=0)
Creates a string array entry value.
NT_Type
NetworkTables data types.
Definition: ntcore_c.h:52
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:85
NetworkTables (ntcore) namespace.
Definition: NetworkTableValue.h:27
static std::shared_ptr< Value > MakeDoubleArray(std::initializer_list< double > value, uint64_t time=0)
Creates a double array entry value.
Definition: NetworkTableValue.h:436
const NT_Value & value() const
Get the data value stored.
Definition: NetworkTableValue.h:57
static std::shared_ptr< Value > MakeDoubleArray(ArrayRef< double > value, uint64_t time=0)
Creates a double array entry value.