forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.h
64 lines (55 loc) · 1.52 KB
/
node.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* @file node.h
*
* @brief Used for building a tree of a key set, which is used on writing.
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*
*/
#ifndef ELEKTRA_PLUGIN_TOML_NODE_H
#define ELEKTRA_PLUGIN_TOML_NODE_H
#include <kdb.h>
#include <stdbool.h>
typedef enum
{
NT_ARRAY,
NT_SIMPLE_TABLE,
NT_INLINE_TABLE,
NT_TABLE_ARRAY,
NT_LIST_ELEMENT,
NT_LEAF,
NT_ROOT
} NodeType;
typedef struct Node_
{
Key * key;
NodeType type;
struct Node_ * parent;
char * relativeName;
size_t childCount;
size_t childSize;
struct Node_ ** children;
} Node;
/*
* @brief Recursively builds a tree out of the given keyset.
*
* The built tree contains keys as well as additional information gathered from the keys,
* in order to make the correct writing of a TOML file easier.
*
* @params parent The root of the (sub-)tree to be created.
* @params root The root key for the given key set.
* @params keys All keys which may be a member of the tree.
* @params ksPosition Index to use for the KeySet keys (must by >=0) (replacement of internal iteration)
*
* @retval Pointer The root of the created tree
* @retval NULL On Error, the root key contains additional error information.
* */
Node * buildTree (Node * parent, Key * root, KeySet * keys, elektraCursor * ksPosition);
/*
* @brief Frees up any memory allocated within the tree and all it's children.
*
* @params node Tree to be freed
* */
void destroyTree (Node * node);
bool isFirstChildren (const Node * node);
#endif // ELEKTRA_PLUGIN_TOML_NODE_H