Skip to content

Commit

Permalink
rename zpl_adt_get
Browse files Browse the repository at this point in the history
  • Loading branch information
zpl-zak authored Jun 12, 2022
1 parent 36f0d17 commit 5bee06f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
18.0.0 - removed coroutines module
- removed timer module
- rename zpl_adt_get -> zpl_adt_query

17.0.0 - ADT API changes
zpl_adt_inset_* -> zpl_adt_append_*
Expand All @@ -10,7 +11,7 @@
16.1.1 - fix scientific notation parsing
16.1.0 - introduce ZPL_PARSER_DISABLE_ANALYSIS that disables extra parsing capabilities to offer better raw performance
at a cost of lack of node metadata.
16.0.0 - introduce a new zpl_adt_get method for flexible data retrieval
16.0.0 - introduce a new zpl_adt_query method for flexible data retrieval
"a/b/c" navigates through objects "a" and "b" to get to "c"
"arr/[foo=123]/bar" iterates over "arr" to find any object with param "foo" that matches the value "123", then gets its field called "bar"
"arr/3" retrieves the 4th element in "arr"
Expand Down
10 changes: 5 additions & 5 deletions code/apps/examples/json_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ int main(void) {
err = zpl_json_parse(&root, (char *)fc.data, zpl_heap_allocator());
zpl_printf("Error code: %d\n", err);

zpl_json_object *nested_node_variant = zpl_adt_get(&root, "layer1/layer2/layer3");
zpl_json_object *nested_node_variant = zpl_adt_query(&root, "layer1/layer2/layer3");
ZPL_ASSERT_NOT_NULL(nested_node_variant);
ZPL_ASSERT(nested_node_variant->integer == 42);

zpl_json_object *def_value_node = zpl_adt_get(&root, "uniforms/[name=distort]/layout/[pos=y]/default_value");
zpl_json_object *def_value_node = zpl_adt_query(&root, "uniforms/[name=distort]/layout/[pos=y]/default_value");
ZPL_ASSERT_NOT_NULL(def_value_node);

zpl_json_object *num_42_node = zpl_adt_get(&root, "numbers/[value=42]");
zpl_json_object *num_42_node = zpl_adt_query(&root, "numbers/[value=42]");
ZPL_ASSERT_NOT_NULL(num_42_node);

zpl_json_object *arr_idx_node = zpl_adt_get(&root, "array/3");
zpl_json_object *arr_idx_node = zpl_adt_query(&root, "array/3");
ZPL_ASSERT_NOT_NULL(arr_idx_node);
ZPL_ASSERT(arr_idx_node->integer == 4);

zpl_json_object *arr_val_node = zpl_adt_get(&root, "array/[4]");
zpl_json_object *arr_val_node = zpl_adt_query(&root, "array/[4]");
ZPL_ASSERT_NOT_NULL(arr_val_node);

zpl_json_free(&root);
Expand Down
7 changes: 6 additions & 1 deletion code/header/adt.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ ZPL_DEF zpl_u8 zpl_adt_make_leaf(zpl_adt_node *node, char const *name, zpl_u8 ty
*
* @see code/apps/examples/json_get.c
*/
ZPL_DEF zpl_adt_node *zpl_adt_get(zpl_adt_node *node, char const *uri);
ZPL_DEF zpl_adt_node *zpl_adt_query(zpl_adt_node *node, char const *uri);

/**
* @brief Find a field node within an object by the given name.
Expand Down Expand Up @@ -370,6 +370,11 @@ ZPL_DEF zpl_adt_error zpl_adt_print_string(zpl_file *file, zpl_adt_node *node, c

/* deprecated */

ZPL_DEPRECATED_FOR(18.0.0, zpl_adt_query)
ZPL_IMPL_INLINE zpl_adt_node *zpl_adt_get(zpl_adt_node *node, char const *uri) {
return zpl_adt_query(node, uri);
}

ZPL_DEPRECATED_FOR(13.3.0, zpl_adt_str_to_number)
ZPL_IMPL_INLINE void zpl_adt_str_to_flt(zpl_adt_node *node) {
(void)zpl_adt_str_to_number(node);
Expand Down
8 changes: 4 additions & 4 deletions code/source/adt.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ zpl_internal zpl_adt_node *zpl__adt_get_field(zpl_adt_node *node, char *name, ch
return NULL;
}

zpl_adt_node *zpl_adt_get(zpl_adt_node *node, char const *uri) {
zpl_adt_node *zpl_adt_query(zpl_adt_node *node, char const *uri) {
ZPL_ASSERT_NOT_NULL(uri);

if (*uri == '/') {
Expand Down Expand Up @@ -182,7 +182,7 @@ zpl_adt_node *zpl_adt_get(zpl_adt_node *node, char const *uri) {

/* go deeper if uri continues */
if (*e) {
return zpl_adt_get(found_node, e+1);
return zpl_adt_query(found_node, e+1);
}
}
/* handle field name lookup */
Expand All @@ -191,7 +191,7 @@ zpl_adt_node *zpl_adt_get(zpl_adt_node *node, char const *uri) {

/* go deeper if uri continues */
if (*e) {
return zpl_adt_get(found_node, e+1);
return zpl_adt_query(found_node, e+1);
}
}
/* handle array index lookup */
Expand All @@ -202,7 +202,7 @@ zpl_adt_node *zpl_adt_get(zpl_adt_node *node, char const *uri) {

/* go deeper if uri continues */
if (*e) {
return zpl_adt_get(found_node, e+1);
return zpl_adt_query(found_node, e+1);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions code/tests/cases/adt.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ MODULE(adt, {
zpl_adt_node *b = zpl_adt_append_obj(a, "b");
zpl_adt_node *c = zpl_adt_append_obj(b, "c");

zpl_adt_node *node = zpl_adt_get(&root, "a/b/c");
zpl_adt_node *node = zpl_adt_query(&root, "a/b/c");

EQUALS(c, node);
});
Expand All @@ -110,7 +110,7 @@ MODULE(adt, {
zpl_adt_append_int(a2, "foo", 123);
zpl_adt_node *a3 = zpl_adt_append_obj(arr, 0);
zpl_adt_append_int(a3, "foo", 789);
zpl_adt_node *node = zpl_adt_get(&root, "arr/[foo=123]");
zpl_adt_node *node = zpl_adt_query(&root, "arr/[foo=123]");

EQUALS(a2, node);
});
Expand All @@ -122,7 +122,7 @@ MODULE(adt, {
zpl_adt_append_int(arr, 0, 1);
zpl_adt_append_int(arr, 0, 2);
zpl_adt_append_int(arr, 0, 3);
zpl_adt_node *node = zpl_adt_get(&root, "arr/1");
zpl_adt_node *node = zpl_adt_query(&root, "arr/1");

EQUALS(2, node->integer);
});
Expand All @@ -134,7 +134,7 @@ MODULE(adt, {
zpl_adt_append_int(arr, "1", 1);
zpl_adt_append_int(arr, "2", 2);
zpl_adt_append_int(arr, "3", 3);
zpl_adt_node *node = zpl_adt_get(&root, "arr/[2]");
zpl_adt_node *node = zpl_adt_query(&root, "arr/[2]");

EQUALS(2, node->integer);
});
Expand Down

0 comments on commit 5bee06f

Please sign in to comment.