Changeset 169 for trunk/include/void_stack.h
- Timestamp:
- 03/03/10 14:24:58 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/void_stack.h
r168 r169 1 /** 2 * @file 3 * 4 * Copyright (C) 2005,2007,2009 Timothy D. Morgan 1 /* 2 * Copyright (C) 2005,2007,2009-2010 Timothy D. Morgan 5 3 * 6 4 * This program is free software; you can redistribute it and/or modify … … 20 18 */ 21 19 20 /** 21 *@file 22 * 23 * This is a very simple implementation of a stack which stores chunks of 24 * memory of any type. 25 */ 26 27 22 28 #ifndef _VOID_STACK_H 23 29 #define _VOID_STACK_H … … 28 34 #include "talloc.h" 29 35 36 /** XXX: document this. */ 30 37 typedef struct _void_stack 31 38 { … … 35 42 } void_stack; 36 43 44 45 /** XXX: document this. */ 37 46 typedef struct _void_stack_iterator 38 47 { … … 42 51 43 52 44 /* void_stack_new(): 45 * Allocates a new void_stack. 53 /** Allocates a new void_stack. 46 54 * 47 * Arguments: 48 * max_size -- the maxiumum number of elements 49 * which may be pushed onto the stack. 55 * @param max_size the maxiumum number of elements 56 * which may be pushed onto the stack. 50 57 * 51 * Returns:52 * a pointer to the newly allocated void_stack,or NULL if an error occurred.58 * @return a pointer to the newly allocated void_stack, 59 * or NULL if an error occurred. 53 60 */ 54 61 void_stack* void_stack_new(unsigned short max_size); 55 62 56 63 57 /* void_stack_copy(): 58 * Makes a shallow copy of void_stack. 64 /** Makes a shallow copy of void_stack. 59 65 * 60 * Arguments: 61 * v -- the stack to make a copy of. 66 * @param v the stack to make a copy of. 62 67 * 63 * Returns: 64 * a pointer to the duplicate void_stack, or NULL If an error occurred. 68 * @return a pointer to the duplicate void_stack, or NULL if an error occurred. 65 69 */ 66 70 void_stack* void_stack_copy(const void_stack* v); 67 71 68 72 69 /* void_stack_copy_reverse(): 70 * Makes a shallow copy of void_stack in reverse order. 73 /** Makes a shallow copy of void_stack in reverse order. 71 74 * 72 * Arguments: 73 * v -- the stack to make a copy of. 75 * @param v the stack to make a copy of. 74 76 * 75 * Returns: 76 * a pointer to the duplicate void_stack (which will be in reverse order), 77 * or NULL If an error occurred. 77 * @return a pointer to the duplicate void_stack 78 * (which will be in reverse order), or NULL if an error occurred. 78 79 */ 79 80 void_stack* void_stack_copy_reverse(const void_stack* v); 80 81 81 82 82 /* void_stack_free(): 83 * Frees the memory associated with a void_stack, but not the elements held 83 /** Frees the memory associated with a void_stack, but not the elements held 84 84 * on the stack. 85 85 * 86 * Arguments: 87 * stack -- the stack to be free()d. 86 * @param stack the stack to be free()d. 88 87 */ 89 88 void void_stack_free(void_stack* stack); 90 89 91 90 92 /* void_stack_free_deep(): 93 * Frees the memory associated with a void_stack and the elements referenced 94 * by the stack. Do not use this function if the elements of the stack 95 * are also free()d elsewhere, or contain pointers to other memory which 96 * cannot be otherwise free()d. 91 /** Frees the memory associated with a void_stack and the elements referenced 92 * by the stack. 97 93 * 98 * Arguments: 99 * stack -- the stack to be free()d. 94 * Do not use this function if the elements of the stack 95 * are also free()d elsewhere, or contain pointers to other memory which 96 * cannot be otherwise free()d. 97 * 98 * @param stack the stack to be free()d. 100 99 */ 101 100 void void_stack_free_deep(void_stack* stack); 102 101 103 102 104 /* void_stack_size(): 105 * Query the current number of elements on a void_stack() 103 /** Query the current number of elements on a void_stack() 106 104 * 107 * Arguments: 108 * stack -- the void_stack to query 105 * @param stack the void_stack to query 109 106 * 110 * Returns: 111 * the number of elements currently on the stack. 107 * @return the number of elements currently on the stack. 112 108 */ 113 109 unsigned short void_stack_size(const void_stack* stack); 114 110 115 111 116 /* void_stack_pop(): 117 * Removes the top element on a void_stack and returns a reference to it. 112 /** Removes the top element on a void_stack and returns a reference to it. 118 113 * 119 * Arguments: 120 * stack -- the void_stack to pop 114 * @param stack the void_stack to pop 121 115 * 122 * Returns: 123 * a pointer to the popped stack element, or NULL if no elements exist on 124 * the stack. 116 * @return a pointer to the popped stack element, or NULL if no elements exist 117 * on the stack. 125 118 */ 126 119 void* void_stack_pop(void_stack* stack); 127 120 128 121 129 /* void_stack_push(): 130 * Puts a new element on the top of a void_stack. 122 /** Puts a new element on the top of a void_stack. 131 123 * 132 * Arguments:133 * stack -- the void_stack being modified.124 * @param stack the void_stack being modified. 125 * @param e the element to be added 134 126 * 135 * e -- the element to be added 136 * 137 * Returns: 138 * true if the element was successfully added, false otherwise. 127 * @return true if the element was successfully added, false otherwise. 139 128 */ 140 129 bool void_stack_push(void_stack* stack, void* e); 141 130 142 131 143 /* void_stack_cur(): 144 * Returns a pointer to the current element on the top of the stack. 132 /** Returns a pointer to the current element on the top of the stack. 145 133 * 146 * Arguments: 147 * stack -- the void_stack being queried. 134 * @param stack the void_stack being queried. 148 135 * 149 * Returns: 150 * a pointer to the current element on the top of the stack, or NULL if no 151 * elements exist in the stack. 136 * @return a pointer to the current element on the top of the stack, or NULL if 137 * no elements exist in the stack. 152 138 */ 153 139 const void* void_stack_cur(const void_stack* stack); 154 140 155 141 156 /* void_stack_iterator_new(): 157 * Creates a new iterator for the specified void_stack. 142 /** Creates a new iterator for the specified void_stack. 158 143 * 159 * Arguments: 160 * stack -- the void_stack to be referenced by the new iterator 144 * @param stack the void_stack to be referenced by the new iterator 161 145 * 162 * Returns: 163 * a new void_stack_iterator, or NULL if an error occurred. 146 * @return a new void_stack_iterator, or NULL if an error occurred. 164 147 */ 165 148 void_stack_iterator* void_stack_iterator_new(const void_stack* stack); 166 149 167 150 168 /* void_stack_iterator_free(): 169 * Frees a void_stack_iterator. Does not affect the void_stack referenced 170 * by the iterator. 151 /** Frees a void_stack_iterator. 171 152 * 172 * Arguments: 173 * iter -- the void_stack_iterator to be free()d. 153 * Does not affect the void_stack referenced by the iterator. 154 * 155 * @param iter the void_stack_iterator to be free()d. 174 156 */ 175 157 void void_stack_iterator_free(void_stack_iterator* iter); 176 158 177 159 178 /* void_stack_iterator_next(): 179 * Returns a pointer to the the next element in the stack. Iterates over 180 * elements starting in order from the oldest element (bottom of the stack). 160 /** Returns a pointer to the the next element in the stack. 181 161 * 182 * Arguments: 183 * iter -- the void_stack_iterator used to lookup the next element. 162 * Iterates over elements starting in order from the oldest element (bottom of the stack). 184 163 * 185 * Returns: 186 * a pointer to the next element. 164 * @param iter the void_stack_iterator used to lookup the next element. 165 * 166 * @return a pointer to the next element. 187 167 */ 188 168 const void* void_stack_iterator_next(void_stack_iterator* iter);
Note: See TracChangeset
for help on using the changeset viewer.