blob: 8b138743c472efc9ed605cf0f70f4d750a198f13 (
plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
//
// Created by spacekookie on 28/08/16.
//
#ifndef LIBDYNTREE_EZTREE_H
#define LIBDYNTREE_EZTREE_H
#include <dtree/dtree.h>
#include <stdlib.h>
/**
* Shortcut function that allocates a new string node. Beware however:
*
* THIS FUNCTION DOES NOT RETURN WARNINGS OR ERROR CODES!
*
* @param string
* @return
*/
static dtree *dtree_alloc_literal(const char *string)
{
dtree *node;
dtree_malloc(&node);
dtree_addliteral(node, string);
return node;
}
/**
* Shortcut function that allocates a new numerical node.
* Beware however:
*
* THIS FUNCTION DOES NOT RETURN WARNINGS OR ERROR CODES!
*
* @param num
* @return
*/
static dtree *dtree_alloc_numeral(const long num)
{
dtree *node;
dtree_malloc(&node);
dtree_addnumeral(node, num);
return node;
}
/**
* Shortcut function which creates two nodes as pair under a root
* node which is returned. Beware however:
*
* THIS FUNCTION DOES NOT RETURN WARNINGS OR ERROR CODES!
*
@param key Will be the key node
* @param val Will be the value node
* @return New root node with key-val children
*/
static dtree *dtree_allocpair_new(dtree **key, dtree **val)
{
dtree *root;
dtree_malloc(&root);
dtree_addpair(root, key, val);
return root;
}
/**
* Shortcut function which allocates a list of nodes in a list under
* a root node listly.
*
* WARNING: Return value is allocated on heap. MUST FREE MANUALLY!
* WARNING: THIS FUNCTION DOES NOT RETURN WARNINGS OR ERROR CODES!
*
* @param root
* @param count
* @return
*/
static dtree **dtree_alloc_listlist(dtree **root, unsigned int count)
{
dtree **nodes = malloc(sizeof(dtree**) * count);
dtree_malloc(root);
int i;
for(i = 0; i < count; i++)
dtree_addlist(*root, &nodes[i]);
return nodes;
}
#endif //LIBDYNTREE_EZTREE_H
|