Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Bishop <nicholasbishop@gmail.com>2012-08-06 03:29:43 +0400
committerNicholas Bishop <nicholasbishop@gmail.com>2012-08-06 03:29:43 +0400
commitb6bc30837596159f513d3a8ecedea6c835d60aa0 (patch)
treec6c7bc33fbe9b21e2e674e3fa3059e02d578a993 /source/blender/blenlib/BLI_stack.h
parent958dc02774b104123c6124a9185815dfe389a529 (diff)
Add an array-based generic stack structure to blenlib
Very simple stack with homogeneous contents. Provides push, pop, and is-empty operations.
Diffstat (limited to 'source/blender/blenlib/BLI_stack.h')
-rw-r--r--source/blender/blenlib/BLI_stack.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_stack.h b/source/blender/blenlib/BLI_stack.h
new file mode 100644
index 00000000000..24c2d9359d7
--- /dev/null
+++ b/source/blender/blenlib/BLI_stack.h
@@ -0,0 +1,50 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Nicholas Bishop
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ */
+
+#ifndef __BLI_STACK_H__
+#define __BLI_STACK_H__
+
+typedef struct BLI_Stack BLI_Stack;
+
+/* Create a new homogeneous stack with elements of 'elem_size' bytes */
+BLI_Stack *BLI_stack_new(int elem_size, const char *description);
+
+/* Free the stack's data and the stack itself */
+void BLI_stack_free(BLI_Stack *stack);
+
+/* Copies the source value onto the stack (note that it copies
+ * elem_size bytes from 'src', the pointer itself is not stored) */
+void BLI_stack_push(BLI_Stack *stack, void *src);
+
+/* Retrieves and removes the top element from the stack. The value is
+ * copies to 'dst', which must be at least elem_size bytes.
+ *
+ * Does not reduce amount of allocated memory.
+ *
+ * If stack is empty, 'dst' will not be modified. */
+void BLI_stack_pop(BLI_Stack *stack, void *dst);
+
+/* Returns TRUE if the stack is empty, FALSE otherwise */
+int BLI_stack_empty(const BLI_Stack *stack);
+
+#endif