BLI_stack: various small additions

- add BLI_stack_count
- add BLI_stack_pop_n to pop into an array
- add BLI_stack_push_r, which returns a pointer that can be filled in

Also remove sanity check in BLI_stack_pop, assert if the stack is empty.
This commit is contained in:
Campbell Barton
2014-07-15 20:37:06 +10:00
parent a378f8d2d8
commit 5c4180d898
3 changed files with 75 additions and 21 deletions

View File

@@ -17,6 +17,7 @@ TEST(stack, Empty)
stack = BLI_stack_new(sizeof(int), __func__);
EXPECT_EQ(BLI_stack_is_empty(stack), true);
EXPECT_EQ(BLI_stack_count(stack), 0);
BLI_stack_free(stack);
}
@@ -29,9 +30,11 @@ TEST(stack, One)
BLI_stack_push(stack, (void *)&in);
EXPECT_EQ(BLI_stack_is_empty(stack), false);
EXPECT_EQ(BLI_stack_count(stack), 1);
BLI_stack_pop(stack, (void *)&out);
EXPECT_EQ(in, out);
EXPECT_EQ(BLI_stack_is_empty(stack), true);
EXPECT_EQ(BLI_stack_count(stack), 0);
BLI_stack_free(stack);
}
@@ -79,7 +82,6 @@ TEST(stack, String)
*((int *)in) = i;
BLI_stack_pop(stack, (void *)&out);
EXPECT_STREQ(in, out);
}
EXPECT_EQ(BLI_stack_is_empty(stack), true);
@@ -133,5 +135,14 @@ TEST(stack, Reuse)
EXPECT_EQ(i, 0);
EXPECT_EQ(memcmp(sizes, sizes_test, sizeof(sizes) - sizeof(int)), 0);
/* finally test BLI_stack_pop_n */
for (i = ARRAY_SIZE(sizes); i--; ) {
BLI_stack_push(stack, (void *)&sizes[i]);
}
EXPECT_EQ(BLI_stack_count(stack), ARRAY_SIZE(sizes));
BLI_stack_pop_n(stack, (void *)sizes_test, ARRAY_SIZE(sizes));
EXPECT_EQ(memcmp(sizes, sizes_test, sizeof(sizes) - sizeof(int)), 0);
BLI_stack_free(stack);
}