Libecoli 0.5.0
Extensible COmmand LIne library
 
Loading...
Searching...
No Matches
ecoli_config.h
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018, Olivier MATZ <zer0@droids-corp.org>
3 */
4
11
12#ifndef ECOLI_CONFIG_
13#define ECOLI_CONFIG_
14
15#include <sys/queue.h>
16#include <stdbool.h>
17#include <stdint.h>
18#include <stdio.h>
19
20struct ec_config;
21struct ec_dict;
22
27 EC_CONFIG_TYPE_NONE = 0,
28 EC_CONFIG_TYPE_BOOL,
29 EC_CONFIG_TYPE_INT64,
30 EC_CONFIG_TYPE_UINT64,
31 EC_CONFIG_TYPE_STRING,
32 EC_CONFIG_TYPE_NODE,
33 EC_CONFIG_TYPE_LIST,
34 EC_CONFIG_TYPE_DICT,
35};
36
45 const char *key;
46 const char *desc;
47 enum ec_config_type type;
48 /* XXX flags: mandatory */
49 /* XXX default */
50
53 const struct ec_config_schema *subschema;
54};
55
56TAILQ_HEAD(ec_config_list, ec_config);
57
61struct ec_config {
63 enum ec_config_type type;
64
65 union {
66 bool boolean;
67 int64_t i64;
68 uint64_t u64;
69 char *string;
70 struct ec_node *node;
71 struct ec_dict *dict;
72 struct ec_config_list list;
73 };
74
78 TAILQ_ENTRY(ec_config) next;
79};
80
81/* schema */
82
93
103void ec_config_schema_dump(FILE *out, const struct ec_config_schema *schema);
104
118const struct ec_config_schema *
120 const char *key);
121
131ec_config_schema_type(const struct ec_config_schema *schema_elt);
132
141const struct ec_config_schema *
142ec_config_schema_sub(const struct ec_config_schema *schema_elt);
143
154bool ec_config_key_is_reserved(const char *name);
155
159extern const char *ec_config_reserved_keys[];
160
161
162/* config */
163
172enum ec_config_type ec_config_get_type(const struct ec_config *config);
173
182struct ec_config *ec_config_bool(bool boolean);
183
192struct ec_config *ec_config_i64(int64_t i64);
193
202struct ec_config *ec_config_u64(uint64_t u64);
203
213struct ec_config *ec_config_string(const char *string);
214
226struct ec_config *ec_config_node(struct ec_node *node);
227
236
245
258int ec_config_list_add(struct ec_config *list, struct ec_config *value);
259
272int ec_config_list_del(struct ec_config *list, struct ec_config *config);
273
282ssize_t ec_config_count(const struct ec_config *config);
283
295int ec_config_validate(const struct ec_config *dict,
296 const struct ec_config_schema *schema);
297
311int ec_config_dict_set(struct ec_config *dict, const char *key,
312 struct ec_config *value);
313
326int ec_config_dict_del(struct ec_config *dict, const char *key);
327
331int ec_config_cmp(const struct ec_config *config1,
332 const struct ec_config *config2);
333
337struct ec_config *ec_config_dict_get(const struct ec_config *config,
338 const char *key);
339
357
368struct ec_config *
369ec_config_list_next(struct ec_config *list, struct ec_config *config);
370
377void ec_config_free(struct ec_config *config);
378
385int ec_config_cmp(const struct ec_config *value1,
386 const struct ec_config *value2);
387
396struct ec_config *
397ec_config_dup(const struct ec_config *config);
398
407void ec_config_dump(FILE *out, const struct ec_config *config);
408
409#endif
410
int ec_config_list_del(struct ec_config *list, struct ec_config *config)
struct ec_config * ec_config_dup(const struct ec_config *config)
int ec_config_schema_validate(const struct ec_config_schema *schema)
struct ec_config * ec_config_list(void)
enum ec_config_type ec_config_schema_type(const struct ec_config_schema *schema_elt)
int ec_config_cmp(const struct ec_config *config1, const struct ec_config *config2)
struct ec_config * ec_config_node(struct ec_node *node)
int ec_config_dict_del(struct ec_config *dict, const char *key)
const struct ec_config_schema * ec_config_schema_sub(const struct ec_config_schema *schema_elt)
void ec_config_free(struct ec_config *config)
ssize_t ec_config_count(const struct ec_config *config)
const char * ec_config_reserved_keys[]
const struct ec_config_schema * ec_config_schema_lookup(const struct ec_config_schema *schema, const char *key)
ec_config_type
void ec_config_dump(FILE *out, const struct ec_config *config)
int ec_config_dict_set(struct ec_config *dict, const char *key, struct ec_config *value)
struct ec_config * ec_config_dict_get(const struct ec_config *config, const char *key)
struct ec_config * ec_config_dict(void)
int ec_config_list_add(struct ec_config *list, struct ec_config *value)
void ec_config_schema_dump(FILE *out, const struct ec_config_schema *schema)
int ec_config_validate(const struct ec_config *dict, const struct ec_config_schema *schema)
struct ec_config * ec_config_list_next(struct ec_config *list, struct ec_config *config)
struct ec_config * ec_config_list_first(struct ec_config *list)
struct ec_config * ec_config_i64(int64_t i64)
struct ec_config * ec_config_bool(bool boolean)
enum ec_config_type ec_config_get_type(const struct ec_config *config)
struct ec_config * ec_config_u64(uint64_t u64)
struct ec_config * ec_config_string(const char *string)
bool ec_config_key_is_reserved(const char *name)
struct ec_dict * ec_dict(void)
struct ec_node * ec_node(const char *typename, const char *id)