Quash Shell  0.1
A simple yet powerfull shell program
Classes | Macros | Typedefs | Functions
deque.h File Reference
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>

Go to the source code of this file.

Classes

struct  Example
 A data structure generated by IMPLEMENT_DEQUE_STRUCT() to store the state of a deque. More...
 

Macros

#define IMPLEMENT_DEQUE_STRUCT(struct_name, type)
 Generates a structure for use with Double Ended Queues. More...
 
#define PROTOTYPE_DEQUE(struct_name, type)
 Generates prototypes for functions that manipulate Double Ended Queue structures. More...
 
#define IMPLEMENT_DEQUE(struct_name, type)
 Generates a malloc based set of functions for use with a structure generated by IMPLEMENT_DEQUE_STRUCT. More...
 
#define IMPLEMENT_DEQUE_MEMORY_POOL(struct_name, type)
 Generates a memory_pool_alloc based set of functions for use with a structure generated by IMPLEMENT_DEQUE_STRUCT. More...
 

Typedefs

typedef char Type
 An example type used for example purposes only.
 
typedef struct Example Example
 

Functions

Example new_Example (size_t)
 Create a new, fully initialized deque structure. More...
 
Example new_destructable_Example (size_t, void(*)(Type))
 Create a new, fully initialized deque structure with a destructor that is applied to every element when the destroy_Example() function is called. More...
 
void destroy_Example (Example *)
 Destroy the deque structure freeing memory if necessary. More...
 
void empty_Example (Example *)
 Quickly empties the deque structure. More...
 
bool is_empty_Example (Example *)
 Checks if the deque is empty. More...
 
size_t length_Example (Example *)
 Query the number of elements in the deque. More...
 
Typeas_array_Example (Example *, size_t *)
 Extract an array based off the deque. More...
 
void apply_Example (Example *, void(*)(Type))
 Calls the function func on every element in the deque. More...
 
void push_front_Example (Example *, Type)
 Insert an element to the front of the deque. More...
 
void push_back_Example (Example *, Type)
 Insert an element to the back of the deque. More...
 
Type pop_front_Example (Example *)
 Remove an element from the front of the deque. More...
 
Type pop_back_Example (Example *)
 Remove an element from the back of the deque. More...
 
Type peek_front_Example (Example *)
 Get a copy of the element at the front of the deque. More...
 
Type peek_back_Example (Example *)
 Remove an element from the back of the deque. More...
 
void update_front_Example (Example *, Type)
 Change the element at the front of the deque to be a copy of element. More...
 
void update_back_Example (Example *, Type)
 Change the element at the front of the deque to be a copy of element. More...
 

Detailed Description

Double ended queue generators

Macro Definition Documentation

◆ IMPLEMENT_DEQUE

#define IMPLEMENT_DEQUE (   struct_name,
  type 
)

Generates a malloc based set of functions for use with a structure generated by IMPLEMENT_DEQUE_STRUCT.

Parameters
struct_nameThe name of the structure
typeThe name of the type of elements stored in the struct_name structure
See also
IMPLEMENT_DEQUE_STRUCT, PROTOTYPE_DEQUE, IMPLEMENT_DEQUE_MEMORY_POOL

◆ IMPLEMENT_DEQUE_MEMORY_POOL

#define IMPLEMENT_DEQUE_MEMORY_POOL (   struct_name,
  type 
)

Generates a memory_pool_alloc based set of functions for use with a structure generated by IMPLEMENT_DEQUE_STRUCT.

Parameters
struct_nameThe name of the structure
typeThe name of the type of elements stored in the struct_name structure
See also
IMPLEMENT_DEQUE_STRUCT, PROTOTYPE_DEQUE, IMPLEMENT_DEQUE_MEMORY_POOL, memory_pool_alloc

◆ IMPLEMENT_DEQUE_STRUCT

#define IMPLEMENT_DEQUE_STRUCT (   struct_name,
  type 
)
Value:
typedef struct struct_name { \
type* data; \
size_t cap; \
size_t front; \
size_t back; \
\
void (*destructor)(type); \
} struct_name;

Generates a structure for use with Double Ended Queues.

Follow this call with either PROTOTYPE_DEQUE, IMPLEMENT_DEQUE, or IMPLEMENT_DEQUE_MEMORY_POOL to generate the functions that correspond to this structure. The structure fields should not be manually changed at any time. Instead use one of the generated functions from the aforementioned macros.

Parameters
struct_nameThe name of the structure
typeThe name of the type of elements stored in the struct_name structure
See also
PROTOTYPE_DEQUE, IMPLEMENT_DEQUE, IMPLEMENT_DEQUE_MEMORY_POOL

◆ PROTOTYPE_DEQUE

#define PROTOTYPE_DEQUE (   struct_name,
  type 
)
Value:
struct_name new_##struct_name(size_t); \
struct_name new_destructable_##struct_name(size_t, void (*)(type)); \
void destroy_##struct_name(struct_name*); \
void empty_##struct_name(struct_name*); \
bool is_empty_##struct_name(struct_name*); \
size_t length_##struct_name(struct_name*); \
type* as_array_##struct_name(struct_name*, size_t*); \
void apply_##struct_name(struct_name*, void (*)(type)); \
void push_front_##struct_name(struct_name*, type); \
void push_back_##struct_name(struct_name*, type); \
type pop_front_##struct_name(struct_name*); \
type pop_back_##struct_name(struct_name*); \
type peek_front_##struct_name(struct_name*); \
type peek_back_##struct_name(struct_name*); \
void update_front_##struct_name(struct_name*, type); \
void update_back_##struct_name(struct_name*, type);

Generates prototypes for functions that manipulate Double Ended Queue structures.

This is intended for use in a header file or anywhere you need a forward declaration of these functions. This does not actually implement these functions.

Parameters
struct_nameThe name of the structure
typeThe name of the type of elements stored in the struct_name structure
See also
IMPLEMENT_DEQUE_STRUCT, IMPLEMENT_DEQUE, IMPLEMENT_DEQUE_MEMORY_POOL