dmlite
0.6
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
include
dmlite
c
any.h
Go to the documentation of this file.
1
/** @file include/dmlite/c/any.h
2
* @brief Opaque handler to pass different types of values to the API.
3
* @author Alejandro Álvarez Ayllon <aalvarez@cern.ch>
4
* @note Basically it wraps boost::any and dmlite::Extensible.
5
*/
6
#ifndef DMLITE_ANY_H
7
#define DMLITE_ANY_H
8
9
#include "
dmlite/common/config.h
"
10
#include <stddef.h>
11
#include <stdint.h>
12
13
#ifdef __cplusplus
14
extern
"C"
{
15
#endif
16
17
/**
18
* @brief Used to pass configuration values.
19
*/
20
typedef
struct
dmlite_any
dmlite_any
;
21
22
/**
23
* @brief Handles key->value pairs.
24
*/
25
typedef
struct
dmlite_any_dict
dmlite_any_dict
;
26
27
/**
28
* @brief Creates a new dmlite_any.
29
* @param str The string that will be wrapped. It is safe to free afterwards.
30
* @return A newly allocated dmlite_any.
31
*/
32
dmlite_any
*
dmlite_any_new_string
(
const
char
* str);
33
34
/**
35
* @brief Creates a new dmlite_any.
36
* @param l The long that will be wrapped.
37
* @return A newly allocated dmlite_any.
38
*/
39
dmlite_any
*
dmlite_any_new_long
(
long
l);
40
41
/**
42
* @brief Creates a new dmlite_any from an int64_t type.
43
* @param i The int64_t value.
44
* @return A newly allocated dmlite_any.
45
*/
46
dmlite_any
*
dmlite_any_new_s64
(int64_t i);
47
48
/**
49
* @brief Creates a new dmlite_any from an uint64_t type.
50
* @param i The uint64_t value.
51
* @return A newly allocated dmlite_any.
52
*/
53
dmlite_any
*
dmlite_any_new_u64
(uint64_t i);
54
55
/**
56
* @brief Creates a new dmlite_any.
57
* @param n The number of elements.
58
* @param strv The strings that will be wrapped. It is safe to free afterwards.
59
* @return A newly allocated dmlite_any.
60
* @deprecated Use dmlite_set_array instead.
61
*/
62
dmlite_any
*
dmlite_any_new_string_array
(
unsigned
n,
const
char
** strv);
63
64
/**
65
* @brief Creates a new dmlite_any.
66
* @param n The number of elements.
67
* @param lv The longs that will be wrapped.
68
* @return A newly allocated dmlite_any.
69
* @deprecated Use dmlite_set_array instead.
70
*/
71
dmlite_any
*
dmlite_any_new_long_array
(
unsigned
n,
long
* lv);
72
73
/**
74
* @brief Frees a dmlite_any.
75
* @param any The dmlite_any to destroy.
76
*/
77
void
dmlite_any_free
(
dmlite_any
* any);
78
79
/**
80
* @brief Gets the string interpretation of the dmlite_any.
81
* @details Defaults to "".
82
* @param any The dmlite_any to convert.
83
* @param buffer Where to put the string.
84
* @param bsize The size of the buffer.
85
*/
86
void
dmlite_any_to_string
(
const
dmlite_any
* any,
char
* buffer,
size_t
bsize);
87
88
/**
89
* @brief Returns the long interpretation of they dmlite_any.
90
* @details Defaults to 0.
91
* @param any The dmlite_any to convert.
92
*/
93
long
dmlite_any_to_long
(
const
dmlite_any
* any);
94
95
/**
96
* @brief Returns the int64_t interpretation of they dmlite_any.
97
* @details Defaults to 0.
98
* @param any The dmlite_any to convert.
99
*/
100
int64_t
dmlite_any_to_s64
(
const
dmlite_any
* any);
101
102
/**
103
* @brief Returns the uint64_t interpretation of they dmlite_any.
104
* @details Defaults to 0.
105
* @param any The dmlite_any to convert.
106
*/
107
uint64_t
dmlite_any_to_u64
(
const
dmlite_any
* any);
108
109
110
/**
111
* @brief Created a new generic dictionary.
112
* @return A newly allocated dmlite_any_dict.
113
*/
114
dmlite_any_dict
*
dmlite_any_dict_new
();
115
116
/**
117
* @brief Make a copy of the dictionary.
118
* @param dict The original
119
* @return A newly allocated copy of dict.
120
*/
121
dmlite_any_dict
*
dmlite_any_dict_copy
(
const
dmlite_any_dict
* dict);
122
123
/**
124
* @brief Frees a dmlite_any_dict
125
*/
126
void
dmlite_any_dict_free
(
dmlite_any_dict
* d);
127
128
/**
129
* @brief Clears the dictionary.
130
*/
131
void
dmlite_any_dict_clear
(
dmlite_any_dict
* d);
132
133
/**
134
* @brief Insert a new dmlite_any value into the dictionary.
135
* @details Replaces if already present.
136
* @param d The dictionary.
137
* @param k The key.
138
* @param v The value.
139
*/
140
void
dmlite_any_dict_insert
(
dmlite_any_dict
* d,
const
char
* k,
const
dmlite_any
* v);
141
142
/**
143
* @brief Returns how many elements there are in a specific dictionary.
144
*/
145
unsigned
long
dmlite_any_dict_count
(
const
dmlite_any_dict
* d);
146
147
/**
148
* @brief Returns the value associated with the key k.
149
* @return NULL if not found.
150
*/
151
dmlite_any
*
dmlite_any_dict_get
(
const
dmlite_any_dict
* d,
const
char
* k);
152
153
/**
154
* @brief Removes a key-value from the dictionary.
155
* @param d The dictionary.
156
* @param k The key to be removed.
157
*/
158
void
dmlite_any_dict_erase
(
dmlite_any_dict
* d,
const
char
* k);
159
160
/**
161
* @brief Generates a JSON serialization of the dictionary.
162
* @return The same pointer as buffer.
163
*/
164
char
*
dmlite_any_dict_to_json
(
const
dmlite_any_dict
* d,
char
* buffer,
size_t
bsize);
165
166
/**
167
* @brief Populates a dmlite_any_dict from a JSON string.
168
*/
169
dmlite_any_dict
*
dmlite_any_dict_from_json
(
const
char
* json);
170
171
/**
172
* @brief Puts in keys a pointer to an array of strings with all the available
173
* keys in d.
174
* @details Use dmlite_any_dict_keys_free to free.
175
* @param d The Dictionary.
176
* @param nkeys Will be set to the number of stored keys.
177
*/
178
void
dmlite_any_dict_keys
(
const
dmlite_any_dict
* d,
unsigned
* nkeys,
char
*** keys);
179
180
/**
181
* @brief Frees an array of strings allocated by dmlite_any_dict_keys.
182
* @param n The number of keys in **keys
183
* @param keys The array of keys.
184
*/
185
void
dmlite_any_dict_keys_free
(
unsigned
n,
char
** keys);
186
187
#ifdef __cplusplus
188
}
189
#endif
190
191
#endif
/* DMLITE_ANY_H */
192
Generated on Thu May 8 2014 08:04:53 for dmlite by
1.8.3.1