X-Git-Url: http://git.droids-corp.org/?p=protos%2Flibecoli.git;a=blobdiff_plain;f=src%2Fecoli_node_option.c;fp=src%2Fecoli_node_option.c;h=f2f89777f13fe3c2545d03402ec6195ba7f12a1c;hp=4b26001a00cb51fbafdc55eff58b95b636a9794b;hb=376f5016e3979247bf0db515e47df49ba1eb82ac;hpb=249ab86786242560a3da422eb59b96479d47859a diff --git a/src/ecoli_node_option.c b/src/ecoli_node_option.c index 4b26001..f2f8977 100644 --- a/src/ecoli_node_option.c +++ b/src/ecoli_node_option.c @@ -23,19 +23,18 @@ EC_LOG_TYPE_REGISTER(node_option); struct ec_node_option { - struct ec_node gen; struct ec_node *child; }; static int -ec_node_option_parse(const struct ec_node *gen_node, +ec_node_option_parse(const struct ec_node *node, struct ec_parse *state, const struct ec_strvec *strvec) { - struct ec_node_option *node = (struct ec_node_option *)gen_node; + struct ec_node_option *priv = ec_node_priv(node); int ret; - ret = ec_node_parse_child(node->child, state, strvec); + ret = ec_node_parse_child(priv->child, state, strvec); if (ret < 0) return ret; @@ -46,42 +45,42 @@ ec_node_option_parse(const struct ec_node *gen_node, } static int -ec_node_option_complete(const struct ec_node *gen_node, +ec_node_option_complete(const struct ec_node *node, struct ec_comp *comp, const struct ec_strvec *strvec) { - struct ec_node_option *node = (struct ec_node_option *)gen_node; + struct ec_node_option *priv = ec_node_priv(node); - return ec_node_complete_child(node->child, comp, strvec); + return ec_node_complete_child(priv->child, comp, strvec); } -static void ec_node_option_free_priv(struct ec_node *gen_node) +static void ec_node_option_free_priv(struct ec_node *node) { - struct ec_node_option *node = (struct ec_node_option *)gen_node; + struct ec_node_option *priv = ec_node_priv(node); - ec_node_free(node->child); + ec_node_free(priv->child); } static size_t -ec_node_option_get_children_count(const struct ec_node *gen_node) +ec_node_option_get_children_count(const struct ec_node *node) { - struct ec_node_option *node = (struct ec_node_option *)gen_node; + struct ec_node_option *priv = ec_node_priv(node); - if (node->child) + if (priv->child) return 1; return 0; } static int -ec_node_option_get_child(const struct ec_node *gen_node, size_t i, +ec_node_option_get_child(const struct ec_node *node, size_t i, struct ec_node **child, unsigned int *refs) { - struct ec_node_option *node = (struct ec_node_option *)gen_node; + struct ec_node_option *priv = ec_node_priv(node); if (i >= 1) return -1; - *child = node->child; + *child = priv->child; *refs = 2; return 0; } @@ -97,10 +96,10 @@ static const struct ec_config_schema ec_node_option_schema[] = { }, }; -static int ec_node_option_set_config(struct ec_node *gen_node, +static int ec_node_option_set_config(struct ec_node *node, const struct ec_config *config) { - struct ec_node_option *node = (struct ec_node_option *)gen_node; + struct ec_node_option *priv = ec_node_priv(node); const struct ec_config *child; child = ec_config_dict_get(config, "child"); @@ -111,9 +110,9 @@ static int ec_node_option_set_config(struct ec_node *gen_node, goto fail; } - if (node->child != NULL) - ec_node_free(node->child); - node->child = ec_node_clone(child->node); + if (priv->child != NULL) + ec_node_free(priv->child); + priv->child = ec_node_clone(child->node); return 0; @@ -136,16 +135,16 @@ static struct ec_node_type ec_node_option_type = { EC_NODE_TYPE_REGISTER(ec_node_option_type); int -ec_node_option_set_child(struct ec_node *gen_node, struct ec_node *child) +ec_node_option_set_child(struct ec_node *node, struct ec_node *child) { const struct ec_config *cur_config = NULL; struct ec_config *config = NULL; int ret; - if (ec_node_check_type(gen_node, &ec_node_option_type) < 0) + if (ec_node_check_type(node, &ec_node_option_type) < 0) goto fail; - cur_config = ec_node_get_config(gen_node); + cur_config = ec_node_get_config(node); if (cur_config == NULL) config = ec_config_dict(); else @@ -159,7 +158,7 @@ ec_node_option_set_child(struct ec_node *gen_node, struct ec_node *child) } child = NULL; /* freed */ - ret = ec_node_set_config(gen_node, config); + ret = ec_node_set_config(node, config); config = NULL; /* freed */ if (ret < 0) goto fail; @@ -174,19 +173,19 @@ fail: struct ec_node *ec_node_option(const char *id, struct ec_node *child) { - struct ec_node *gen_node = NULL; + struct ec_node *node = NULL; if (child == NULL) goto fail; - gen_node = ec_node_from_type(&ec_node_option_type, id); - if (gen_node == NULL) + node = ec_node_from_type(&ec_node_option_type, id); + if (node == NULL) goto fail; - ec_node_option_set_child(gen_node, child); + ec_node_option_set_child(node, child); child = NULL; - return gen_node; + return node; fail: ec_node_free(child);