8 #ifndef NTCORE_NETWORKTABLES_NETWORKTABLEVALUE_H_
9 #define NTCORE_NETWORKTABLES_NETWORKTABLEVALUE_H_
16 #include <type_traits>
20 #include <wpi/ArrayRef.h>
21 #include <wpi/StringRef.h>
22 #include <wpi/Twine.h>
37 struct private_init {};
70 uint64_t
time()
const {
return m_val.last_change; }
82 bool IsValid()
const {
return m_val.type != NT_UNASSIGNED; }
89 bool IsBoolean()
const {
return m_val.type == NT_BOOLEAN; }
96 bool IsDouble()
const {
return m_val.type == NT_DOUBLE; }
103 bool IsString()
const {
return m_val.type == NT_STRING; }
110 bool IsRaw()
const {
return m_val.type == NT_RAW; }
117 bool IsRpc()
const {
return m_val.type == NT_RPC; }
153 assert(m_val.type == NT_BOOLEAN);
154 return m_val.data.v_boolean != 0;
163 assert(m_val.type == NT_DOUBLE);
164 return m_val.data.v_double;
173 assert(m_val.type == NT_STRING);
183 assert(m_val.type == NT_RAW);
193 assert(m_val.type == NT_RPC);
203 assert(m_val.type == NT_BOOLEAN_ARRAY);
205 m_val.data.arr_boolean.size);
214 assert(m_val.type == NT_DOUBLE_ARRAY);
216 m_val.data.arr_double.size);
225 assert(m_val.type == NT_STRING_ARRAY);
226 return m_string_array;
245 auto val = std::make_shared<Value>(NT_BOOLEAN,
time, private_init());
246 val->m_val.data.v_boolean =
value;
259 auto val = std::make_shared<Value>(NT_DOUBLE,
time, private_init());
260 val->m_val.data.v_double =
value;
274 auto val = std::make_shared<Value>(NT_STRING,
time, private_init());
275 val->m_string = value.
str();
276 val->m_val.data.v_string.str =
const_cast<char*
>(val->m_string.c_str());
277 val->m_val.data.v_string.len = val->m_string.size();
290 template <
typename T,
291 typename = std::enable_if_t<std::is_same<T, std::string>>>
293 template <
typename T,
294 typename std::enable_if<std::is_same<T, std::string>::value>
::type>
297 auto val = std::make_shared<Value>(NT_STRING,
time, private_init());
298 val->m_string = std::move(
value);
299 val->m_val.data.v_string.str =
const_cast<char*
>(val->m_string.c_str());
300 val->m_val.data.v_string.len = val->m_string.size();
313 auto val = std::make_shared<Value>(NT_RAW,
time, private_init());
314 val->m_string =
value;
315 val->m_val.data.v_raw.
str =
const_cast<char*
>(val->m_string.c_str());
316 val->m_val.data.v_raw.len = val->m_string.size();
329 template <
typename T,
330 typename = std::enable_if_t<std::is_same<T, std::string>>>
332 template <
typename T,
333 typename std::enable_if<std::is_same<T, std::string>::value>
::type>
336 auto val = std::make_shared<Value>(NT_RAW,
time, private_init());
337 val->m_string = std::move(
value);
338 val->m_val.data.v_raw.str =
const_cast<char*
>(val->m_string.c_str());
339 val->m_val.data.v_raw.len = val->m_string.size();
352 auto val = std::make_shared<Value>(NT_RPC,
time, private_init());
353 val->m_string =
value;
354 val->m_val.data.v_raw.
str =
const_cast<char*
>(val->m_string.c_str());
355 val->m_val.data.v_raw.len = val->m_string.size();
367 template <
typename T>
369 auto val = std::make_shared<Value>(NT_RPC,
time, private_init());
370 val->m_string = std::move(
value);
371 val->m_val.data.v_raw.str =
const_cast<char*
>(val->m_string.c_str());
372 val->m_val.data.v_raw.len = val->m_string.size();
420 std::vector<std::string>&&
value, uint64_t time = 0);
426 friend bool operator==(
const Value& lhs,
const Value& rhs);
430 std::string m_string;
431 std::vector<std::string> m_string_array;
434 bool operator==(
const Value& lhs,
const Value& rhs);
435 inline bool operator!=(
const Value& lhs,
const Value& rhs) {
436 return !(lhs == rhs);
447 #endif // NTCORE_NETWORKTABLES_NETWORKTABLEVALUE_H_
bool IsBoolean() const
Determine if entry value contains a boolean.
Definition: NetworkTableValue.h:89
static std::shared_ptr< Value > MakeRpc(StringRef value, uint64_t time=0)
Creates a rpc entry value.
Definition: NetworkTableValue.h:351
static std::shared_ptr< Value > MakeString(const Twine &value, uint64_t time=0)
Creates a string entry value.
Definition: NetworkTableValue.h:272
static std::shared_ptr< Value > MakeRaw(T &&value, uint64_t time=0)
Creates a raw entry value.
Definition: NetworkTableValue.h:335
bool IsValid() const
Determine if entry value contains a value or is unassigned.
Definition: NetworkTableValue.h:82
NetworkTables Entry Value.
Definition: ntcore_c.h:122
static std::shared_ptr< Value > MakeRaw(StringRef value, uint64_t time=0)
Creates a raw entry value.
Definition: NetworkTableValue.h:312
static std::shared_ptr< Value > MakeString(T &&value, uint64_t time=0)
Creates a string entry value.
Definition: NetworkTableValue.h:296
bool IsRpc() const
Determine if entry value contains a rpc definition.
Definition: NetworkTableValue.h:117
bool IsStringArray() const
Determine if entry value contains a string array.
Definition: NetworkTableValue.h:138
static std::shared_ptr< Value > MakeDoubleArray(ArrayRef< double > value, uint64_t time=0)
Creates a double array entry value.
bool GetBoolean() const
Get the entry's boolean value.
Definition: NetworkTableValue.h:152
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:41
ArrayRef< double > GetDoubleArray() const
Get the entry's double array value.
Definition: NetworkTableValue.h:213
static std::shared_ptr< Value > MakeStringArray(ArrayRef< std::string > value, uint64_t time=0)
Creates a string array entry value.
static std::shared_ptr< Value > MakeBooleanArray(ArrayRef< int > value, uint64_t time=0)
Creates a boolean array entry value.
std::string str() const
Return the twine contents as a std::string.
NetworkTables (ntcore) namespace.
Definition: ITable.h:21
uint64_t time() const
Get the creation time of the value.
Definition: NetworkTableValue.h:70
StringRef GetRpc() const
Get the entry's rpc definition value.
Definition: NetworkTableValue.h:192
bool IsDouble() const
Determine if entry value contains a double.
Definition: NetworkTableValue.h:96
double GetDouble() const
Get the entry's double value.
Definition: NetworkTableValue.h:162
bool IsBooleanArray() const
Determine if entry value contains a boolean array.
Definition: NetworkTableValue.h:124
bool IsDoubleArray() const
Determine if entry value contains a double array.
Definition: NetworkTableValue.h:131
NT_Type type() const
Get the data type.
Definition: NetworkTableValue.h:49
ArrayRef< int > GetBooleanArray() const
Get the entry's boolean array value.
Definition: NetworkTableValue.h:202
const NT_Value & value() const
Get the data value stored.
Definition: NetworkTableValue.h:56
ArrayRef< std::string > GetStringArray() const
Get the entry's string array value.
Definition: NetworkTableValue.h:224
StringRef GetString() const
Get the entry's string value.
Definition: NetworkTableValue.h:172
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
NT_Type
NetworkTables data types.
Definition: ntcore_c.h:52
static std::shared_ptr< Value > MakeBoolean(bool value, uint64_t time=0)
Creates a boolean entry value.
Definition: NetworkTableValue.h:244
static std::shared_ptr< Value > MakeRpc(T &&value, uint64_t time=0)
Creates a rpc entry value.
Definition: NetworkTableValue.h:368
StringRef GetRaw() const
Get the entry's raw value.
Definition: NetworkTableValue.h:182
char * str
String contents (UTF-8).
Definition: ntcore_c.h:112
uint64_t last_change() const
Get the creation time of the value.
Definition: NetworkTableValue.h:63
A network table entry value.
Definition: NetworkTableValue.h:36
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
static std::shared_ptr< Value > MakeDouble(double value, uint64_t time=0)
Creates a double entry value.
Definition: NetworkTableValue.h:258
Value NetworkTableValue
NetworkTable Value alias for similarity with Java.
Definition: NetworkTableValue.h:443
bool IsString() const
Determine if entry value contains a string.
Definition: NetworkTableValue.h:103
bool IsRaw() const
Determine if entry value contains a raw.
Definition: NetworkTableValue.h:110