11#include <initializer_list>
27#pragma GCC diagnostic push
28#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
36 struct private_init {};
41 m_val.last_change = 0;
42 m_val.server_time = 0;
52 m_val.last_change =
time;
53 m_val.server_time = serverTime;
56 m_val.data.arr_boolean.arr =
nullptr;
59 m_val.data.arr_int.arr =
nullptr;
62 m_val.data.arr_float.arr =
nullptr;
65 m_val.data.arr_double.arr =
nullptr;
68 m_val.data.arr_string.arr =
nullptr;
103 int64_t
time()
const {
return m_val.last_change; }
112 size_t size()
const {
return m_size; }
238 return m_val.data.v_boolean != 0;
248 return m_val.data.v_int;
258 return m_val.data.v_float;
268 return m_val.data.v_double;
278 return {m_val.data.v_string.str, m_val.data.v_string.len};
286 std::span<const uint8_t>
GetRaw()
const {
287 assert(m_val.type ==
NT_RAW);
288 return {m_val.data.v_raw.data, m_val.data.v_raw.size};
298 return {m_val.data.arr_boolean.arr, m_val.data.arr_boolean.size};
308 return {m_val.data.arr_int.arr, m_val.data.arr_int.size};
318 return {m_val.data.arr_float.arr, m_val.data.arr_float.size};
328 return {m_val.data.arr_double.arr, m_val.data.arr_double.size};
338 return *
static_cast<std::vector<std::string>*
>(m_storage.get());
413 auto data = std::make_shared<std::string>(
value);
415 val.m_val.
data.v_string.str =
const_cast<char*
>(data->c_str());
416 val.m_val.
data.v_string.len = data->size();
417 val.m_storage = std::move(data);
429 template <std::same_as<std::
string> T>
431 auto data = std::make_shared<std::string>(std::forward<T>(
value));
433 val.m_val.
data.v_string.str =
const_cast<char*
>(data->c_str());
434 val.m_val.
data.v_string.len = data->size();
435 val.m_storage = std::move(data);
449 std::make_shared<std::vector<uint8_t>>(
value.begin(),
value.end());
451 val.m_val.
data.v_raw.data =
const_cast<uint8_t*
>(data->data());
452 val.m_val.
data.v_raw.size = data->size();
453 val.m_storage = std::move(data);
465 template <std::same_as<std::vector<u
int8_t>> T>
467 auto data = std::make_shared<std::vector<uint8_t>>(std::forward<T>(
value));
469 val.m_val.data.v_raw.data =
const_cast<uint8_t*
>(data->data());
470 val.m_val.data.v_raw.size = data->size();
471 val.m_storage = std::move(data);
682 std::shared_ptr<void> m_storage;
687#pragma GCC diagnostic pop
A network table entry value.
Definition NetworkTableValue.hpp:35
static Value MakeBoolean(bool value, int64_t time=0)
Creates a boolean entry value.
Definition NetworkTableValue.hpp:356
static Value MakeDouble(double value, int64_t time=0)
Creates a double entry value.
Definition NetworkTableValue.hpp:398
int64_t server_time() const
Get the creation time of the value, in server time.
Definition NetworkTableValue.hpp:126
static Value MakeStringArray(std::initializer_list< std::string > value, int64_t time=0)
Creates a string array entry value.
Definition NetworkTableValue.hpp:658
bool IsDouble() const
Determine if entry value contains a double.
Definition NetworkTableValue.hpp:173
static Value MakeRaw(std::span< const uint8_t > value, int64_t time=0)
Creates a raw entry value.
Definition NetworkTableValue.hpp:447
void SetTime(int64_t time)
Set the local creation time of the value.
Definition NetworkTableValue.hpp:119
std::span< const std::string > GetStringArray() const
Get the entry's string array value.
Definition NetworkTableValue.hpp:336
std::span< const int > GetBooleanArray() const
Get the entry's boolean array value.
Definition NetworkTableValue.hpp:296
size_t size() const
Get the approximate in-memory size of the value in bytes.
Definition NetworkTableValue.hpp:112
bool IsDoubleArray() const
Determine if entry value contains a double array.
Definition NetworkTableValue.hpp:215
static Value MakeStringArray(std::span< const std::string > value, int64_t time=0)
Creates a string array entry value.
int64_t last_change() const
Get the creation time of the value, in local time.
Definition NetworkTableValue.hpp:96
static Value MakeBooleanArray(std::initializer_list< bool > value, int64_t time=0)
Creates a boolean array entry value.
Definition NetworkTableValue.hpp:493
static Value MakeFloatArray(std::initializer_list< float > value, int64_t time=0)
Creates a float array entry value.
Definition NetworkTableValue.hpp:587
static Value MakeBooleanArray(std::initializer_list< int > value, int64_t time=0)
Creates a boolean array entry value.
Definition NetworkTableValue.hpp:516
static Value MakeBooleanArray(std::span< const bool > value, int64_t time=0)
Creates a boolean array entry value.
static Value MakeBooleanArray(std::span< const int > value, int64_t time=0)
Creates a boolean array entry value.
Value()
Definition NetworkTableValue.hpp:39
int64_t GetInteger() const
Get the entry's integer value.
Definition NetworkTableValue.hpp:246
static Value MakeRaw(T &&value, int64_t time=0)
Creates a raw entry value.
Definition NetworkTableValue.hpp:466
bool IsFloatArray() const
Determine if entry value contains a float array.
Definition NetworkTableValue.hpp:208
bool IsBoolean() const
Determine if entry value contains a boolean.
Definition NetworkTableValue.hpp:152
Value(NT_Type type, size_t size, int64_t time, int64_t serverTime, const private_init &)
Definition NetworkTableValue.hpp:48
std::span< const uint8_t > GetRaw() const
Get the entry's raw value.
Definition NetworkTableValue.hpp:286
friend bool operator==(const Value &lhs, const Value &rhs)
bool IsIntegerArray() const
Determine if entry value contains an integer array.
Definition NetworkTableValue.hpp:201
static Value MakeBooleanArray(std::vector< int > &&value, int64_t time=0)
Creates a boolean array entry value.
static Value MakeString(T &&value, int64_t time=0)
Creates a string entry value.
Definition NetworkTableValue.hpp:430
static Value MakeStringArray(std::vector< std::string > &&value, int64_t time=0)
Creates a string array entry value.
bool IsRaw() const
Determine if entry value contains a raw.
Definition NetworkTableValue.hpp:187
bool IsValid() const
Determine if entry value contains a value or is unassigned.
Definition NetworkTableValue.hpp:145
static Value MakeIntegerArray(std::initializer_list< int64_t > value, int64_t time=0)
Creates an integer array entry value.
Definition NetworkTableValue.hpp:552
double GetDouble() const
Get the entry's double value.
Definition NetworkTableValue.hpp:266
Value(NT_Type type, size_t size, int64_t time, const private_init &)
Definition NetworkTableValue.hpp:45
static Value MakeFloatArray(std::span< const float > value, int64_t time=0)
Creates a float array entry value.
int64_t time() const
Get the creation time of the value, in local time.
Definition NetworkTableValue.hpp:103
std::span< const int64_t > GetIntegerArray() const
Get the entry's integer array value.
Definition NetworkTableValue.hpp:306
NT_Type type() const
Get the data type.
Definition NetworkTableValue.hpp:82
std::string_view GetString() const
Get the entry's string value.
Definition NetworkTableValue.hpp:276
static Value MakeIntegerArray(std::vector< int64_t > &&value, int64_t time=0)
Creates an integer array entry value.
bool IsString() const
Determine if entry value contains a string.
Definition NetworkTableValue.hpp:180
static Value MakeFloat(float value, int64_t time=0)
Creates a float entry value.
Definition NetworkTableValue.hpp:384
bool IsInteger() const
Determine if entry value contains an integer.
Definition NetworkTableValue.hpp:159
std::span< const double > GetDoubleArray() const
Get the entry's double array value.
Definition NetworkTableValue.hpp:326
const NT_Value & value() const
Get the data value stored.
Definition NetworkTableValue.hpp:89
static Value MakeDoubleArray(std::initializer_list< double > value, int64_t time=0)
Creates a double array entry value.
Definition NetworkTableValue.hpp:622
bool IsBooleanArray() const
Determine if entry value contains a boolean array.
Definition NetworkTableValue.hpp:194
static Value MakeIntegerArray(std::span< const int64_t > value, int64_t time=0)
Creates an integer array entry value.
static Value MakeFloatArray(std::vector< float > &&value, int64_t time=0)
Creates a float array entry value.
float GetFloat() const
Get the entry's float value.
Definition NetworkTableValue.hpp:256
bool GetBoolean() const
Get the entry's boolean value.
Definition NetworkTableValue.hpp:236
static Value MakeInteger(int64_t value, int64_t time=0)
Creates an integer entry value.
Definition NetworkTableValue.hpp:370
void SetServerTime(int64_t time)
Set the creation time of the value, in server time.
Definition NetworkTableValue.hpp:133
static Value MakeDoubleArray(std::vector< double > &&value, int64_t time=0)
Creates a double array entry value.
bool IsStringArray() const
Determine if entry value contains a string array.
Definition NetworkTableValue.hpp:222
bool IsFloat() const
Determine if entry value contains a float.
Definition NetworkTableValue.hpp:166
static Value MakeDoubleArray(std::span< const double > value, int64_t time=0)
Creates a double array entry value.
std::span< const float > GetFloatArray() const
Get the entry's float array value.
Definition NetworkTableValue.hpp:316
static Value MakeString(std::string_view value, int64_t time=0)
Creates a string entry value.
Definition NetworkTableValue.hpp:412
NT_Type
NetworkTables data types.
Definition ntcore_c.h:50
@ NT_DOUBLE
Definition ntcore_c.h:53
@ NT_BOOLEAN
Definition ntcore_c.h:52
@ NT_DOUBLE_ARRAY
Definition ntcore_c.h:57
@ NT_STRING
Definition ntcore_c.h:54
@ NT_FLOAT_ARRAY
Definition ntcore_c.h:63
@ NT_INTEGER
Definition ntcore_c.h:60
@ NT_BOOLEAN_ARRAY
Definition ntcore_c.h:56
@ NT_FLOAT
Definition ntcore_c.h:61
@ NT_STRING_ARRAY
Definition ntcore_c.h:58
@ NT_INTEGER_ARRAY
Definition ntcore_c.h:62
@ NT_UNASSIGNED
Definition ntcore_c.h:51
@ NT_RAW
Definition ntcore_c.h:55
Value NetworkTableValue
NetworkTable Value alias for similarity with Java.
Definition NetworkTableValue.hpp:696
int64_t Now()
Returns monotonic current time in 1 us increments.
NetworkTables (ntcore) namespace.
Definition NTSendable.hpp:9
bool operator==(const Value &lhs, const Value &rhs)
NetworkTables Entry Value.
Definition ntcore_c.h:132
uint8_t * data
Definition ntcore_c.h:143