8 #ifndef NTCORE_NETWORKTABLES_NETWORKTABLEVALUE_H_ 9 #define NTCORE_NETWORKTABLES_NETWORKTABLEVALUE_H_ 16 #include <type_traits> 20 #include <llvm/ArrayRef.h> 21 #include <llvm/StringRef.h> 22 #include <llvm/Twine.h> 36 struct private_init {};
47 NT_Type
type()
const {
return m_val.type; }
65 uint64_t
time()
const {
return m_val.last_change; }
76 bool IsValid()
const {
return m_val.type != NT_UNASSIGNED; }
82 bool IsBoolean()
const {
return m_val.type == NT_BOOLEAN; }
88 bool IsDouble()
const {
return m_val.type == NT_DOUBLE; }
94 bool IsString()
const {
return m_val.type == NT_STRING; }
100 bool IsRaw()
const {
return m_val.type == NT_RAW; }
106 bool IsRpc()
const {
return m_val.type == NT_RPC; }
138 assert(m_val.type == NT_BOOLEAN);
139 return m_val.data.v_boolean != 0;
147 assert(m_val.type == NT_DOUBLE);
148 return m_val.data.v_double;
156 assert(m_val.type == NT_STRING);
165 assert(m_val.type == NT_RAW);
174 assert(m_val.type == NT_RPC);
183 assert(m_val.type == NT_BOOLEAN_ARRAY);
185 m_val.data.arr_boolean.size);
193 assert(m_val.type == NT_DOUBLE_ARRAY);
195 m_val.data.arr_double.size);
203 assert(m_val.type == NT_STRING_ARRAY);
204 return m_string_array;
222 auto val = std::make_shared<Value>(NT_BOOLEAN,
time, private_init());
223 val->m_val.data.v_boolean =
value;
235 auto val = std::make_shared<Value>(NT_DOUBLE,
time, private_init());
236 val->m_val.data.v_double =
value;
249 auto val = std::make_shared<Value>(NT_STRING,
time, private_init());
250 val->m_string = value.
str();
251 val->m_val.data.v_string.str =
const_cast<char*
>(val->m_string.c_str());
252 val->m_val.data.v_string.len = val->m_string.size();
264 template <
typename T,
265 typename = std::enable_if_t<std::is_same<T, std::string>>>
267 template <
typename T,
268 typename std::enable_if<std::is_same<T, std::string>::value>
::type>
271 auto val = std::make_shared<Value>(NT_STRING,
time, private_init());
272 val->m_string = std::move(
value);
273 val->m_val.data.v_string.str =
const_cast<char*
>(val->m_string.c_str());
274 val->m_val.data.v_string.len = val->m_string.size();
286 auto val = std::make_shared<Value>(NT_RAW,
time, private_init());
287 val->m_string =
value;
288 val->m_val.data.v_raw.
str =
const_cast<char*
>(val->m_string.c_str());
289 val->m_val.data.v_raw.len = val->m_string.size();
301 template <
typename T,
302 typename = std::enable_if_t<std::is_same<T, std::string>>>
304 template <
typename T,
305 typename std::enable_if<std::is_same<T, std::string>::value>
::type>
308 auto val = std::make_shared<Value>(NT_RAW,
time, private_init());
309 val->m_string = std::move(
value);
310 val->m_val.data.v_raw.str =
const_cast<char*
>(val->m_string.c_str());
311 val->m_val.data.v_raw.len = val->m_string.size();
323 auto val = std::make_shared<Value>(NT_RPC,
time, private_init());
324 val->m_string =
value;
325 val->m_val.data.v_raw.
str =
const_cast<char*
>(val->m_string.c_str());
326 val->m_val.data.v_raw.len = val->m_string.size();
337 template <
typename T>
339 auto val = std::make_shared<Value>(NT_RPC,
time, private_init());
340 val->m_string = std::move(
value);
341 val->m_val.data.v_raw.str =
const_cast<char*
>(val->m_string.c_str());
342 val->m_val.data.v_raw.len = val->m_string.size();
378 std::vector<std::string>&& value, uint64_t time = 0);
384 friend bool operator==(
const Value& lhs,
const Value& rhs);
388 std::string m_string;
389 std::vector<std::string> m_string_array;
392 bool operator==(
const Value& lhs,
const Value& rhs);
393 inline bool operator!=(
const Value& lhs,
const Value& rhs) {
394 return !(lhs == rhs);
402 #endif // NTCORE_NETWORKTABLES_NETWORKTABLEVALUE_H_ static std::shared_ptr< Value > MakeDouble(double value, uint64_t time=0)
Creates a double entry value.
Definition: NetworkTableValue.h:234
bool IsValid() const
Determine if entry value contains a value or is unassigned.
Definition: NetworkTableValue.h:76
static std::shared_ptr< Value > MakeRpc(T &&value, uint64_t time=0)
Creates a rpc entry value.
Definition: NetworkTableValue.h:338
NetworkTables Entry Value.
Definition: ntcore_c.h:110
static std::shared_ptr< Value > MakeString(const Twine &value, uint64_t time=0)
Creates a string entry value.
Definition: NetworkTableValue.h:247
bool IsBooleanArray() const
Determine if entry value contains a boolean array.
Definition: NetworkTableValue.h:112
static std::shared_ptr< Value > MakeRpc(StringRef value, uint64_t time=0)
Creates a rpc entry value.
Definition: NetworkTableValue.h:322
bool IsString() const
Determine if entry value contains a string.
Definition: NetworkTableValue.h:94
static std::shared_ptr< Value > MakeRaw(StringRef value, uint64_t time=0)
Creates a raw entry value.
Definition: NetworkTableValue.h:285
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:15
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
ArrayRef< std::string > GetStringArray() const
Get the entry's string array value.
Definition: NetworkTableValue.h:202
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:32
static std::shared_ptr< Value > MakeBoolean(bool value, uint64_t time=0)
Creates a boolean entry value.
Definition: NetworkTableValue.h:221
static std::shared_ptr< Value > MakeRaw(T &&value, uint64_t time=0)
Creates a raw entry value.
Definition: NetworkTableValue.h:307
StringRef GetRpc() const
Get the entry's rpc definition value.
Definition: NetworkTableValue.h:173
static std::shared_ptr< Value > MakeBooleanArray(ArrayRef< int > value, uint64_t time=0)
Creates a boolean array entry value.
Definition: Value.cpp:45
ArrayRef< int > GetBooleanArray() const
Get the entry's boolean array value.
Definition: NetworkTableValue.h:182
static std::shared_ptr< Value > MakeStringArray(ArrayRef< std::string > value, uint64_t time=0)
Creates a string array entry value.
Definition: Value.cpp:63
Definition: IEntryNotifier.h:16
uint64_t time() const
Get the creation time of the value.
Definition: NetworkTableValue.h:65
bool IsDoubleArray() const
Determine if entry value contains a double array.
Definition: NetworkTableValue.h:118
ArrayRef< double > GetDoubleArray() const
Get the entry's double array value.
Definition: NetworkTableValue.h:192
static std::shared_ptr< Value > MakeString(T &&value, uint64_t time=0)
Creates a string entry value.
Definition: NetworkTableValue.h:270
bool IsBoolean() const
Determine if entry value contains a boolean.
Definition: NetworkTableValue.h:82
NT_Type type() const
Get the data type.
Definition: NetworkTableValue.h:47
bool IsRpc() const
Determine if entry value contains a rpc definition.
Definition: NetworkTableValue.h:106
const NT_Value & value() const
Get the data value stored.
Definition: NetworkTableValue.h:53
static std::shared_ptr< Value > MakeDoubleArray(ArrayRef< double > value, uint64_t time=0)
Creates a double array entry value.
Definition: Value.cpp:54
double GetDouble() const
Get the entry's double value.
Definition: NetworkTableValue.h:146
StringRef GetRaw() const
Get the entry's raw value.
Definition: NetworkTableValue.h:164
bool IsRaw() const
Determine if entry value contains a raw.
Definition: NetworkTableValue.h:100
bool IsDouble() const
Determine if entry value contains a double.
Definition: NetworkTableValue.h:88
bool GetBoolean() const
Get the entry's boolean value.
Definition: NetworkTableValue.h:137
bool IsStringArray() const
Determine if entry value contains a string array.
Definition: NetworkTableValue.h:124
char * str
String contents (UTF-8).
Definition: ntcore_c.h:100
uint64_t last_change() const
Get the creation time of the value.
Definition: NetworkTableValue.h:59
A network table entry value.
Definition: NetworkTableValue.h:35
StringRef GetString() const
Get the entry's string value.
Definition: NetworkTableValue.h:155
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42