Kohi Game Engine
stack.h File Reference

A simple stack container. Elements may be pushed on or popped off of the stack only. More...

#include "defines.h"

Go to the source code of this file.

Data Structures

struct  stack
 A simple stack container. Elements may be pushed on or popped off of the stack only. More...
 

Typedefs

typedef struct stack stack
 A simple stack container. Elements may be pushed on or popped off of the stack only. More...
 

Functions

KAPI b8 stack_create (stack *out_stack, u32 element_size)
 Creates a new stack. More...
 
KAPI void stack_destroy (stack *s)
 Destroys the given stack. More...
 
KAPI b8 stack_push (stack *s, void *element_data)
 Pushes an element (a copy of the element data) onto the stack. More...
 
KAPI b8 stack_pop (stack *s, void *out_element_data)
 Attempts to pop an element (writing out a copy of the element data on success) from the stack. If the stack is empty, nothing is done and false is returned. More...
 

Detailed Description

A simple stack container. Elements may be pushed on or popped off of the stack only.

Author
Travis Vroman (travi.nosp@m.s@ko.nosp@m.hieng.nosp@m.ine..nosp@m.com)
Version
1.0
Date
2023-01-18

Typedef Documentation

◆ stack

typedef struct stack stack

A simple stack container. Elements may be pushed on or popped off of the stack only.

Function Documentation

◆ stack_create()

KAPI b8 stack_create ( stack out_stack,
u32  element_size 
)

Creates a new stack.

Parameters
out_stackA pointer to hold the newly-created stack.
element_sizeThe size of each element in the stack.
Returns
True on success; otherwise false.

◆ stack_destroy()

KAPI void stack_destroy ( stack s)

Destroys the given stack.

Parameters
sA pointer to the stack to be destroyed.

◆ stack_pop()

KAPI b8 stack_pop ( stack s,
void *  out_element_data 
)

Attempts to pop an element (writing out a copy of the element data on success) from the stack. If the stack is empty, nothing is done and false is returned.

Parameters
sA pointer to the stack to pop from.
element_dataA pointer to write the element data to. Required.
Returns
True on succcess; otherwise false.

◆ stack_push()

KAPI b8 stack_push ( stack s,
void *  element_data 
)

Pushes an element (a copy of the element data) onto the stack.

Parameters
sA pointer to the stack to push to.
element_dataThe element data to be pushed. Required.
Returns
True on succcess; otherwise false.