X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fcore%2Ftimeseries.c;h=e5bff91c97a9fca413e3e5752f1c880403b7a80a;hb=e04534362b8993b5400e0859aae9a38cfcc08aa6;hp=06c321c3f253198e47b57303bbcbe7b30df4d6ad;hpb=325795abc4d6530149b5538d3d1136eed3195d16;p=sysdb.git diff --git a/src/core/timeseries.c b/src/core/timeseries.c index 06c321c..e5bff91 100644 --- a/src/core/timeseries.c +++ b/src/core/timeseries.c @@ -33,11 +33,53 @@ #include "core/timeseries.h" #include +#include /* * public API */ +sdb_timeseries_t * +sdb_timeseries_create(size_t data_names_len, const char * const *data_names, + size_t data_len) +{ + sdb_timeseries_t *ts; + size_t i; + + ts = calloc(1, sizeof(*ts)); + if (! ts) + return NULL; + + ts->data = calloc(data_names_len, sizeof(*ts->data)); + if (! ts->data) { + sdb_timeseries_destroy(ts); + return NULL; + } + ts->data_names_len = data_names_len; + for (i = 0; i < data_names_len; ++i) { + ts->data[i] = calloc(data_len, sizeof(**ts->data)); + if (! ts->data[i]) { + sdb_timeseries_destroy(ts); + return NULL; + } + } + ts->data_len = data_len; + + ts->data_names = calloc(data_names_len, sizeof(*ts->data_names)); + if (! ts->data_names) { + sdb_timeseries_destroy(ts); + return NULL; + } + for (i = 0; i < data_names_len; ++i) { + ts->data_names[i] = strdup(data_names[i]); + if (! ts->data_names[i]) { + sdb_timeseries_destroy(ts); + return NULL; + } + } + return ts; +} /* sdb_timeseries_create */ + void sdb_timeseries_destroy(sdb_timeseries_t *ts) { @@ -67,6 +109,7 @@ sdb_timeseries_destroy(sdb_timeseries_t *ts) } ts->data_names = NULL; ts->data_names_len = 0; + free(ts); } /* sdb_timeseries_destroy */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */