regfi
void_stack.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005,2007,2009-2010 Timothy D. Morgan
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 3 of the License.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16  *
17  * $Id$
18  */
19 
28 #ifndef _VOID_STACK_H
29 #define _VOID_STACK_H
30 
31 #include <stdlib.h>
32 #include <stdbool.h>
33 #include <string.h>
34 #include <talloc.h>
35 
36 #include "compat.h"
37 
39 typedef struct _void_stack
40 {
41  void** elements;
42  unsigned short max_size;
43  unsigned short top;
44 } void_stack;
45 
46 
48 typedef struct _void_stack_iterator
49 {
50  const void_stack* stack;
51  unsigned short cur;
53 
54 
63 _EXPORT()
64 void_stack* void_stack_new(unsigned short max_size);
65 
66 
73 _EXPORT()
75 
76 
84 _EXPORT()
86 
87 
93 _EXPORT()
94 void void_stack_free(void_stack* stack);
95 
96 
106 _EXPORT()
107 void void_stack_free_deep(void_stack* stack);
108 
109 
116 _EXPORT()
117 unsigned short void_stack_size(const void_stack* stack);
118 
119 
127 _EXPORT()
128 void* void_stack_pop(void_stack* stack);
129 
130 
138 _EXPORT()
139 bool void_stack_push(void_stack* stack, void* e);
140 
141 
149 _EXPORT()
150 const void* void_stack_cur(const void_stack* stack);
151 
152 
159 _EXPORT()
161 
162 
169 _EXPORT()
171 
172 
181 _EXPORT()
183 
184 
185 /* XXX: for completeness, might want to add a void_stack_iterator_first()
186  * function, to return iterator to first element
187  */
188 #endif
XXX: document this.
Definition: void_stack.h:49
XXX: document this.
Definition: void_stack.h:40
void_stack * void_stack_new(unsigned short max_size)
Allocates a new void_stack.
Definition: void_stack.c:27
void_stack * void_stack_copy_reverse(const void_stack *v)
Makes a shallow copy of void_stack in reverse order.
Definition: void_stack.c:72
unsigned short void_stack_size(const void_stack *stack)
Query the current number of elements on a void_stack()
Definition: void_stack.c:106
const void * void_stack_cur(const void_stack *stack)
Returns a pointer to the current element on the top of the stack.
Definition: void_stack.c:138
bool void_stack_push(void_stack *stack, void *e)
Puts a new element on the top of a void_stack.
Definition: void_stack.c:126
void void_stack_free(void_stack *stack)
Frees the memory associated with a void_stack, but not the elements held on the stack.
Definition: void_stack.c:91
void void_stack_iterator_free(void_stack_iterator *iter)
Frees a void_stack_iterator.
Definition: void_stack.c:167
const void * void_stack_iterator_next(void_stack_iterator *iter)
Returns a pointer to the the next element in the stack.
Definition: void_stack.c:173
void_stack_iterator * void_stack_iterator_new(const void_stack *stack)
Creates a new iterator for the specified void_stack.
Definition: void_stack.c:149
void * void_stack_pop(void_stack *stack)
Removes the top element on a void_stack and returns a reference to it.
Definition: void_stack.c:112
void_stack * void_stack_copy(const void_stack *v)
Makes a shallow copy of void_stack.
Definition: void_stack.c:53
void void_stack_free_deep(void_stack *stack)
Frees the memory associated with a void_stack and the elements referenced by the stack.
Definition: void_stack.c:97