source: releases/0.11.0/include/void_stack.h @ 191

Last change on this file since 191 was 150, checked in by tim, 16 years ago

integrated talloc into most of the rest of the regfi library
fixed a length validation issue

  • Property svn:keywords set to Id
File size: 4.8 KB
Line 
1/*
2 * Copyright (C) 2005,2007,2009 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: void_stack.h 150 2009-03-02 02:17:46Z tim $
18 */
19
20#ifndef _VOID_STACK_H
21#define _VOID_STACK_H
22
23#include <stdlib.h>
24#include <stdbool.h>
25#include <string.h>
26#include "talloc.h"
27
28typedef struct _void_stack
29{
30  void** elements;
31  unsigned short max_size;
32  unsigned short top;
33} void_stack;
34
35typedef struct _void_stack_iterator
36{
37  const void_stack* stack;
38  unsigned short cur;
39} void_stack_iterator;
40
41
42/* void_stack_new():
43 *  Allocates a new void_stack.
44 *
45 * Arguments:
46 *  max_size -- the maxiumum number of elements
47 *              which may be pushed onto the stack.
48 *
49 * Returns:
50 *  a pointer to the newly allocated void_stack, or NULL if an error occurred.
51 */
52void_stack* void_stack_new(unsigned short max_size);
53
54
55/* void_stack_copy():
56 *  Makes a shallow copy of void_stack.
57 *
58 * Arguments:
59 *  v -- the stack to make a copy of.
60 *
61 * Returns:
62 *  a pointer to the duplicate void_stack, or NULL If an error occurred.
63 */
64void_stack* void_stack_copy(const void_stack* v);
65
66
67/* void_stack_copy_reverse():
68 *  Makes a shallow copy of void_stack in reverse order.
69 *
70 * Arguments:
71 *  v -- the stack to make a copy of.
72 *
73 * Returns:
74 *  a pointer to the duplicate void_stack (which will be in reverse order),
75 *  or NULL If an error occurred.
76 */
77void_stack* void_stack_copy_reverse(const void_stack* v);
78
79
80/* void_stack_free():
81 *  Frees the memory associated with a void_stack, but not the elements held
82 *  on the stack.
83 *
84 * Arguments:
85 *  stack -- the stack to be free()d.
86 */
87void void_stack_free(void_stack* stack);
88
89
90/* void_stack_free_deep():
91 *  Frees the memory associated with a void_stack and the elements referenced
92 *  by the stack.  Do not use this function if the elements of the stack
93 *  are also free()d elsewhere, or contain pointers to other memory which
94 *  cannot be otherwise free()d.
95 *
96 * Arguments:
97 *  stack -- the stack to be free()d.
98 */
99void void_stack_free_deep(void_stack* stack);
100
101
102/* void_stack_size():
103 *  Query the current number of elements on a void_stack()
104 *
105 * Arguments:
106 *  stack -- the void_stack to query
107 *
108 * Returns:
109 *  the number of elements currently on the stack.
110 */
111unsigned short void_stack_size(const void_stack* stack);
112
113
114/* void_stack_pop():
115 *  Removes the top element on a void_stack and returns a reference to it.
116 *
117 * Arguments:
118 *  stack -- the void_stack to pop
119 *
120 * Returns:
121 *  a pointer to the popped stack element, or NULL if no elements exist on
122 *  the stack.
123 */
124void* void_stack_pop(void_stack* stack);
125
126
127/* void_stack_push():
128 *  Puts a new element on the top of a void_stack.
129 *
130 * Arguments:
131 *  stack -- the void_stack being modified.
132 *
133 *  e     -- the element to be added
134 *
135 * Returns:
136 *  true if the element was successfully added, false otherwise.
137 */
138bool void_stack_push(void_stack* stack, void* e);
139
140
141/* void_stack_cur():
142 *  Returns a pointer to the current element on the top of the stack.
143 *
144 * Arguments:
145 *  stack -- the void_stack being queried.
146 *
147 * Returns:
148 *  a pointer to the current element on the top of the stack, or NULL if no
149 *  elements exist in the stack.
150 */
151const void* void_stack_cur(const void_stack* stack);
152
153
154/* void_stack_iterator_new():
155 *  Creates a new iterator for the specified void_stack.
156 *
157 * Arguments:
158 *  stack -- the void_stack to be referenced by the new iterator
159 *
160 * Returns:
161 *  a new void_stack_iterator, or NULL if an error occurred.
162 */
163void_stack_iterator* void_stack_iterator_new(const void_stack* stack);
164
165
166/* void_stack_iterator_free():
167 *  Frees a void_stack_iterator.  Does not affect the void_stack referenced
168 *  by the iterator.
169 *
170 * Arguments:
171 *  iter -- the void_stack_iterator to be free()d.
172 */
173void void_stack_iterator_free(void_stack_iterator* iter);
174
175
176/* void_stack_iterator_next():
177 *  Returns a pointer to the the next element in the stack.  Iterates over
178 *  elements starting in order from the oldest element (bottom of the stack).
179 *
180 * Arguments:
181 *  iter -- the void_stack_iterator used to lookup the next element.
182 *
183 * Returns:
184 *  a pointer to the next element.
185 */
186const void* void_stack_iterator_next(void_stack_iterator* iter);
187
188
189/* XXX: for completeness, might want to add a void_stack_iterator_first()
190 *      function, to return iterator to first element
191 */
192#endif
Note: See TracBrowser for help on using the repository browser.