cdcontainers  0.1.1
Library of data containers and collections for C programming language.
Data Structures | Functions
stack.h File Reference

The cdc_stack is a struct and functions that provide a stack. More...

#include <cdcontainers/common.h>
#include <cdcontainers/status.h>
#include <cdcontainers/tables/isequence.h>
#include <assert.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdlib.h>

Go to the source code of this file.

Data Structures

struct  cdc_stack
 The cdc_stack struct. More...
 

Functions

enum cdc_stat cdc_stack_ctor (const struct cdc_sequence_table *table, struct cdc_stack **s, struct cdc_data_info *info)
 Constructs an empty stack. More...
 
enum cdc_stat cdc_stack_ctorl (const struct cdc_sequence_table *table, struct cdc_stack **s, struct cdc_data_info *info,...)
 Constructs a stack, initialized by an arbitrary number of pointers. The last item must be NULL. More...
 
enum cdc_stat cdc_stack_ctorv (const struct cdc_sequence_table *table, struct cdc_stack **s, struct cdc_data_info *info, va_list args)
 Constructs a stack, initialized by args. The last item must be NULL. More...
 
void cdc_stack_dtor (struct cdc_stack *s)
 Destroys the stack. More...
 
static void * cdc_stack_top (struct cdc_stack *s)
 Returns a pointer to the stack's top item. This function assumes that the stack isn't empty. More...
 
static bool cdc_stack_empty (struct cdc_stack *s)
 Returns true if the stack has size 0; otherwise returns false. More...
 
static size_t cdc_stack_size (struct cdc_stack *s)
 Returns the number of items in the stack. More...
 
static enum cdc_stat cdc_stack_push (struct cdc_stack *s, void *elem)
 Adds element elem to the top of the stack. More...
 
static void cdc_stack_pop (struct cdc_stack *s)
 Removes the top item from the stack. This function assumes that the stack isn't empty. More...
 
void cdc_stack_swap (struct cdc_stack *a, struct cdc_stack *b)
 Swaps stack a and b. This operation is very fast and never fails. More...
 

Detailed Description

The cdc_stack is a struct and functions that provide a stack.

Author
Maksim Andrianov maksi.nosp@m.mand.nosp@m.riano.nosp@m.v1@y.nosp@m.andex.nosp@m..ru

Function Documentation

◆ cdc_stack_ctor()

enum cdc_stat cdc_stack_ctor ( const struct cdc_sequence_table table,
struct cdc_stack **  s,
struct cdc_data_info info 
)

Constructs an empty stack.

Parameters
table- method table for a particular implementation
s- cdc_stack
info- cdc_data_info
Returns
CDC_STATUS_OK in a successful case or other value indicating an error

◆ cdc_stack_ctorl()

enum cdc_stat cdc_stack_ctorl ( const struct cdc_sequence_table table,
struct cdc_stack **  s,
struct cdc_data_info info,
  ... 
)

Constructs a stack, initialized by an arbitrary number of pointers. The last item must be NULL.

Parameters
table- method table for a particular implementation
s- cdc_stack
info- cdc_data_info
Returns
CDC_STATUS_OK in a successful case or other value indicating an error

◆ cdc_stack_ctorv()

enum cdc_stat cdc_stack_ctorv ( const struct cdc_sequence_table table,
struct cdc_stack **  s,
struct cdc_data_info info,
va_list  args 
)

Constructs a stack, initialized by args. The last item must be NULL.

Parameters
table- method table for a particular implementation
s- cdc_stack
info- cdc_data_info
Returns
CDC_STATUS_OK in a successful case or other value indicating an error

◆ cdc_stack_dtor()

void cdc_stack_dtor ( struct cdc_stack s)

Destroys the stack.

Parameters
s- cdc_stack

◆ cdc_stack_top()

static void* cdc_stack_top ( struct cdc_stack s)
inlinestatic

Returns a pointer to the stack's top item. This function assumes that the stack isn't empty.

Parameters
s- cdc_stack
Returns
pointer to the stack's top item

◆ cdc_stack_empty()

static bool cdc_stack_empty ( struct cdc_stack s)
inlinestatic

Returns true if the stack has size 0; otherwise returns false.

Parameters
s- cdc_stack
Returns
true if the list has size 0; otherwise returns false

◆ cdc_stack_size()

static size_t cdc_stack_size ( struct cdc_stack s)
inlinestatic

Returns the number of items in the stack.

Parameters
s- cdc_stack
Returns
size

◆ cdc_stack_push()

static enum cdc_stat cdc_stack_push ( struct cdc_stack s,
void *  elem 
)
inlinestatic

Adds element elem to the top of the stack.

Parameters
s- cdc_stack
elem
Returns
CDC_STATUS_OK in a successful case or other value indicating an error

◆ cdc_stack_pop()

static void cdc_stack_pop ( struct cdc_stack s)
inlinestatic

Removes the top item from the stack. This function assumes that the stack isn't empty.

Parameters
s- cdc_stack

◆ cdc_stack_swap()

void cdc_stack_swap ( struct cdc_stack a,
struct cdc_stack b 
)

Swaps stack a and b. This operation is very fast and never fails.

Parameters
a- cdc_stack
b- cdc_stack