X-Git-Url: http://git.droids-corp.org/?p=protos%2Flibecoli.git;a=blobdiff_plain;f=src%2Fecoli_node_many.c;fp=src%2Fecoli_node_many.c;h=91a5fbfaf23e23a3ebd8d1f224c50a19a8ca2400;hp=0850ae702a22b380dcfcf6a3e5f7549a8237347f;hb=376f5016e3979247bf0db515e47df49ba1eb82ac;hpb=249ab86786242560a3da422eb59b96479d47859a diff --git a/src/ecoli_node_many.c b/src/ecoli_node_many.c index 0850ae7..91a5fbf 100644 --- a/src/ecoli_node_many.c +++ b/src/ecoli_node_many.c @@ -24,29 +24,28 @@ EC_LOG_TYPE_REGISTER(node_many); struct ec_node_many { - struct ec_node gen; unsigned int min; unsigned int max; struct ec_node *child; }; -static int ec_node_many_parse(const struct ec_node *gen_node, +static int ec_node_many_parse(const struct ec_node *node, struct ec_parse *state, const struct ec_strvec *strvec) { - struct ec_node_many *node = (struct ec_node_many *)gen_node; + struct ec_node_many *priv = ec_node_priv(node); struct ec_parse *child_parse; struct ec_strvec *childvec = NULL; size_t off = 0, count; int ret; - for (count = 0; node->max == 0 || count < node->max; count++) { + for (count = 0; priv->max == 0 || count < priv->max; count++) { childvec = ec_strvec_ndup(strvec, off, ec_strvec_len(strvec) - off); if (childvec == NULL) goto fail; - ret = ec_node_parse_child(node->child, state, childvec); + ret = ec_node_parse_child(priv->child, state, childvec); if (ret < 0) goto fail; @@ -67,7 +66,7 @@ static int ec_node_many_parse(const struct ec_node *gen_node, off += ret; } - if (count < node->min) { + if (count < priv->min) { ec_parse_free_children(state); return EC_PARSE_NOMATCH; } @@ -80,7 +79,7 @@ fail: } static int -__ec_node_many_complete(struct ec_node_many *node, unsigned int max, +__ec_node_many_complete(struct ec_node_many *priv, unsigned int max, struct ec_comp *comp, const struct ec_strvec *strvec) { @@ -90,7 +89,7 @@ __ec_node_many_complete(struct ec_node_many *node, unsigned int max, int ret; /* first, try to complete with the child node */ - ret = ec_node_complete_child(node->child, comp, strvec); + ret = ec_node_complete_child(priv->child, comp, strvec); if (ret < 0) goto fail; @@ -109,7 +108,7 @@ __ec_node_many_complete(struct ec_node_many *node, unsigned int max, if (childvec == NULL) goto fail; - ret = ec_node_parse_child(node->child, parse, childvec); + ret = ec_node_parse_child(priv->child, parse, childvec); if (ret < 0) goto fail; @@ -128,7 +127,7 @@ __ec_node_many_complete(struct ec_node_many *node, unsigned int max, goto fail; } - ret = __ec_node_many_complete(node, max, comp, childvec); + ret = __ec_node_many_complete(priv, max, comp, childvec); ec_parse_del_last_child(parse); ec_strvec_free(childvec); childvec = NULL; @@ -145,43 +144,43 @@ fail: } static int -ec_node_many_complete(const struct ec_node *gen_node, +ec_node_many_complete(const struct ec_node *node, struct ec_comp *comp, const struct ec_strvec *strvec) { - struct ec_node_many *node = (struct ec_node_many *)gen_node; + struct ec_node_many *priv = ec_node_priv(node); - return __ec_node_many_complete(node, node->max, comp, + return __ec_node_many_complete(priv, priv->max, comp, strvec); } -static void ec_node_many_free_priv(struct ec_node *gen_node) +static void ec_node_many_free_priv(struct ec_node *node) { - struct ec_node_many *node = (struct ec_node_many *)gen_node; + struct ec_node_many *priv = ec_node_priv(node); - ec_node_free(node->child); + ec_node_free(priv->child); } static size_t -ec_node_many_get_children_count(const struct ec_node *gen_node) +ec_node_many_get_children_count(const struct ec_node *node) { - struct ec_node_many *node = (struct ec_node_many *)gen_node; + struct ec_node_many *priv = ec_node_priv(node); - if (node->child) + if (priv->child) return 1; return 0; } static int -ec_node_many_get_child(const struct ec_node *gen_node, size_t i, +ec_node_many_get_child(const struct ec_node *node, size_t i, struct ec_node **child, unsigned int *refs) { - struct ec_node_many *node = (struct ec_node_many *)gen_node; + struct ec_node_many *priv = ec_node_priv(node); if (i >= 1) return -1; - *child = node->child; + *child = priv->child; *refs = 2; return 0; } @@ -208,10 +207,10 @@ static const struct ec_config_schema ec_node_many_schema[] = { }, }; -static int ec_node_many_set_config(struct ec_node *gen_node, +static int ec_node_many_set_config(struct ec_node *node, const struct ec_config *config) { - struct ec_node_many *node = (struct ec_node_many *)gen_node; + struct ec_node_many *priv = ec_node_priv(node); const struct ec_config *child, *min, *max; child = ec_config_dict_get(config, "child"); @@ -234,17 +233,17 @@ static int ec_node_many_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); if (min == NULL) - node->min = 0; + priv->min = 0; else - node->min = min->u64; + priv->min = min->u64; if (max == NULL) - node->max = 0; + priv->max = 0; else - node->max = max->u64; + priv->max = max->u64; return 0; @@ -267,17 +266,17 @@ static struct ec_node_type ec_node_many_type = { EC_NODE_TYPE_REGISTER(ec_node_many_type); int -ec_node_many_set_params(struct ec_node *gen_node, struct ec_node *child, +ec_node_many_set_params(struct ec_node *node, struct ec_node *child, unsigned int min, unsigned int max) { const struct ec_config *cur_config = NULL; struct ec_config *config = NULL; int ret; - if (ec_node_check_type(gen_node, &ec_node_many_type) < 0) + if (ec_node_check_type(node, &ec_node_many_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 @@ -296,7 +295,7 @@ ec_node_many_set_params(struct ec_node *gen_node, struct ec_node *child, if (ec_config_dict_set(config, "max", ec_config_u64(max)) < 0) goto fail; - ret = ec_node_set_config(gen_node, config); + ret = ec_node_set_config(node, config); config = NULL; /* freed */ if (ret < 0) goto fail; @@ -312,25 +311,25 @@ fail: struct ec_node *ec_node_many(const char *id, struct ec_node *child, unsigned int min, unsigned int max) { - struct ec_node *gen_node = NULL; + struct ec_node *node = NULL; if (child == NULL) return NULL; - gen_node = ec_node_from_type(&ec_node_many_type, id); - if (gen_node == NULL) + node = ec_node_from_type(&ec_node_many_type, id); + if (node == NULL) goto fail; - if (ec_node_many_set_params(gen_node, child, min, max) < 0) { + if (ec_node_many_set_params(node, child, min, max) < 0) { child = NULL; goto fail; } child = NULL; - return gen_node; + return node; fail: - ec_node_free(gen_node); + ec_node_free(node); ec_node_free(child); return NULL; }