Libecoli 0.10.1
Extensible COmmand LIne library
 
Loading...
Searching...
No Matches
node.h
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
3 */
4
48
49#pragma once
50
51#include <stdbool.h>
52#include <stdio.h>
53#include <sys/queue.h>
54#include <sys/types.h>
55
59#define EC_NO_ID ""
60
62struct ec_node;
63
64struct ec_pnode;
65struct ec_comp;
66struct ec_strvec;
67struct ec_dict;
68struct ec_config;
69struct ec_config_schema;
70
80#define EC_NODE_TYPE_REGISTER(t) \
81 static void ec_node_init_##t(void); \
82 static void __attribute__((constructor, used)) ec_node_init_##t(void) \
83 { \
84 if (ec_node_type_register(&t, 0) < 0) \
85 fprintf(stderr, "cannot register node type %s\n", t.name); \
86 }
87
101#define EC_NODE_TYPE_REGISTER_OVERRIDE(t) \
102 static void ec_node_init_##t(void); \
103 static void __attribute__((constructor, used)) ec_node_init_##t(void) \
104 { \
105 if (ec_node_type_register(&t, 1) < 0) \
106 fprintf(stderr, "cannot register node type %s\n", t.name); \
107 }
108
130typedef int (*ec_node_set_config_t)(struct ec_node *node, const struct ec_config *config);
131
155typedef int (*ec_parse_t)(
156 const struct ec_node *node,
157 struct ec_pnode *pstate,
158 const struct ec_strvec *strvec
159);
160
202typedef int (*ec_complete_t)(
203 const struct ec_node *node,
204 struct ec_comp *comp,
205 const struct ec_strvec *strvec
206);
207
233typedef char *(*ec_node_desc_t)(const struct ec_node *);
234
249typedef int (*ec_node_init_priv_t)(struct ec_node *);
250
260typedef void (*ec_node_free_priv_t)(struct ec_node *);
261
272typedef size_t (*ec_node_get_children_count_t)(const struct ec_node *);
273
290typedef int (*ec_node_get_child_t)(
291 const struct ec_node *,
292 size_t i,
293 struct ec_node **child,
294 unsigned int *refs
295);
296
305 TAILQ_ENTRY(ec_node_type) next;
306 const char *name;
309 const struct ec_config_schema *schema;
310 size_t size;
311 ec_node_set_config_t set_config;
312 ec_parse_t parse;
313 ec_complete_t complete;
314 ec_node_desc_t desc;
315 ec_node_init_priv_t init_priv;
316 ec_node_free_priv_t free_priv;
318 ec_node_get_children_count_t get_children_count;
319 ec_node_get_child_t get_child;
320};
321
325TAILQ_HEAD(ec_node_type_list, ec_node_type);
326
331extern struct ec_node_type_list node_type_list;
332
349int ec_node_type_register(struct ec_node_type *type, bool override);
350
359const struct ec_node_type *ec_node_type_lookup(const char *name);
360
367void ec_node_type_dump(FILE *out);
368
378const struct ec_config_schema *ec_node_type_schema(const struct ec_node_type *type);
379
388const char *ec_node_type_name(const struct ec_node_type *type);
389
402struct ec_node *ec_node_from_type(const struct ec_node_type *type, const char *id);
403
417struct ec_node *ec_node(const char *typename, const char *id);
418
432struct ec_node *ec_node_clone(struct ec_node *node);
433
440void ec_node_free(struct ec_node *node);
441
458int ec_node_set_config(struct ec_node *node, struct ec_config *config);
459
470const struct ec_config *ec_node_get_config(const struct ec_node *node);
471
480size_t ec_node_get_children_count(const struct ec_node *node);
481
494int ec_node_get_child(const struct ec_node *node, size_t i, struct ec_node **child);
495
504const struct ec_node_type *ec_node_type(const struct ec_node *node);
505
517struct ec_dict *ec_node_attrs(const struct ec_node *node);
518
527const char *ec_node_id(const struct ec_node *node);
528
538char *ec_node_desc(const struct ec_node *node);
539
548void ec_node_dump(FILE *out, const struct ec_node *node);
549
563struct ec_node *ec_node_find(struct ec_node *node, const char *id);
564
583struct ec_node *ec_node_find_next(struct ec_node *root, const struct ec_node *prev, const char *id);
584
595int ec_node_check_type(const struct ec_node *node, const struct ec_node_type *type);
596
605const char *ec_node_get_type_name(const struct ec_node *node);
606
615void *ec_node_priv(const struct ec_node *node);
616
625void ec_node_schema_dump(FILE *out, const struct ec_node *node);
626
struct ec_comp * ec_comp(void)
struct ec_dict * ec_dict(void)
struct ec_node * ec_node_clone(struct ec_node *node)
const char * ec_node_id(const struct ec_node *node)
int ec_node_get_child(const struct ec_node *node, size_t i, struct ec_node **child)
const char * ec_node_get_type_name(const struct ec_node *node)
struct ec_node * ec_node_from_type(const struct ec_node_type *type, const char *id)
void ec_node_dump(FILE *out, const struct ec_node *node)
void(* ec_node_free_priv_t)(struct ec_node *)
Definition node.h:260
struct ec_node * ec_node_find_next(struct ec_node *root, const struct ec_node *prev, const char *id)
struct ec_node * ec_node(const char *typename, const char *id)
struct ec_dict * ec_node_attrs(const struct ec_node *node)
struct ec_node * ec_node_find(struct ec_node *node, const char *id)
void ec_node_type_dump(FILE *out)
int ec_node_check_type(const struct ec_node *node, const struct ec_node_type *type)
int ec_node_set_config(struct ec_node *node, struct ec_config *config)
struct ec_node_type_list node_type_list
int(* ec_node_get_child_t)(const struct ec_node *, size_t i, struct ec_node **child, unsigned int *refs)
Definition node.h:290
size_t ec_node_get_children_count(const struct ec_node *node)
char *(* ec_node_desc_t)(const struct ec_node *)
Definition node.h:233
const struct ec_config * ec_node_get_config(const struct ec_node *node)
int(* ec_node_set_config_t)(struct ec_node *node, const struct ec_config *config)
Definition node.h:130
const struct ec_node_type * ec_node_type(const struct ec_node *node)
int ec_node_type_register(struct ec_node_type *type, bool override)
int(* ec_node_init_priv_t)(struct ec_node *)
Definition node.h:249
int(* ec_complete_t)(const struct ec_node *node, struct ec_comp *comp, const struct ec_strvec *strvec)
Definition node.h:202
size_t(* ec_node_get_children_count_t)(const struct ec_node *)
Definition node.h:272
const struct ec_config_schema * ec_node_type_schema(const struct ec_node_type *type)
char * ec_node_desc(const struct ec_node *node)
int(* ec_parse_t)(const struct ec_node *node, struct ec_pnode *pstate, const struct ec_strvec *strvec)
Definition node.h:155
void ec_node_schema_dump(FILE *out, const struct ec_node *node)
const struct ec_node_type * ec_node_type_lookup(const char *name)
const char * ec_node_type_name(const struct ec_node_type *type)
void * ec_node_priv(const struct ec_node *node)
void ec_node_free(struct ec_node *node)
struct ec_pnode * ec_pnode(const struct ec_node *node)
struct ec_strvec * ec_strvec(void)