Debian Codegraph @

collection/collection_tools.h

raw symbols SCIP
1 /*
2 COLLECTION LIBRARY
3
4 Header file for supplementary functions that provide
5 printing and debugging of collections.
6
7 Copyright (C) Dmitri Pal <[email protected]> 2009
8
9 Collection Library is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 Collection Library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with Collection Library. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #ifndef COLLECTION_TOOLS_H
24 #define COLLECTION_TOOLS_H
25
26 #include "collection.h"
27
28 /**
29 * @defgroup tools TOOLS interface
30 *
31 * Additional functions retaed to tracing,
32 * printing, debugging and serializaing collections.
33 *
34 * Functions in this module are more a sample implementation
35 * than a part of the interface. There is a chance they will
36 * change over time.
37 *
38 * @{
39 */
40
41 #ifdef HAVE_TRACE
42 #define COL_DEBUG_COLLECTION(collection) col_debug_collection(collection,COL_TRAVERSE_DEFAULT);
43 #else
44 #define COL_DEBUG_COLLECTION(collection) ;
45 #endif
46
47 /** @brief Name used for string type. */
48 #define COL_TYPE_NAME_STRING "string"
49 /** @brief Name used for binary type. */
50 #define COL_TYPE_NAME_BINARY "bin"
51 /** @brief Name used for integer type. */
52 #define COL_TYPE_NAME_INTEGER "int"
53 /** @brief Name used for unsigned integer type. */
54 #define COL_TYPE_NAME_UNSIGNED "uint"
55 /** @brief Name used for long type. */
56 #define COL_TYPE_NAME_LONG "long"
57 /** @brief Name used for unsigned long type. */
58 #define COL_TYPE_NAME_ULONG "ulong"
59 /** @brief Name used for floating point type. */
60 #define COL_TYPE_NAME_DOUBLE "double"
61 /** @brief Name used for boolean type. */
62 #define COL_TYPE_NAME_BOOL "bool"
63 /** @brief Name used for unknown type. */
64 #define COL_TYPE_NAME_UNKNOWN "unknown"
65
66 /** @brief Literal used in the default serialization. */
67 #define TEXT_COLLECTION "SET"
68 /** @brief Length of the \ref TEXT_COLLECTION literal. */
69 #define TEXT_COLLEN 3
70
71 /**
72 * @brief The data will be allocated in BLOCK_SIZE
73 * blocks during serialization.
74 */
75 #define BLOCK_SIZE 1024
76
77 /**
78 * @struct col_serial_data
79 * @brief Structure is used to incrementaly serialize collection.
80 */
81 struct col_serial_data {
82 char *buffer;
83 int size;
84 int length;
85 int nest_level;
86 };
87
88
89 /**
90 * @brief Calculate the potential size of the item.
91 *
92 * @param[in] type Type of the value.
93 * @param[in] length Length of the value.
94 *
95 * @return Maximum length the value would occupy when serialized.
96 */
97 int col_get_data_len(int type, int length);
98
99 /**
100 * @brief Grow serialization buffer.
101 *
102 * @param[in] buf_data Serialization object.
103 * @param[in] len For how much the serialization storage
104 * should be incrementally increased.
105 *
106 * @return 0 - Success.
107 * @return ENOMEM - No memory.
108 */
109 int col_grow_buffer(struct col_serial_data *buf_data, int len);
110
111 /**
112 * @brief Add special data to the serialization output.
113 *
114 * @param[in] buf_data Serialization object.
115 * @param[in] data Pointer to special data.
116 * @param[in] len Length of the data to insert.
117 *
118 * @return 0 - Success.
119 * @return ENOMEM - No memory.
120 */
121 int col_put_marker(struct col_serial_data *buf_data,
122 const void *data, int len);
123
124 /**
125 * @brief Serialization of data callback.
126 *
127 * @param[in] property_in Property to serialize.
128 * @param[in] property_len_in Length of the property to serialize.
129 * @param[in] type Type of the value.
130 * @param[in] data_in Value to serialize.
131 * @param[in] length_in Length of the value.
132 * @param[in] custom_data State data passed to callback.
133 * It is actually a serialization object.
134 * @param[in] dummy Not used. It is here because
135 * the callback needs to comply
136 * to the functions signature.
137 *
138 * @return 0 - Success.
139 * @return ENOMEM - No memory.
140 */
141 int col_serialize(const char *property_in,
142 int property_len_in,
143 int type,
144 void *data_in,
145 int length_in,
146 void *custom_data,
147 int *dummy);
148
149 /**
150 * @brief Debug property callback.
151 *
152 * @param[in] property Property to debug.
153 * @param[in] property_len Length of the property to debug.
154 * @param[in] type Type of the value.
155 * @param[in] data Value to serialize.
156 * @param[in] length Length of the value.
157 * @param[in] custom_data State data passed to the callback.
158 * @param[in] dummy Not used. It is here because
159 * the callback needs to comply
160 * to the functions signature.
161 *
162 * @return 0 - Success.
163 * @return ENOMEM - No memory.
164 */
165 int col_debug_handle(const char *property,
166 int property_len,
167 int type,
168 void *data,
169 int length,
170 void *custom_data,
171 int *dummy);
172
173 /**
174 * @brief Convenience function to debug an item.
175 *
176 * Prints item internals.
177 *
178 * @param[in] item Item to print.
179 *
180 * @return 0 - Success.
181 * @return ENOMEM - No memory.
182 */
183 int col_debug_item(struct collection_item *item);
184
185 /**
186 * @brief Print collection for debugging purposes.
187 *
188 * Prints collection internals.
189 *
190 * @param[in] handle Collection to debug.
191 * @param[in] flag See traverse flags.
192 *
193 * @return 0 - Success.
194 * @return ENOMEM - No memory.
195 */
196 int col_debug_collection(struct collection_item *handle,
197 int flag);
198
199 /**
200 * @brief Print collection data.
201 *
202 * Prints collection data.
203 * Uses traverse function to iterate through
204 * the collection.
205 *
206 * @param[in] handle Collection to print.
207 *
208 * @return 0 - Success.
209 * @return ENOMEM - No memory.
210 */
211 int col_print_collection(struct collection_item *handle);
212
213 /**
214 * @brief Print collection data.
215 *
216 * Prints collection data.
217 * Uses iterator to process the collection.
218 *
219 * @param[in] handle Collection to print.
220 *
221 * @return 0 - Success.
222 * @return ENOMEM - No memory.
223 */
224 int col_print_collection2(struct collection_item *handle);
225
226 /**
227 * @brief Find and print one property.
228 *
229 * Prints item data.
230 *
231 * @param[in] handle Collection to search.
232 * @param[in] name Item to find and print.
233 *
234 * @return 0 - Success.
235 * @return ENOMEM - No memory.
236 */
237 int col_print_item(struct collection_item *handle, const char *name);
238
239 /**
240 * @brief Convert collection to the array of properties.
241 *
242 * @param[in] handle Collection to convert.
243 * @param[in] size Will receive the number of
244 * the strings in the array.
245 * Can be NULL if caller is not interested
246 * in the size of the array.
247 * @param[in] error Will receive error value if any.
248 * Can be NULL if the caller does
249 * not care about error codes.
250 * - 0 - Success.
251 * - ENOMEM - No memory.
252 *
253 * @return List of strings that constitute
254 * the properties in the collection.
255 * Collection name is not included.
256 */
257 char **col_collection_to_list(struct collection_item *handle,
258 int *size,
259 int *error);
260
261 /**
262 * @brief Free list of properties.
263 *
264 * @param[in] str_list List to free.
265 */
266 void col_free_property_list(char **str_list);
267
268 /**
269 * @}
270 */
271
272 #endif