mirror of
https://github.com/Lurkki14/tuxclocker.git
synced 2024-11-24 09:10:16 -06:00
lib: add tc_readable_result_create()
This commit is contained in:
parent
d29249e0cf
commit
f200fae8f4
@ -48,6 +48,9 @@ int8_t tc_readable_node_add_child(tc_readable_node_t *parent, tc_readable_node_t
|
||||
// Convinience function for creating a new node and adding it to parent
|
||||
tc_readable_node_t *tc_readable_node_add_new_child(tc_readable_node_t *parent);
|
||||
|
||||
// Create a tc_readable_result from data, data type and validity. Avoids boilerplate in returning values from readable nodes.
|
||||
tc_readable_result_t tc_readable_result_create(enum tc_data_types type, void *data, bool valid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -50,3 +50,28 @@ tc_readable_node_t *tc_readable_node_add_new_child(tc_readable_node_t *parent) {
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
tc_readable_result_t tc_readable_result_create(enum tc_data_types type, void *data, bool valid) {
|
||||
tc_readable_result_t res;
|
||||
res.valid = valid;
|
||||
res.data.data_type = type;
|
||||
|
||||
if (!data || !valid) {
|
||||
return res;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case TC_TYPE_UINT:
|
||||
res.data.uint_value = *(uint64_t*) data;
|
||||
break;
|
||||
case TC_TYPE_INT:
|
||||
res.data.int_value = *(int64_t*) data;
|
||||
case TC_TYPE_DOUBLE:
|
||||
res.data.uint_value = *(double*) data;
|
||||
break;
|
||||
default:
|
||||
res.valid = false;
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user