Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tree_data static functions available in api #2101

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/tree_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -3056,3 +3056,55 @@ lyd_find_target(const struct ly_path *path, const struct lyd_node *tree, struct
}
return LY_SUCCESS;
}

LIBYANG_API_DEF struct lyd_node *
lyd_parent(const struct lyd_node *node)
{
if (!node || !node->parent) {
return NULL;
}

return &node->parent->node;
}

LIBYANG_API_DEF struct lyd_node *
lyd_child(const struct lyd_node *node)
{
if (!node) {
return NULL;
}

if (!node->schema) {
/* opaq node */
return ((const struct lyd_node_opaq *)node)->child;
}

switch (node->schema->nodetype) {
case LYS_CONTAINER:
case LYS_LIST:
case LYS_RPC:
case LYS_ACTION:
case LYS_NOTIF:
return ((const struct lyd_node_inner *)node)->child;
default:
return NULL;
}
}

LIBYANG_API_DEF const char *
lyd_get_value(const struct lyd_node *node)
{
if (!node) {
return NULL;
}

if (!node->schema) {
return ((const struct lyd_node_opaq *)node)->value;
} else if (node->schema->nodetype & LYD_NODE_TERM) {
const struct lyd_value *value = &((const struct lyd_node_term *)node)->value;

return value->_canonical ? value->_canonical : lyd_value_get_canonical(LYD_CTX(node), value);
}

return NULL;
}
52 changes: 3 additions & 49 deletions src/tree_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -1004,15 +1004,7 @@ struct lyd_node_opaq {
* @return Pointer to the parent node of the @p node.
* @return NULL in case of the top-level node or if the @p node is NULL itself.
*/
static inline struct lyd_node *
lyd_parent(const struct lyd_node *node)
{
if (!node || !node->parent) {
return NULL;
}

return &node->parent->node;
}
LIBYANG_API_DECL struct lyd_node *lyd_parent(const struct lyd_node *node);

/**
* @brief Get the child pointer of a generic data node.
Expand All @@ -1024,29 +1016,7 @@ lyd_parent(const struct lyd_node *node)
* @param[in] node Node to use.
* @return Pointer to the first child node (if any) of the @p node.
*/
static inline struct lyd_node *
lyd_child(const struct lyd_node *node)
{
if (!node) {
return NULL;
}

if (!node->schema) {
/* opaq node */
return ((const struct lyd_node_opaq *)node)->child;
}

switch (node->schema->nodetype) {
case LYS_CONTAINER:
case LYS_LIST:
case LYS_RPC:
case LYS_ACTION:
case LYS_NOTIF:
return ((const struct lyd_node_inner *)node)->child;
default:
return NULL;
}
}
LIBYANG_API_DECL struct lyd_node *lyd_child(const struct lyd_node *node);

/**
* @brief Get the child pointer of a generic data node but skip its keys in case it is ::LYS_LIST.
Expand Down Expand Up @@ -1141,23 +1111,7 @@ LIBYANG_API_DECL const char *lyd_value_get_canonical(const struct ly_ctx *ctx, c
* @param[in] node Data node to use.
* @return Canonical value.
*/
static inline const char *
lyd_get_value(const struct lyd_node *node)
{
if (!node) {
return NULL;
}

if (!node->schema) {
return ((const struct lyd_node_opaq *)node)->value;
} else if (node->schema->nodetype & LYD_NODE_TERM) {
const struct lyd_value *value = &((const struct lyd_node_term *)node)->value;

return value->_canonical ? value->_canonical : lyd_value_get_canonical(LYD_CTX(node), value);
}

return NULL;
}
LIBYANG_API_DECL const char *lyd_get_value(const struct lyd_node *node);

/**
* @brief Get anydata string value.
Expand Down