Some fixes + improvements (Vector) + code reformatting
[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{
e45132ac
BA
9 stack->dataSize = dataSize;
10 _vector_init(stack->array, dataSize);
a7868768
BA
11}
12
13Stack* _stack_new(size_t dataSize)
14{
e45132ac
BA
15 Stack* stack = (Stack*) safe_malloc(sizeof (Stack));
16 stack->array = _vector_new(dataSize);
17 _stack_init(stack, dataSize);
18 return stack;
a7868768
BA
19}
20
21Stack* stack_copy(Stack* stack)
22{
e45132ac
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;
27 return stackCopy;
a7868768
BA
28}
29
1ff641f9 30bool stack_empty(Stack* stack)
a7868768 31{
e45132ac 32 return vector_empty(stack->array);
a7868768
BA
33}
34
35UInt stack_size(Stack* stack)
36{
e45132ac 37 return vector_size(stack->array);
a7868768
BA
38}
39
40void _stack_push(Stack* stack, void* data)
41{
e45132ac 42 _vector_push(stack->array, data);
a7868768
BA
43}
44
45void* _stack_top(Stack* stack)
46{
e45132ac 47 return _vector_get(stack->array, vector_size(stack->array)-1);
a7868768
BA
48}
49
50void stack_pop(Stack* stack)
51{
e45132ac 52 vector_pop(stack->array);
a7868768
BA
53}
54
55void stack_clear(Stack* stack)
56{
e45132ac 57 vector_clear(stack->array);
a7868768
BA
58}
59
60void stack_destroy(Stack* stack)
61{
e45132ac
BA
62 vector_destroy(stack->array);
63 safe_free(stack);
a7868768 64}