Contiki-NG
Macros | Typedefs | Functions

This library provides functions for the creation and manipulation of stacks. More...

Macros

#define STACK(name)   LIST(name)
 Define a stack. More...
 

Typedefs

typedef list_t stack_t
 The stack data type.
 

Functions

static void stack_init (stack_t stack)
 Initialise a stack. More...
 
static void stack_push (stack_t stack, void *element)
 Adds an element to the top of the stack. More...
 
static void * stack_pop (stack_t stack)
 Removes the top element from the stack. More...
 
static void * stack_peek (stack_t stack)
 Returns the top element of the stack, without popping it. More...
 
static bool stack_is_empty (stack_t stack)
 Check if a stack is empty. More...
 

Detailed Description

This library provides functions for the creation and manipulation of stacks.

The library is implemented as a wrapper around the list library.

A stack is declared using the STACK macro. Stack elements must be allocated by the calling code and must be of a C struct datatype. In this struct, the first field must be a pointer called next. This field will be used by the library to maintain the stack. Application code must not modify this field directly.

Macro Definition Documentation

◆ STACK

#define STACK (   name)    LIST(name)

Define a stack.

This macro defines a stack.

The datatype for elements must be a C struct. The struct's first member must be a pointer called next. This is used internally by the library to maintain data structure integrity and must not be modified directly by application code.

Parameters
nameThe name of the stack.

Definition at line 75 of file stack.h.

Function Documentation

◆ stack_init()

static void stack_init ( stack_t  stack)
inlinestatic

Initialise a stack.

Parameters
stackThe stack

Definition at line 86 of file stack.h.

◆ stack_is_empty()

static bool stack_is_empty ( stack_t  stack)
inlinestatic

Check if a stack is empty.

Parameters
stackThe stack
Return values
trueThe stack is empty
falseThe stack has at least one element

Definition at line 133 of file stack.h.

◆ stack_peek()

static void* stack_peek ( stack_t  stack)
inlinestatic

Returns the top element of the stack, without popping it.

Parameters
stackThe stack
Returns
A pointer to the element at the top of the stack

Definition at line 121 of file stack.h.

◆ stack_pop()

static void* stack_pop ( stack_t  stack)
inlinestatic

Removes the top element from the stack.

Parameters
stackThe stack
Returns
A pointer to the element popped

If this function returns NULL if the stack was empty (stack underflow)

Definition at line 110 of file stack.h.

◆ stack_push()

static void stack_push ( stack_t  stack,
void *  element 
)
inlinestatic

Adds an element to the top of the stack.

Parameters
stackThe stack
elementA pointer to the element to be added

Definition at line 97 of file stack.h.