mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +00:00
[ntcore] Value: Inline constructors
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
|
||||
#include "Value_internal.h"
|
||||
#include "networktables/NetworkTableValue.h"
|
||||
#include "ntcore_cpp.h"
|
||||
|
||||
using namespace nt;
|
||||
|
||||
@@ -70,35 +69,6 @@ void StringArrayStorage::InitNtStrings() {
|
||||
}
|
||||
}
|
||||
|
||||
Value::Value() {
|
||||
m_val.type = NT_UNASSIGNED;
|
||||
m_val.last_change = 0;
|
||||
m_val.server_time = 0;
|
||||
m_size = 0;
|
||||
}
|
||||
|
||||
Value::Value(NT_Type type, size_t size, int64_t time, const private_init&)
|
||||
: Value{type, size, time == 0 ? nt::Now() : time, 1, private_init{}} {}
|
||||
|
||||
Value::Value(NT_Type type, size_t size, int64_t time, int64_t serverTime,
|
||||
const private_init&) {
|
||||
m_val.type = type;
|
||||
m_val.last_change = time;
|
||||
m_val.server_time = serverTime;
|
||||
if (m_val.type == NT_BOOLEAN_ARRAY) {
|
||||
m_val.data.arr_boolean.arr = nullptr;
|
||||
} else if (m_val.type == NT_INTEGER_ARRAY) {
|
||||
m_val.data.arr_int.arr = nullptr;
|
||||
} else if (m_val.type == NT_FLOAT_ARRAY) {
|
||||
m_val.data.arr_float.arr = nullptr;
|
||||
} else if (m_val.type == NT_DOUBLE_ARRAY) {
|
||||
m_val.data.arr_double.arr = nullptr;
|
||||
} else if (m_val.type == NT_STRING_ARRAY) {
|
||||
m_val.data.arr_string.arr = nullptr;
|
||||
}
|
||||
m_size = size;
|
||||
}
|
||||
|
||||
Value Value::MakeBooleanArray(std::span<const bool> value, int64_t time) {
|
||||
Value val{NT_BOOLEAN_ARRAY, value.size() * sizeof(int), time, private_init{}};
|
||||
auto data = AllocateArray<int>(value.size());
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
|
||||
namespace nt {
|
||||
|
||||
// Forward declare here to avoid circular dependency on ntcore_cpp.h
|
||||
int64_t Now();
|
||||
|
||||
#if __GNUC__ >= 13
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
@@ -33,10 +36,41 @@ class Value final {
|
||||
struct private_init {};
|
||||
|
||||
public:
|
||||
Value();
|
||||
Value(NT_Type type, size_t size, int64_t time, const private_init&);
|
||||
Value() {
|
||||
m_val.type = NT_UNASSIGNED;
|
||||
m_val.last_change = 0;
|
||||
m_val.server_time = 0;
|
||||
}
|
||||
|
||||
Value(NT_Type type, size_t size, int64_t time, const private_init&)
|
||||
: Value{type, size, time == 0 ? Now() : time, 1, private_init{}} {}
|
||||
|
||||
Value(NT_Type type, size_t size, int64_t time, int64_t serverTime,
|
||||
const private_init&);
|
||||
const private_init&)
|
||||
: m_size{size} {
|
||||
m_val.type = type;
|
||||
m_val.last_change = time;
|
||||
m_val.server_time = serverTime;
|
||||
switch (type) {
|
||||
case NT_BOOLEAN_ARRAY:
|
||||
m_val.data.arr_boolean.arr = nullptr;
|
||||
break;
|
||||
case NT_INTEGER_ARRAY:
|
||||
m_val.data.arr_int.arr = nullptr;
|
||||
break;
|
||||
case NT_FLOAT_ARRAY:
|
||||
m_val.data.arr_float.arr = nullptr;
|
||||
break;
|
||||
case NT_DOUBLE_ARRAY:
|
||||
m_val.data.arr_double.arr = nullptr;
|
||||
break;
|
||||
case NT_STRING_ARRAY:
|
||||
m_val.data.arr_string.arr = nullptr;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
explicit operator bool() const { return m_val.type != NT_UNASSIGNED; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user