3D-ICE 3.0.0
Data Structures | Typedefs | Functions
powers_queue.h File Reference
#include <stdio.h>
#include "types.h"
#include "string_t.h"

Go to the source code of this file.

Data Structures

struct  PowersQueue_t
 A First In - First Out circular queue to store power values. More...
 

Typedefs

typedef struct PowersQueue_t PowersQueue_t
 

Functions

void powers_queue_init (PowersQueue_t *pqueue)
 
void powers_queue_copy (PowersQueue_t *dst, PowersQueue_t *src)
 
void powers_queue_build (PowersQueue_t *pqueue, Quantity_t capacity)
 
void powers_queue_destroy (PowersQueue_t *pqueue)
 
PowersQueue_tpowers_queue_calloc (void)
 
PowersQueue_tpowers_queue_clone (PowersQueue_t *pqueue)
 
void powers_queue_free (PowersQueue_t *pqueue)
 
void powers_queue_print (PowersQueue_t *pqueue, FILE *stream, String_t prefix)
 
bool is_empty_powers_queue (PowersQueue_t *pqueue)
 
bool is_full_powers_queue (PowersQueue_t *pqueue)
 
void put_into_powers_queue (PowersQueue_t *pqueue, Power_t power)
 
Power_t get_from_powers_queue (PowersQueue_t *pqueue)
 

Typedef Documentation

◆ PowersQueue_t

typedef struct PowersQueue_t PowersQueue_t

Definition of the type PowersQueue_t

Definition at line 87 of file powers_queue.h.

Function Documentation

◆ get_from_powers_queue()

Power_t get_from_powers_queue ( PowersQueue_t pqueue)

Returns and remve the power value at the beginning of a powers queue

Parameters
pqueuethe powers queue
Returns
the first power value in pqueue
0 if the power queue pqueue is empty

Definition at line 244 of file powers_queue.c.

◆ is_empty_powers_queue()

bool is_empty_powers_queue ( PowersQueue_t pqueue)

Returns the state of the powers queue

Parameters
pqueuethe powers queue
Returns
TRUE if the queue is empty
FALSE otherwise

Definition at line 190 of file powers_queue.c.

◆ is_full_powers_queue()

bool is_full_powers_queue ( PowersQueue_t pqueue)

Returns the state of the powers queue

Parameters
pqueuethe powers queue
Returns
TRUE if the queue is full
FALSE otherwise

Definition at line 197 of file powers_queue.c.

◆ powers_queue_build()

void powers_queue_build ( PowersQueue_t pqueue,
Quantity_t  capacity 
)

Reserves space to store power values

The function deletes old memory, if any, calling powers_queue_destroy on the parameter pqueue. Then, it reserves new memory.

Parameters
pqueuethe address of the power queue
capacitythe new capacity of the power queue

Definition at line 56 of file powers_queue.c.

◆ powers_queue_calloc()

PowersQueue_t * powers_queue_calloc ( void  )

Allocates memory for a structure of type PowersQueue_t

The content of the new structure is set to default values calling powers_queue_init

Returns
the pointer to the new structure
NULL if the memory allocation fails

Definition at line 119 of file powers_queue.c.

◆ powers_queue_clone()

PowersQueue_t * powers_queue_clone ( PowersQueue_t pqueue)

Allocates memory for a new copy of the structure pqueue

Parameters
pqueuethe address of the structure to clone
Returns
a pointer to a new structure
NULL if the memory allocation fails
NULL if the parameter pqueue is NULL

Definition at line 132 of file powers_queue.c.

◆ powers_queue_copy()

void powers_queue_copy ( PowersQueue_t dst,
PowersQueue_t src 
)

Copies the structure src into dst , as an assignement

If src is an empty queue, then dst will be set as an empty queue as well. Its capacity will not be affected.

If src is not empty, then the capacity of dst will change (i.e. set as the capacity of src ) only if it is less than the capacity of src. Otherwise, it will not be affected by the copy.

Parameters
dstthe address of the left term sructure (destination)
srcthe address of the right term structure (source)

Definition at line 87 of file powers_queue.c.

◆ powers_queue_destroy()

void powers_queue_destroy ( PowersQueue_t pqueue)

Destroys the content of the fields of the structure pqueue

The function releases any dynamic memory used by the structure and resets its state calling powers_queue_init .

Parameters
pqueuethe address of the structure to destroy

Definition at line 76 of file powers_queue.c.

◆ powers_queue_free()

void powers_queue_free ( PowersQueue_t pqueue)

Frees the memory space pointed by pqueue

The function destroys the structure pqueue and then frees its memory. The pointer pqueue must have been returned by a previous call to powers_queue_calloc or powers_queue_clone .

If pqueue is NULL, no operation is performed.

Parameters
pqueuethe pointer to free

Definition at line 149 of file powers_queue.c.

◆ powers_queue_init()

void powers_queue_init ( PowersQueue_t pqueue)

Inits the fields of the pqueue structure with default values

Parameters
pqueuethe address of the structure to initalize

Definition at line 45 of file powers_queue.c.

◆ powers_queue_print()

void powers_queue_print ( PowersQueue_t pqueue,
FILE *  stream,
String_t  prefix 
)

Prints the list of power values as it looks in the floorplan file

Parameters
pqueuethe powers queue to print
streamthe output stream (must be already open)
prefixa string to be printed as prefix at the beginning of each line

Definition at line 162 of file powers_queue.c.

◆ put_into_powers_queue()

void put_into_powers_queue ( PowersQueue_t pqueue,
Power_t  power 
)

Inserts a power value at the end of the powers queue

If the power queue pqueue is full, the Capacity will be doubled.

Parameters
pqueuethe powers queue
powerthe power value to insert

Definition at line 204 of file powers_queue.c.