diff options
author | sanine <sanine.not@pm.me> | 2023-02-05 16:52:42 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-02-05 16:52:42 -0600 |
commit | 24d7f717b76a3c6fba44e32c2816f2ce612a2f2c (patch) | |
tree | 34474238e08f7bff47f8ec9fe1d8c76db4b63cd6 /src/geometry | |
parent | 1ba558a9c92cd61f05a695dcd2e6f75215c0c584 (diff) |
implement kai_read_source() and add kai_release_ functions
Diffstat (limited to 'src/geometry')
-rw-r--r-- | src/geometry/geometry.c | 47 | ||||
-rw-r--r-- | src/geometry/geometry.h | 7 | ||||
-rw-r--r-- | src/geometry/geometry.test.c | 24 |
3 files changed, 73 insertions, 5 deletions
diff --git a/src/geometry/geometry.c b/src/geometry/geometry.c index 42e7970..2405ae9 100644 --- a/src/geometry/geometry.c +++ b/src/geometry/geometry.c @@ -42,6 +42,12 @@ int kai_read_float_array(struct ka_float_array_t *dest, struct kai_tag_t *src) return 0; } +void kai_release_float_array(struct ka_float_array_t fa) +{ + free(fa.id); + free(fa.buf); +} + int kai_read_param(struct ka_param_t *dest, struct kai_tag_t *src) { @@ -60,6 +66,14 @@ int kai_read_param(struct ka_param_t *dest, struct kai_tag_t *src) return 0; } +void kai_release_param(struct ka_param_t p) +{ + free(p.name); + free(p.sid); + free(p.type); + free(p.semantic); +} + int kai_read_accessor(struct ka_accessor_t *dest, struct kai_tag_t *src) { @@ -99,6 +113,16 @@ int kai_read_accessor(struct ka_accessor_t *dest, struct kai_tag_t *src) return 0; } +void kai_release_accessor(struct ka_accessor_t a) +{ + free(a.source); + int i; + for (i=0; i<a.param_count; i++) { + kai_release_param(a.param[i]); + } + free(a.param); +} + int kai_read_source(struct ka_source_t *dest, struct kai_tag_t *src) { @@ -107,5 +131,28 @@ int kai_read_source(struct ka_source_t *dest, struct kai_tag_t *src) char *id = kai_tag_attr_to_dup(src, "id"); if (id == NULL) { return -1; } + dest->id = id; + dest->name = kai_tag_attr_to_dup(src, "name"); + + struct kai_tag_t *child; + for (child = src->children; child != NULL; child = child->next) { + if (strcmp(child->type, "float_array") == 0) { + kai_read_float_array(&(dest->float_array), child); + } + else if (strcmp(child->type, "technique_common") == 0) { + kai_read_accessor(&(dest->accessor), child->children); + } + /* ignore others */ + } + return 0; } + +void kai_release_source(struct ka_source_t s) +{ + free(s.id); + free(s.name); + + kai_release_float_array(s.float_array); + kai_release_accessor(s.accessor); +} diff --git a/src/geometry/geometry.h b/src/geometry/geometry.h index a0c122c..fd6f8f3 100644 --- a/src/geometry/geometry.h +++ b/src/geometry/geometry.h @@ -5,8 +5,15 @@ #include "xml/xml.h" int kai_read_float_array(struct ka_float_array_t *dest, struct kai_tag_t *src); +void kai_release_float_array(struct ka_float_array_t fa); + int kai_read_param(struct ka_param_t *dest, struct kai_tag_t *src); +void kai_release_param(struct ka_param_t p); + int kai_read_accessor(struct ka_accessor_t *dest, struct kai_tag_t *src); +void kai_release_accessor(struct ka_accessor_t a); + int kai_read_source(struct ka_source_t *dest, struct kai_tag_t *src); +void kai_release_source(struct ka_source_t s); #endif diff --git a/src/geometry/geometry.test.c b/src/geometry/geometry.test.c index fd1f379..298de3a 100644 --- a/src/geometry/geometry.test.c +++ b/src/geometry/geometry.test.c @@ -62,8 +62,7 @@ LILY_TEST("read normal float_array") CHECK_EQF(arr.buf[1], 0.0, "%f"); CHECK_EQF(arr.buf[2], 0.5, "%f"); - free(arr.id); - free(arr.buf); + kai_release_float_array(arr); } #include LILY_PUSH_TEST() @@ -113,6 +112,8 @@ LILY_TEST("read param tag") CHECK_EQ(param.sid, NULL, "%p"); CHECK_EQS(param.type, "float"); CHECK_EQ(param.semantic, NULL, "%p"); + + kai_release_param(param); } #include LILY_PUSH_TEST() @@ -172,8 +173,7 @@ LILY_TEST("parse accessor") CHECK_EQS(acc.param[1].name, "y"); CHECK_EQS(acc.param[2].name, "z"); - free(acc.source); - for (int i=0; i<3; i++) free(acc.param[i].name); + kai_release_accessor(acc); } #include LILY_PUSH_TEST() @@ -214,13 +214,27 @@ LILY_TEST("read source correctly") "<source id=\"source\">" " <float_array count=\"1\">0.0</float_array>" " <technique_common>" - " <accessor count=\"1\" id=\"xxx\">" + " <accessor count=\"1\" source=\"xxx\">" " <param type=\"float\" />" " </accessor>" " </technique_common>" "</source>" ); + + struct ka_source_t source; + int result = kai_read_source(&source, t); + kai_tag_destroy(t); + + CHECK_EQ(result, 0, "%d"); + REQUIRE_EQS(source.id, "source"); + CHECK_EQS(source.name, NULL); + + CHECK_EQ(source.float_array.count, 1, "%d"); + CHECK_EQS(source.accessor.source, "xxx"); + + kai_release_source(source); } +#include LILY_PUSH_TEST() #define LILY_FILE_END |