1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

port config_helper.c to C++

This commit is contained in:
Steffen Vogel 2019-03-26 07:01:10 +01:00
parent 23979c6def
commit 618b25bf4f
9 changed files with 30 additions and 34 deletions

View file

@ -30,28 +30,21 @@
#include <villas/sample.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef LIBCONFIG_FOUND
/* Convert a libconfig object to a jansson object */
/** Convert a libconfig object to a jansson object */
json_t *config_to_json(config_setting_t *cfg);
/* Convert a jansson object into a libconfig object. */
/** Convert a jansson object into a libconfig object. */
int json_to_config(json_t *json, config_setting_t *parent);
#endif /* LIBCONFIG_FOUND */
/* Create a JSON object from command line parameters. */
json_t *json_load_cli(int argc, const char *argv[]);
int json_object_extend_str(json_t *orig, const char *str);
void json_object_extend_key_value(json_t *obj, const char *key, const char *value);
/* Merge two JSON objects recursively. */
void json_object_extend_key_value_token(json_t *obj, const char *key, const char *value);
/** Merge two JSON objects recursively. */
int json_object_extend(json_t *orig, json_t *merge);
#ifdef __cplusplus
}
#endif
json_t * json_load_cli(int argc, const char *argv[]);

View file

@ -41,6 +41,7 @@ endif()
set(LIB_SRC
super_node.cpp
config_helper.cpp
memory/heap.c
memory/hugepage.c
memory/managed.c
@ -56,7 +57,6 @@ set(LIB_SRC
stats.c
mapping.c
shmem.c
config_helper.c
signal.c
pool.c
queue.c

View file

@ -20,10 +20,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
#include <iostream>
#include <fstream>
#include <string.h>
#include <villas/node/config.h>
#include <villas/config_helper.h>
#include <villas/config_helper.hpp>
#include <villas/utils.h>
#ifdef LIBCONFIG_FOUND
@ -168,7 +171,7 @@ int json_to_config(json_t *json, config_setting_t *parent)
void json_object_extend_key_value_token(json_t *obj, const char *key, const char *value)
{
char *str = strdup(value);
char *delim = ",";
const char *delim = ",";
char *lasts;
char *token = strtok_r(str, delim, &lasts);
@ -189,7 +192,7 @@ void json_object_extend_key_value(json_t *obj, const char *key, const char *valu
double real;
long integer;
json_t *arr, *new, *existing, *subobj;
json_t *arr, *add, *existing, *subobj;
/* Is the key pointing to an object? */
subobj = obj;
@ -203,10 +206,10 @@ void json_object_extend_key_value(json_t *obj, const char *key, const char *valu
if (existing)
subobj = existing;
else {
new = json_object();
json_object_set(subobj, key1, new);
add = json_object();
json_object_set(subobj, key1, add);
subobj = new;
subobj = add;
}
key1 = key2;
@ -216,35 +219,35 @@ void json_object_extend_key_value(json_t *obj, const char *key, const char *valu
/* Try to parse as integer */
integer = strtol(value, &end, 0);
if (*end == 0) {
new = json_integer(integer);
add = json_integer(integer);
goto success;
}
/* Try to parse as floating point */
real = strtod(value, &end);
if (*end == 0) {
new = json_real(real);
add = json_real(real);
goto success;
}
/* Try to parse special types */
if (!strcmp(value, "true")) {
new = json_true();
add = json_true();
goto success;
}
if (!strcmp(value, "false")) {
new = json_false();
add = json_false();
goto success;
}
if (!strcmp(value, "null")) {
new = json_null();
add = json_null();
goto success;
}
/* Fallback to string */
new = json_string(value);
add = json_string(value);
success:
/* Does the key already exist?
@ -259,10 +262,10 @@ success:
json_array_append(arr, existing);
}
json_array_append(arr, new);
json_array_append(arr, add);
}
else
json_object_set(subobj, key1, new);
json_object_set(subobj, key1, add);
}
json_t * json_load_cli(int argc, const char *argv[])

View file

@ -34,7 +34,7 @@
#include <villas/advio.h>
#include <villas/plugin.h>
#include <villas/memory.h>
#include <villas/config_helper.h>
#include <villas/config_helper.hpp>
#include <villas/log.hpp>
#include <villas/exceptions.hpp>
#include <villas/kernel/rt.hpp>

View file

@ -40,7 +40,7 @@
#include <villas/exceptions.hpp>
#include <villas/copyright.hpp>
#include <villas/plugin.h>
#include <villas/config_helper.h>
#include <villas/config_helper.hpp>
#include <villas/kernel/rt.hpp>
#include <villas/node/config.h>

View file

@ -34,7 +34,7 @@
#include <atomic>
#include <villas/node/config.h>
#include <villas/config_helper.h>
#include <villas/config_helper.hpp>
#include <villas/super_node.hpp>
#include <villas/copyright.hpp>
#include <villas/utils.hpp>

View file

@ -28,7 +28,7 @@
#include <libconfig.h>
#include <villas/utils.h>
#include <villas/config_helper.h>
#include <villas/config_helper.hpp>
const char *cfg_example = "test : \n"
"{\n"

View file

@ -25,7 +25,7 @@
#include <criterion/parameterized.h>
#include <villas/utils.h>
#include <villas/config_helper.h>
#include <villas/config_helper.hpp>
using str = std::basic_string<char, std::char_traits<char>, criterion::allocator<char>>;

View file

@ -26,7 +26,7 @@
#include <libconfig.h>
#include <villas/config.h>
#include <villas/config_helper.h>
#include <villas/config_helper.hpp>
#include <villas/utils.hpp>
#include <villas/copyright.hpp>