A hierarchical data management and serialisation library written in ANSI C, with a focus on simplicity, security and efficiency.
git clone https://github.com/Swarthe/ode
Include the header files src/*.h
where they are needed, and compile the source
files src/*.c
together with your project.
You may optionally modify src/ode_alloc.h
to use your preferred allocator.
Error checking is omitted for the sake of brevity.
ode_t *data;
We can create an empty object
data = ode_create("root", -1);
Or read its contents from serialised data.
data = ode_deserial(buffer, buffer_size);
Adding subordinate objects:
ode_add(data, "test1", -1);
ode_add(ode_get1(data, "test1", -1), "test2", 5);
Storing and modifying data:
ode_t *sub;
sub = ode_add(data, "emptyobj", -1);
ode_mod(sub, ODE_VALUE, "testval", -1);
ode_mod(sub, ODE_NAME, "objwithval", -1);
Removing data:
sub = ode_get(data, "test1", "test2", (char *) NULL);
ode_zero(sub, &bzero); /* Optional */
ode_del(sub);
We can obtain data directly
puts(ode_getstr(data, ODE_NAME));
fwrite(ode_getstr(data, ODE_NAME), 1, ode_getlen(data, ODE_NAME), stdout);
Or by iterating through subordinates.
ode_t *o;
for (o = ode_iter(data, NULL); o; o = ode_iter(data, o))
puts(ode_getstr(o, ODE_NAME));
Serialising data for future use:
char *buffer;
size_t buffer_size;
buffer = ode_serial(data, &buffer_size);
Freeing all data:
ode_del(data);
This library is free software and subject to the MIT license. See LICENSE.txt
for more information.