[Bf-blender-cvs] [52e95ad] master: BLI_stack: BLI_stack_pop_n_reverse

Campbell Barton noreply at git.blender.org
Fri Jun 19 12:24:12 CEST 2015


Commit: 52e95ad3d392a1767f9eb46c1814c6bf6d8c7a89
Author: Campbell Barton
Date:   Fri Jun 19 17:40:35 2015 +1000
Branches: master
https://developer.blender.org/rB52e95ad3d392a1767f9eb46c1814c6bf6d8c7a89

BLI_stack: BLI_stack_pop_n_reverse

Useful to fill an array in the order its added.

===================================================================

M	source/blender/blenlib/BLI_stack.h
M	source/blender/blenlib/intern/stack.c

===================================================================

diff --git a/source/blender/blenlib/BLI_stack.h b/source/blender/blenlib/BLI_stack.h
index 6d41e5f..222005e 100644
--- a/source/blender/blenlib/BLI_stack.h
+++ b/source/blender/blenlib/BLI_stack.h
@@ -44,6 +44,7 @@ void *BLI_stack_push_r(BLI_Stack *stack) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
 void  BLI_stack_push(BLI_Stack *stack, const void *src) ATTR_NONNULL();
 
 void BLI_stack_pop_n(BLI_Stack *stack, void *dst, unsigned int n) ATTR_NONNULL();
+void BLI_stack_pop_n_reverse(BLI_Stack *stack, void *dst, unsigned int n) ATTR_NONNULL();
 void BLI_stack_pop(BLI_Stack *stack, void *dst) ATTR_NONNULL();
 
 void *BLI_stack_peek(BLI_Stack *stack) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
diff --git a/source/blender/blenlib/intern/stack.c b/source/blender/blenlib/intern/stack.c
index 36fad5a..084d692 100644
--- a/source/blender/blenlib/intern/stack.c
+++ b/source/blender/blenlib/intern/stack.c
@@ -208,6 +208,23 @@ void BLI_stack_pop_n(BLI_Stack *stack, void *dst, unsigned int n)
 	}
 }
 
+/**
+ * A version of #BLI_stack_pop_n which which fills in an array (in the reverse order).
+ *
+ * \note The first item in the array will be first item added to the stack.
+ */
+void BLI_stack_pop_n_reverse(BLI_Stack *stack, void *dst, unsigned int n)
+{
+	BLI_assert(n <= BLI_stack_count(stack));
+
+	dst = (void *)((char *)dst + (stack->elem_size * n));
+
+	while (n--) {
+		dst = (void *)((char *)dst - stack->elem_size);
+		BLI_stack_pop(stack, dst);
+	}
+}
+
 void *BLI_stack_peek(BLI_Stack *stack)
 {
 	BLI_assert(BLI_stack_is_empty(stack) == false);




More information about the Bf-blender-cvs mailing list