Archeus 0.0.0
A C library and game engine that focuses on documentation
Loading...
Searching...
No Matches
handler.c File Reference
#include "arc/std/handler.h"
#include "arc/std/errno.h"
#include "arc/std/vector.h"
#include <stdlib.h>

Go to the source code of this file.

Data Structures

struct  ARC_Handler
 

Functions

void ARC_Handler_Create (ARC_Handler **handler, ARC_Handler_CompareDataFn *compareFn, ARC_Handler_CleanDataFn cleanfn)
 creates ARC_Handler type
 
void ARC_Handler_Destroy (ARC_Handler *handler)
 destroyes ARC_Handler type
 
void ARC_Handler_Add (ARC_Handler *handler, void *data)
 adds data to handler
 
void ARC_Handler_Remove (ARC_Handler *handler, void *data)
 remove from handler
 
void ARC_Handler_RemoveIndex (ARC_Handler *handler, uint32_t index)
 remove from handler
 
void ARC_Handler_Iterate (ARC_Handler *handler, ARC_Handler_DataFn datafn)
 calls provided function on each element in handler
 
void ARC_Handler_Clear (ARC_Handler *handler)
 clears all data from handler and puts it in trash vector
 
void ARC_Handler_Clean (ARC_Handler *handler)
 clears trash from handler
 
uint32_t ARC_Handler_GetSize (ARC_Handler *handler)
 gets size of vector
 

Function Documentation

◆ ARC_Handler_Add()

void ARC_Handler_Add ( ARC_Handler * handler,
void * data )

adds data to handler

Parameters
handlerARC_Handler to add to
datadata that is being added

Definition at line 31 of file handler.c.

31 {
32 ARC_Vector_Add(handler->data, data);
33}
ARC_Vector * data
Definition handler.c:8
void ARC_Vector_Add(ARC_Vector *vector, void *data)
adds an item to an ARC_Vector
Definition vector.c:70

References ARC_Vector_Add(), and ARC_Handler::data.

◆ ARC_Handler_Clean()

void ARC_Handler_Clean ( ARC_Handler * handler)

clears trash from handler

Note
cleanfn's main purpose is to help manage memory
Parameters
handlerARC_Handler to remove trash from

Definition at line 63 of file handler.c.

63 {
64 uint32_t i = 0;
65 while(ARC_Vector_GetSize(handler->trash)){
66 void *data = ARC_Vector_Get(handler->trash, i);
67
68 if(handler->cleanfn){
69 handler->cleanfn(data);
70 }
71
72 ARC_Vector_RemoveIndex(handler->trash, i);
73 }
74}
ARC_Vector * trash
Definition handler.c:9
ARC_Handler_CleanDataFn cleanfn
Definition handler.c:11
uint32_t ARC_Vector_GetSize(ARC_Vector *vector)
gets the current size of an ARC_Vector as an unsigned 32 bit integer
Definition vector.c:149
void * ARC_Vector_Get(ARC_Vector *vector, uint32_t index)
gets an item from an ARC_Vector at a position index
Definition vector.c:153
void ARC_Vector_RemoveIndex(ARC_Vector *vector, uint32_t index)
removes an item from an ARC_Vector at an index
Definition vector.c:110

References ARC_Vector_Get(), ARC_Vector_GetSize(), ARC_Vector_RemoveIndex(), ARC_Handler::cleanfn, and ARC_Handler::trash.

Referenced by ARC_Engine_RunUncapped(), and ARC_Handler_Destroy().

◆ ARC_Handler_Clear()

void ARC_Handler_Clear ( ARC_Handler * handler)

clears all data from handler and puts it in trash vector

Parameters
handlerARC_Handler to clear data from

Definition at line 56 of file handler.c.

56 {
57 uint32_t zeroIndex = 0;
58 while(ARC_Vector_GetSize(handler->data)){
59 ARC_Handler_RemoveIndex(handler, zeroIndex);
60 }
61}
void ARC_Handler_RemoveIndex(ARC_Handler *handler, uint32_t index)
remove from handler
Definition handler.c:40

References ARC_Handler_RemoveIndex(), ARC_Vector_GetSize(), and ARC_Handler::data.

Referenced by ARC_Handler_Destroy().

◆ ARC_Handler_Create()

void ARC_Handler_Create ( ARC_Handler ** handler,
ARC_Handler_CompareDataFn * compareFn,
ARC_Handler_CleanDataFn cleanFn )

creates ARC_Handler type

Parameters
configARC_Handler to initialize
compareFnfunction to remove handler data
cleanFnfunction to clean data in handler can be null

