mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Runs clang-format on ntcore (#150)
Also updates .clang-format to match allwpilib WPIUtil was skipped
This commit is contained in:
committed by
Peter Johnson
parent
cf0ec7b9a9
commit
05ca76ea99
@@ -11,18 +11,20 @@
|
||||
|
||||
extern "C" {
|
||||
struct NT_String* NT_GetStringForTesting(const char* string, int* struct_size) {
|
||||
struct NT_String* str = static_cast<NT_String*>(std::calloc(1, sizeof(NT_String)));
|
||||
struct NT_String* str =
|
||||
static_cast<NT_String*>(std::calloc(1, sizeof(NT_String)));
|
||||
nt::ConvertToC(llvm::StringRef(string), str);
|
||||
*struct_size = sizeof(NT_String);
|
||||
return str;
|
||||
}
|
||||
|
||||
struct NT_EntryInfo* NT_GetEntryInfoForTesting(const char* name, enum NT_Type type,
|
||||
unsigned int flags,
|
||||
struct NT_EntryInfo* NT_GetEntryInfoForTesting(const char* name,
|
||||
enum NT_Type type,
|
||||
unsigned int flags,
|
||||
unsigned long long last_change,
|
||||
int* struct_size) {
|
||||
struct NT_EntryInfo* entry_info = static_cast<NT_EntryInfo*>(std::calloc(1,
|
||||
sizeof(NT_EntryInfo)));
|
||||
struct NT_EntryInfo* entry_info =
|
||||
static_cast<NT_EntryInfo*>(std::calloc(1, sizeof(NT_EntryInfo)));
|
||||
nt::ConvertToC(llvm::StringRef(name), &entry_info->name);
|
||||
entry_info->type = type;
|
||||
entry_info->flags = flags;
|
||||
@@ -36,12 +38,10 @@ void NT_FreeEntryInfoForTesting(struct NT_EntryInfo* info) {
|
||||
std::free(info);
|
||||
}
|
||||
|
||||
struct NT_ConnectionInfo* NT_GetConnectionInfoForTesting(const char* remote_id,
|
||||
const char* remote_ip,
|
||||
unsigned int remote_port,
|
||||
unsigned long long last_update,
|
||||
unsigned int protocol_version,
|
||||
int* struct_size) {
|
||||
struct NT_ConnectionInfo* NT_GetConnectionInfoForTesting(
|
||||
const char* remote_id, const char* remote_ip, unsigned int remote_port,
|
||||
unsigned long long last_update, unsigned int protocol_version,
|
||||
int* struct_size) {
|
||||
struct NT_ConnectionInfo* conn_info = static_cast<NT_ConnectionInfo*>(
|
||||
std::calloc(1, sizeof(NT_ConnectionInfo)));
|
||||
nt::ConvertToC(llvm::StringRef(remote_id), &conn_info->remote_id);
|
||||
@@ -50,7 +50,7 @@ struct NT_ConnectionInfo* NT_GetConnectionInfoForTesting(const char* remote_id,
|
||||
conn_info->last_update = last_update;
|
||||
conn_info->protocol_version = protocol_version;
|
||||
*struct_size = sizeof(NT_ConnectionInfo);
|
||||
return conn_info;
|
||||
return conn_info;
|
||||
}
|
||||
|
||||
void NT_FreeConnectionInfoForTesting(struct NT_ConnectionInfo* info) {
|
||||
@@ -59,10 +59,10 @@ void NT_FreeConnectionInfoForTesting(struct NT_ConnectionInfo* info) {
|
||||
std::free(info);
|
||||
}
|
||||
|
||||
struct NT_Value* NT_GetValueBooleanForTesting(
|
||||
unsigned long long last_change, int val,
|
||||
int* struct_size) {
|
||||
struct NT_Value* value = static_cast<NT_Value*>(std::calloc(1, sizeof(NT_Value)));
|
||||
struct NT_Value* NT_GetValueBooleanForTesting(unsigned long long last_change,
|
||||
int val, int* struct_size) {
|
||||
struct NT_Value* value =
|
||||
static_cast<NT_Value*>(std::calloc(1, sizeof(NT_Value)));
|
||||
value->type = NT_BOOLEAN;
|
||||
value->last_change = last_change;
|
||||
value->data.v_boolean = val;
|
||||
@@ -70,10 +70,10 @@ struct NT_Value* NT_GetValueBooleanForTesting(
|
||||
return value;
|
||||
}
|
||||
|
||||
struct NT_Value* NT_GetValueDoubleForTesting(
|
||||
unsigned long long last_change, double val,
|
||||
int* struct_size) {
|
||||
struct NT_Value* value = static_cast<NT_Value*>(std::calloc(1, sizeof(NT_Value)));
|
||||
struct NT_Value* NT_GetValueDoubleForTesting(unsigned long long last_change,
|
||||
double val, int* struct_size) {
|
||||
struct NT_Value* value =
|
||||
static_cast<NT_Value*>(std::calloc(1, sizeof(NT_Value)));
|
||||
value->type = NT_DOUBLE;
|
||||
value->last_change = last_change;
|
||||
value->data.v_double = val;
|
||||
@@ -81,10 +81,11 @@ struct NT_Value* NT_GetValueDoubleForTesting(
|
||||
return value;
|
||||
}
|
||||
|
||||
struct NT_Value* NT_GetValueStringForTesting(
|
||||
unsigned long long last_change,
|
||||
const char* str, int* struct_size) {
|
||||
struct NT_Value* value = static_cast<NT_Value*>(std::calloc(1, sizeof(NT_Value)));
|
||||
struct NT_Value* NT_GetValueStringForTesting(unsigned long long last_change,
|
||||
const char* str,
|
||||
int* struct_size) {
|
||||
struct NT_Value* value =
|
||||
static_cast<NT_Value*>(std::calloc(1, sizeof(NT_Value)));
|
||||
value->type = NT_STRING;
|
||||
value->last_change = last_change;
|
||||
nt::ConvertToC(llvm::StringRef(str), &value->data.v_string);
|
||||
@@ -92,10 +93,11 @@ struct NT_Value* NT_GetValueStringForTesting(
|
||||
return value;
|
||||
}
|
||||
|
||||
struct NT_Value* NT_GetValueRawForTesting(
|
||||
unsigned long long last_change,
|
||||
const char* raw, int raw_len, int* struct_size) {
|
||||
struct NT_Value* value = static_cast<NT_Value*>(std::calloc(1, sizeof(NT_Value)));
|
||||
struct NT_Value* NT_GetValueRawForTesting(unsigned long long last_change,
|
||||
const char* raw, int raw_len,
|
||||
int* struct_size) {
|
||||
struct NT_Value* value =
|
||||
static_cast<NT_Value*>(std::calloc(1, sizeof(NT_Value)));
|
||||
value->type = NT_RAW;
|
||||
value->last_change = last_change;
|
||||
nt::ConvertToC(llvm::StringRef(raw, raw_len), &value->data.v_string);
|
||||
@@ -104,10 +106,10 @@ struct NT_Value* NT_GetValueRawForTesting(
|
||||
}
|
||||
|
||||
struct NT_Value* NT_GetValueBooleanArrayForTesting(
|
||||
unsigned long long last_change,
|
||||
const int* arr, size_t array_len,
|
||||
unsigned long long last_change, const int* arr, size_t array_len,
|
||||
int* struct_size) {
|
||||
struct NT_Value* value = static_cast<NT_Value*>(std::calloc(1, sizeof(NT_Value)));
|
||||
struct NT_Value* value =
|
||||
static_cast<NT_Value*>(std::calloc(1, sizeof(NT_Value)));
|
||||
value->type = NT_BOOLEAN_ARRAY;
|
||||
value->last_change = last_change;
|
||||
value->data.arr_boolean.arr = NT_AllocateBooleanArray(array_len);
|
||||
@@ -119,54 +121,56 @@ struct NT_Value* NT_GetValueBooleanArrayForTesting(
|
||||
}
|
||||
|
||||
struct NT_Value* NT_GetValueDoubleArrayForTesting(
|
||||
unsigned long long last_change,
|
||||
const double* arr, size_t array_len,
|
||||
unsigned long long last_change, const double* arr, size_t array_len,
|
||||
int* struct_size) {
|
||||
struct NT_Value* value = static_cast<NT_Value*>(std::calloc(1, sizeof(NT_Value)));
|
||||
struct NT_Value* value =
|
||||
static_cast<NT_Value*>(std::calloc(1, sizeof(NT_Value)));
|
||||
value->type = NT_BOOLEAN;
|
||||
value->last_change = last_change;
|
||||
value->data.arr_double.arr = NT_AllocateDoubleArray(array_len);
|
||||
value->data.arr_double.size = array_len;
|
||||
std::memcpy(value->data.arr_double.arr, arr,
|
||||
value->data.arr_double.size * sizeof(int));
|
||||
value->data.arr_double.size * sizeof(int));
|
||||
*struct_size = sizeof(NT_Value);
|
||||
return value;
|
||||
}
|
||||
|
||||
struct NT_Value* NT_GetValueStringArrayForTesting(
|
||||
unsigned long long last_change,
|
||||
const struct NT_String* arr,
|
||||
size_t array_len, int* struct_size) {
|
||||
struct NT_Value* value = static_cast<NT_Value*>(std::calloc(1, sizeof(NT_Value)));
|
||||
unsigned long long last_change, const struct NT_String* arr,
|
||||
size_t array_len, int* struct_size) {
|
||||
struct NT_Value* value =
|
||||
static_cast<NT_Value*>(std::calloc(1, sizeof(NT_Value)));
|
||||
value->type = NT_BOOLEAN;
|
||||
value->last_change = last_change;
|
||||
value->data.arr_string.arr = NT_AllocateStringArray(array_len);
|
||||
value->data.arr_string.size = array_len;
|
||||
for (size_t i = 0; i < value->data.arr_string.size; ++i) {
|
||||
size_t len = arr[i].len;
|
||||
value->data.arr_string.arr[i].len = len;
|
||||
value->data.arr_string.arr[i].str = (char*)std::malloc(len + 1);
|
||||
std::memcpy(value->data.arr_string.arr[i].str, arr[i].str, len + 1);
|
||||
}
|
||||
size_t len = arr[i].len;
|
||||
value->data.arr_string.arr[i].len = len;
|
||||
value->data.arr_string.arr[i].str = (char*)std::malloc(len + 1);
|
||||
std::memcpy(value->data.arr_string.arr[i].str, arr[i].str, len + 1);
|
||||
}
|
||||
*struct_size = sizeof(NT_Value);
|
||||
return value;
|
||||
}
|
||||
// No need for free as one already exists in the main library
|
||||
|
||||
static void CopyNtValue(const struct NT_Value* copy_from, struct NT_Value* copy_to) {
|
||||
static void CopyNtValue(const struct NT_Value* copy_from,
|
||||
struct NT_Value* copy_to) {
|
||||
auto cpp_value = nt::ConvertFromC(*copy_from);
|
||||
nt::ConvertToC(*cpp_value, copy_to);
|
||||
}
|
||||
|
||||
static void CopyNtString(const struct NT_String* copy_from, struct NT_String* copy_to) {
|
||||
static void CopyNtString(const struct NT_String* copy_from,
|
||||
struct NT_String* copy_to) {
|
||||
nt::ConvertToC(llvm::StringRef(copy_from->str, copy_from->len), copy_to);
|
||||
}
|
||||
|
||||
struct NT_RpcParamDef* NT_GetRpcParamDefForTesting(const char* name,
|
||||
const struct NT_Value* val,
|
||||
int* struct_size) {
|
||||
struct NT_RpcParamDef* def = static_cast<NT_RpcParamDef*>(std::calloc(1,
|
||||
sizeof(NT_RpcParamDef)));
|
||||
struct NT_RpcParamDef* def =
|
||||
static_cast<NT_RpcParamDef*>(std::calloc(1, sizeof(NT_RpcParamDef)));
|
||||
nt::ConvertToC(llvm::StringRef(name), &def->name);
|
||||
CopyNtValue(val, &def->def_value);
|
||||
*struct_size = sizeof(NT_RpcParamDef);
|
||||
@@ -182,8 +186,8 @@ void NT_FreeRpcParamDefForTesting(struct NT_RpcParamDef* def) {
|
||||
struct NT_RpcResultDef* NT_GetRpcResultsDefForTesting(const char* name,
|
||||
enum NT_Type type,
|
||||
int* struct_size) {
|
||||
struct NT_RpcResultDef* def = static_cast<NT_RpcResultDef*>(std::calloc(1,
|
||||
sizeof(NT_RpcResultDef)));
|
||||
struct NT_RpcResultDef* def =
|
||||
static_cast<NT_RpcResultDef*>(std::calloc(1, sizeof(NT_RpcResultDef)));
|
||||
nt::ConvertToC(llvm::StringRef(name), &def->name);
|
||||
def->type = type;
|
||||
*struct_size = sizeof(NT_RpcResultDef);
|
||||
@@ -195,28 +199,25 @@ void NT_FreeRpcResultsDefForTesting(struct NT_RpcResultDef* def) {
|
||||
std::free(def);
|
||||
}
|
||||
|
||||
struct NT_RpcDefinition* NT_GetRpcDefinitionForTesting(unsigned int version,
|
||||
const char* name,
|
||||
size_t num_params,
|
||||
const struct NT_RpcParamDef* params,
|
||||
size_t num_results,
|
||||
const struct NT_RpcResultDef* results,
|
||||
int* struct_size) {
|
||||
struct NT_RpcDefinition* def = static_cast<NT_RpcDefinition*>(std::calloc(1,
|
||||
sizeof(NT_RpcDefinition)));
|
||||
struct NT_RpcDefinition* NT_GetRpcDefinitionForTesting(
|
||||
unsigned int version, const char* name, size_t num_params,
|
||||
const struct NT_RpcParamDef* params, size_t num_results,
|
||||
const struct NT_RpcResultDef* results, int* struct_size) {
|
||||
struct NT_RpcDefinition* def =
|
||||
static_cast<NT_RpcDefinition*>(std::calloc(1, sizeof(NT_RpcDefinition)));
|
||||
def->version = version;
|
||||
nt::ConvertToC(llvm::StringRef(name), &def->name);
|
||||
def->num_params = num_params;
|
||||
def->params = static_cast<NT_RpcParamDef*>(std::malloc(num_params *
|
||||
sizeof(NT_RpcParamDef)));
|
||||
for (size_t i=0; i<num_params; ++i) {
|
||||
def->params = static_cast<NT_RpcParamDef*>(
|
||||
std::malloc(num_params * sizeof(NT_RpcParamDef)));
|
||||
for (size_t i = 0; i < num_params; ++i) {
|
||||
CopyNtString(¶ms[i].name, &def->params[i].name);
|
||||
CopyNtValue(¶ms[i].def_value, &def->params[i].def_value);
|
||||
}
|
||||
def->num_results = num_results;
|
||||
def->results = static_cast<NT_RpcResultDef*>(std::malloc(num_results *
|
||||
sizeof(NT_RpcResultDef)));
|
||||
for (size_t i=0; i<num_results; ++i) {
|
||||
def->results = static_cast<NT_RpcResultDef*>(
|
||||
std::malloc(num_results * sizeof(NT_RpcResultDef)));
|
||||
for (size_t i = 0; i < num_results; ++i) {
|
||||
CopyNtString(&results[i].name, &def->results[i].name);
|
||||
def->results[i].type = results[i].type;
|
||||
}
|
||||
@@ -225,14 +226,11 @@ struct NT_RpcDefinition* NT_GetRpcDefinitionForTesting(unsigned int version,
|
||||
}
|
||||
// No need for free as one already exists in the main library
|
||||
|
||||
struct NT_RpcCallInfo* NT_GetRpcCallInfoForTesting(unsigned int rpc_id,
|
||||
unsigned int call_uid,
|
||||
const char* name,
|
||||
const char* params,
|
||||
size_t params_len,
|
||||
int* struct_size) {
|
||||
struct NT_RpcCallInfo* info = static_cast<NT_RpcCallInfo*>(std::calloc(1,
|
||||
sizeof(NT_RpcCallInfo)));
|
||||
struct NT_RpcCallInfo* NT_GetRpcCallInfoForTesting(
|
||||
unsigned int rpc_id, unsigned int call_uid, const char* name,
|
||||
const char* params, size_t params_len, int* struct_size) {
|
||||
struct NT_RpcCallInfo* info =
|
||||
static_cast<NT_RpcCallInfo*>(std::calloc(1, sizeof(NT_RpcCallInfo)));
|
||||
info->rpc_id = rpc_id;
|
||||
info->call_uid = call_uid;
|
||||
nt::ConvertToC(llvm::StringRef(name), &info->name);
|
||||
|
||||
Reference in New Issue
Block a user