remove FTEST marker in test files
[cgds.git] / src / Stack.c
CommitLineData
a7868768
BA
1/**
2 * @file Stack.c
3 */
4
5#include "cgds/Stack.h"
6
7void _stack_init(Stack* stack, size_t dataSize)
8{
a7868768 9 stack->dataSize = dataSize;
10b9967a 10 _vector_init(stack->array, dataSize);
a7868768
BA
11}
12
13Stack* _stack_new(size_t dataSize)
14{
15 Stack* stack = (Stack*) safe_malloc(sizeof (Stack));
ea7acb53 16 stack->array = _vector_new(dataSize);
a7868768
BA
17 _stack_init(stack, dataSize);
18 return stack;
19}
20
21Stack* stack_copy(Stack* stack)
22{
10b9967a
BA
23 Stack* stackCopy = (Stack*) safe_malloc(sizeof (Stack));
24 stackCopy->dataSize = stack->dataSize;
25 Vector* arrayCopy = vector_copy(stack->array);
26 stackCopy->array = arrayCopy;
a7868768
BA
27 return stackCopy;
28}
29
30Bool stack_empty(Stack* stack)
31{
10b9967a 32 return vector_empty(stack->array);
a7868768
BA
33}
34
35UInt stack_size(Stack* stack)
36{
10b9967a 37 return vector_size(stack->array);
a7868768
BA
38}
39
40void _stack_push(Stack* stack, void* data)
41{
10b9967a 42 _vector_push(stack->array, data);
a7868768
BA
43}
44
45void* _stack_top(Stack* stack)
46{
10b9967a 47 return _vector_get(stack->array, vector_size(stack->array)-1);
a7868768
BA
48}
49
50void stack_pop(Stack* stack)
51{
10b9967a 52 vector_pop(stack->array);
a7868768
BA
53}
54
55void stack_clear(Stack* stack)
56{
10b9967a 57 vector_clear(stack->array);
a7868768
BA
58}
59
60void stack_destroy(Stack* stack)
61{
ea7acb53 62 vector_destroy(stack->array);
a7868768
BA
63 safe_free(stack);
64}