Definition at line 14 of file handler.c.

14 {
15 *handler = (ARC_Handler *) malloc(sizeof(ARC_Handler));
16 ARC_Vector_Create(&((*handler)->data), NULL, NULL);
17 ARC_Vector_Create(&((*handler)->trash), compareFn, NULL);
18 (*handler)->cleanfn = cleanfn;
19}
void ARC_Vector_Create(ARC_Vector **vector, ARC_Vector_CompareDataFn *compareDataFn, ARC_Vector_DestroyDataFn *destroyDataFn)
creates an ARC_Vector which is an "expandable" array
Definition vector.c:31

References ARC_Vector_Create().

Referenced by ARC_EngineData_Create().

◆ ARC_Handler_Destroy()

void ARC_Handler_Destroy ( ARC_Handler * handler)

destroyes ARC_Handler type

Parameters
handlerARC_Handler to destory

Definition at line 21 of file handler.c.

21 {
22 ARC_Handler_Clear(handler);
23 ARC_Handler_Clean(handler);
24
25 ARC_Vector_Destroy(handler->data);
26 ARC_Vector_Destroy(handler->trash);
27
28 free(handler);
29}
void ARC_Handler_Clear(ARC_Handler *handler)
clears all data from handler and puts it in trash vector
Definition handler.c:56
void ARC_Handler_Clean(ARC_Handler *handler)
clears trash from handler
Definition handler.c:63
void ARC_Vector_Destroy(ARC_Vector *vector)
destroys an ARC_Vector
Definition vector.c:54

References ARC_Handler_Clean(), ARC_Handler_Clear(), ARC_Vector_Destroy(), ARC_Handler::data, and ARC_Handler::trash.

Referenced by ARC_EngineData_Destroy().

◆ ARC_Handler_GetSize()

uint32_t ARC_Handler_GetSize ( ARC_Handler * handler)

gets size of vector

Parameters
handlerARC_handler to get size from

Definition at line 76 of file handler.c.

76 {
77 return ARC_Vector_GetSize(handler->data);
78}

References ARC_Vector_GetSize(), and ARC_Handler::data.

◆ ARC_Handler_Iterate()

void ARC_Handler_Iterate ( ARC_Handler * handler,
ARC_Handler_DataFn datafn )

calls provided function on each element in handler

Parameters
handlerARC_Handler to iterate through
datafnfunction that will be called on each element of data

Definition at line 50 of file handler.c.

50 {
51 for(uint32_t i = 0; i < ARC_Vector_GetSize(handler->data); i++){
52 datafn(ARC_Vector_Get(handler->data, i));
53 }
54}

References ARC_Vector_Get(), ARC_Vector_GetSize(), and ARC_Handler::data.

Referenced by ARC_Engine_RunUncapped().

◆ ARC_Handler_Remove()

void ARC_Handler_Remove ( ARC_Handler * handler,
void * data )

remove from handler

Note
the data that is removed is stored in a trash vector the ARC_Handler_Clean function must be called clean the trash vector the trash vector is to make sure a state is not deleted while being run
Parameters
handlerARC_Handler to remove from
datadata that is being removed

Definition at line 35 of file handler.c.

35 {
36 ARC_Vector_Add(handler->trash, data);
37 ARC_Vector_Remove(handler->data, data);
38}
void ARC_Vector_Remove(ARC_Vector *vector, void *data)
removes an item from a matching item in an ARC_Vector
Definition vector.c:97

References ARC_Vector_Add(), ARC_Vector_Remove(), ARC_Handler::data, and ARC_Handler::trash.

◆ ARC_Handler_RemoveIndex()

void ARC_Handler_RemoveIndex ( ARC_Handler * handler,
uint32_t index )

remove from handler

Note
the data that is removed is stored in a trash vector the ARC_Handler_Clean function must be called clean the trash vector the trash vector is to make sure a state is not deleted while being run
Parameters
handlerARC_Handler to remove from
indexindex of data that is being removed

Definition at line 40 of file handler.c.

40 {
41 if(ARC_Vector_GetSize(handler->data) == 0){
42 return;
43 }
44
45 void *data = ARC_Vector_Get(handler->data, index);
46 ARC_Vector_Add(handler->trash, data);
47 ARC_Vector_RemoveIndex(handler->data, index);
48}

References ARC_Vector_Add(), ARC_Vector_Get(), ARC_Vector_GetSize(), ARC_Vector_RemoveIndex(), ARC_Handler::data, and ARC_Handler::trash.

Referenced by ARC_Handler_Clear().