hide ec_node structure
[protos/libecoli.git] / src / ecoli_node_many.c
index 0850ae7..91a5fbf 100644 (file)
 EC_LOG_TYPE_REGISTER(node_many);
 
 struct ec_node_many {
 EC_LOG_TYPE_REGISTER(node_many);
 
 struct ec_node_many {
-       struct ec_node gen;
        unsigned int min;
        unsigned int max;
        struct ec_node *child;
 };
 
        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_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;
 
        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;
 
                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;
 
                if (ret < 0)
                        goto fail;
 
@@ -67,7 +66,7 @@ static int ec_node_many_parse(const struct ec_node *gen_node,
                off += ret;
        }
 
                off += ret;
        }
 
-       if (count < node->min) {
+       if (count < priv->min) {
                ec_parse_free_children(state);
                return EC_PARSE_NOMATCH;
        }
                ec_parse_free_children(state);
                return EC_PARSE_NOMATCH;
        }
@@ -80,7 +79,7 @@ fail:
 }
 
 static int
 }
 
 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)
 {
                        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 */
        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;
 
        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;
 
                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;
 
                if (ret < 0)
                        goto fail;
 
@@ -128,7 +127,7 @@ __ec_node_many_complete(struct ec_node_many *node, unsigned int max,
                        goto fail;
                }
 
                        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;
                ec_parse_del_last_child(parse);
                ec_strvec_free(childvec);
                childvec = NULL;
@@ -145,43 +144,43 @@ fail:
 }
 
 static int
 }
 
 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_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);
 }
 
                                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
 }
 
 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
                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 **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;
 
 
        if (i >= 1)
                return -1;
 
-       *child = node->child;
+       *child = priv->child;
        *refs = 2;
        return 0;
 }
        *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)
 {
                                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");
        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;
        }
 
                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)
        if (min == NULL)
-               node->min = 0;
+               priv->min = 0;
        else
        else
-               node->min = min->u64;
+               priv->min = min->u64;
        if (max == NULL)
        if (max == NULL)
-               node->max = 0;
+               priv->max = 0;
        else
        else
-               node->max = max->u64;
+               priv->max = max->u64;
 
        return 0;
 
 
        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_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;
 
        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;
 
                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
        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;
 
        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;
        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 *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;
 
 
        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;
 
                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;
 
                child = NULL;
                goto fail;
        }
        child = NULL;
 
-       return gen_node;
+       return node;
 
 fail:
 
 fail:
-       ec_node_free(gen_node);
+       ec_node_free(node);
        ec_node_free(child);
        return NULL;
 }
        ec_node_free(child);
        return NULL;
 }