4
Implementation of the stack on top of collection library interface.
6
Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
8
Collection Library is free software: you can redistribute it and/or modify
9
it under the terms of the GNU Lesser General Public License as published by
10
the Free Software Foundation, either version 3 of the License, or
11
(at your option) any later version.
13
Collection Library is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU Lesser General Public License for more details.
18
You should have received a copy of the GNU Lesser General Public License
19
along with Collection Library. If not, see <http://www.gnu.org/licenses/>.
24
#include "collection_stack.h"
27
/* Function that creates a stack object */
28
int col_create_stack(struct collection_item **stack)
32
TRACE_FLOW_STRING("col_create_stack", "Entry point.");
34
error = col_create_collection(stack, COL_NAME_STACK, COL_CLASS_STACK);
36
TRACE_FLOW_STRING("col_create_stack", "Exit.");
40
/* Function that destroys a stack object */
41
void col_destroy_stack(struct collection_item *stack)
43
TRACE_FLOW_STRING("col_destroy_stack", "Entry point.");
45
col_destroy_collection(stack);
47
TRACE_FLOW_STRING("col_destroy_stack", "Exit");
52
int col_push_str_property(struct collection_item *stack,
53
const char *property, const char *string, int length)
57
TRACE_FLOW_STRING("col_push_str_property", "Entry point.");
59
/* Check that stack is not empty */
61
TRACE_ERROR_STRING("Stack can't be NULL", "");
65
/* Make sure it is a stack */
66
if (!col_is_of_class(stack, COL_CLASS_STACK)) {
67
TRACE_ERROR_STRING("Wrong class", "");
71
error = col_add_str_property(stack, NULL, property, string, length);
73
TRACE_FLOW_STRING("col_push_str_property", "Exit.");
77
/* Push a binary property to stack. */
78
int col_push_binary_property(struct collection_item *stack,
85
TRACE_FLOW_STRING("col_push_binary_property", "Entry point.");
87
/* Check that stack is not empty */
89
TRACE_ERROR_STRING("Stack can't be NULL", "");
93
/* Make sure it is a stack */
94
if (!col_is_of_class(stack, COL_CLASS_STACK)) {
95
TRACE_ERROR_STRING("Wrong class", "");
99
error = col_add_binary_property(stack, NULL, property, binary_data, length);
101
TRACE_FLOW_STRING("col_push_binary_property", "Exit.");
106
/* Push an int property to stack. */
107
int col_push_int_property(struct collection_item *stack,
108
const char *property,
113
TRACE_FLOW_STRING("col_push_int_property", "Entry point.");
115
/* Check that stack is not empty */
117
TRACE_ERROR_STRING("Stack can't be NULL", "");
121
/* Make sure it is a stack */
122
if (!col_is_of_class(stack, COL_CLASS_STACK)) {
123
TRACE_ERROR_STRING("Wrong class", "");
127
error = col_add_int_property(stack, NULL, property, number);
129
TRACE_FLOW_STRING("col_push_int_property", "Exit.");
133
/* Push an unsigned int property to stack. */
134
int col_push_unsigned_property(struct collection_item *stack,
135
const char *property,
140
TRACE_FLOW_STRING("col_push_unsigned_property", "Entry point.");
142
/* Check that stack is not empty */
144
TRACE_ERROR_STRING("Stack can't be NULL", "");
148
/* Make sure it is a stack */
149
if (!col_is_of_class(stack, COL_CLASS_STACK)) {
150
TRACE_ERROR_STRING("Wrong class", "");
154
error = col_add_unsigned_property(stack, NULL, property, number);
156
TRACE_FLOW_STRING("col_push_unsigned_property", "Exit.");
161
/* Push a long property. */
162
int col_push_long_property(struct collection_item *stack,
163
const char *property,
168
TRACE_FLOW_STRING("col_push_long_property", "Entry point.");
170
/* Check that stack is not empty */
172
TRACE_ERROR_STRING("Stack can't be NULL", "");
176
/* Make sure it is a stack */
177
if (!col_is_of_class(stack, COL_CLASS_STACK)) {
178
TRACE_ERROR_STRING("Wrong class", "");
182
error = col_add_long_property(stack, NULL, property, number);
184
TRACE_FLOW_STRING("col_push_long_property", "Exit.");
188
/* Push an unsigned long property. */
189
int col_push_ulong_property(struct collection_item *stack,
190
const char *property,
191
unsigned long number)
195
TRACE_FLOW_STRING("col_push_ulong_property", "Entry point.");
197
/* Check that stack is not empty */
199
TRACE_ERROR_STRING("Stack can't be NULL", "");
203
/* Make sure it is a stack */
204
if (!col_is_of_class(stack, COL_CLASS_STACK)) {
205
TRACE_ERROR_STRING("Wrong class", "");
209
error = col_add_ulong_property(stack, NULL, property, number);
211
TRACE_FLOW_STRING("col_push_ulong_property", "Exit.");
215
/* Push a double property. */
216
int col_push_double_property(struct collection_item *stack,
217
const char *property,
222
TRACE_FLOW_STRING("col_push_double_property", "Entry point.");
224
/* Check that stack is not empty */
226
TRACE_ERROR_STRING("Stack can't be NULL", "");
230
/* Make sure it is a stack */
231
if (!col_is_of_class(stack, COL_CLASS_STACK)) {
232
TRACE_ERROR_STRING("Wrong class", "");
236
error = col_add_double_property(stack, NULL, property, number);
238
TRACE_FLOW_STRING("col_push_double_property", "Exit.");
242
/* Push a bool property. */
243
int col_push_bool_property(struct collection_item *stack,
244
const char *property,
245
unsigned char logical)
249
TRACE_FLOW_STRING("col_push_bool_property", "Entry point.");
251
/* Check that stack is not empty */
253
TRACE_ERROR_STRING("Stack can't be NULL", "");
257
/* Make sure it is a stack */
258
if (!col_is_of_class(stack, COL_CLASS_STACK)) {
259
TRACE_ERROR_STRING("Wrong class", "");
263
error = col_add_bool_property(stack, NULL, property, logical);
265
TRACE_FLOW_STRING("push_double_property", "Exit.");
269
/* Push any property */
270
int col_push_any_property(struct collection_item *stack,
271
const char *property,
278
TRACE_FLOW_STRING("col_push_any_property", "Entry point.");
280
/* Check that stack is not empty */
282
TRACE_ERROR_STRING("Stack can't be NULL", "");
286
/* Make sure it is a stack */
287
if (!col_is_of_class(stack, COL_CLASS_STACK)) {
288
TRACE_ERROR_STRING("Wrong class", "");
292
error = col_add_any_property(stack, NULL, property, type, data, length);
294
TRACE_FLOW_STRING("col_push_any_property", "Exit.");
299
int col_push_item(struct collection_item *stack,
300
struct collection_item *item)
304
TRACE_FLOW_STRING("col_push_item", "Entry point.");
306
/* Check that stack is not empty */
308
TRACE_ERROR_STRING("Stack can't be NULL", "");
312
/* Make sure it is a stack */
313
if (!col_is_of_class(stack, COL_CLASS_STACK)) {
314
TRACE_ERROR_STRING("Wrong class", "");
318
error = col_insert_item_into_current(stack,
325
TRACE_FLOW_STRING("col_push_item", "Exit.");
330
int col_pop_item(struct collection_item *stack,
331
struct collection_item **item)
335
TRACE_FLOW_STRING("col_pop_item", "Entry point.");
337
/* Check that stack is not empty */
339
TRACE_ERROR_STRING("Stack can't be NULL", "");
343
/* Make sure it is a stack */
344
if (!col_is_of_class(stack, COL_CLASS_STACK)) {
345
TRACE_ERROR_STRING("Wrong class", "");
349
error = col_extract_item_from_current(stack,
356
TRACE_FLOW_STRING("col_pop_item", "Exit.");