Skip to content

Commit

Permalink
data tree REFACTOR add canonical getter for lyd_value
Browse files Browse the repository at this point in the history
- inline other canonical getter functions.

Signed-off-by: Christian Hopps <chopps@labn.net>
  • Loading branch information
choppsv1 authored and michalvasko committed Apr 27, 2021
1 parent eceb6da commit 46bd21b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
39 changes: 37 additions & 2 deletions src/tree_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -977,21 +977,56 @@ struct lyd_node *lyd_first_sibling(const struct lyd_node *node);
*/
int lyd_lyb_data_length(const char *data);

/**
* @brief Get the (canonical) value of a lyd_value.
*
* @param[in] ctx Context for the value
* @param[in] value value node to use.
* @return Canonical value.
*/
const char *lyd_value_get_canonical(const struct ly_ctx *ctx, const struct lyd_value *value);

/**
* @brief Get the (canonical) value of a data node.
*
* @param[in] node Data node to use.
* @return Canonical value.
*/
const char *lyd_get_value(const struct lyd_node *node);
static inline const char *
lyd_get_value(const struct lyd_node *node)
{
if (!node) {
return NULL;
}

if (!node->schema) {
return ((struct lyd_node_opaq *)node)->value;
} else if (node->schema->nodetype & LYD_NODE_TERM) {
const struct lyd_value *value = &((struct lyd_node_term *)node)->value;
return value->_canonical
? value->_canonical
: lyd_value_get_canonical(LYD_CTX(node), value);
}
return NULL;
}

/**
* @brief Get the (canonical) value of a metadata node.
*
* @param[in] meta Metadata node to use.
* @return Canonical value.
*/
const char *lyd_get_meta_value(const struct lyd_meta *meta);
static inline const char *
lyd_get_meta_value(const struct lyd_meta *meta)
{
if (meta) {
const struct lyd_value *value = &meta->value;
return value->_canonical
? value->_canonical
: lyd_value_get_canonical(meta->annotation->module->ctx, value);
}
return NULL;
}

/**
* @brief Get anydata string value.
Expand Down
29 changes: 5 additions & 24 deletions src/tree_data_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,31 +257,12 @@ lyd_parse_set_data_flags(struct lyd_node *node, struct ly_set *when_check, struc
}

API const char *
lyd_get_value(const struct lyd_node *node)
lyd_value_get_canonical(const struct ly_ctx *ctx, const struct lyd_value *value)
{
if (!node) {
return NULL;
}

if (!node->schema) {
return ((struct lyd_node_opaq *)node)->value;
} else if (node->schema->nodetype & LYD_NODE_TERM) {
const struct lyd_value *val = &((struct lyd_node_term *)node)->value;
return val->_canonical ? val->_canonical :
val->realtype->plugin->print(LYD_CTX(node), val, LY_VALUE_CANON, NULL, NULL, NULL);
}
return NULL;
}

API const char *
lyd_get_meta_value(const struct lyd_meta *meta)
{
if (!meta) {
return NULL;
}

return meta->value._canonical ? meta->value._canonical :
meta->value.realtype->plugin->print(meta->annotation->module->ctx, &meta->value, LY_VALUE_CANON, NULL, NULL, NULL);
return value->_canonical
? value->_canonical
: (const char *)value->realtype->plugin->print(
ctx, value, LY_VALUE_CANON, NULL, NULL, NULL);
}

API LY_ERR
Expand Down

0 comments on commit 46bd21b

Please sign in to comment.