From a9661c348560cc559a03e6165926be626fc33aa6 Mon Sep 17 00:00:00 2001 From: Leonardo Vencovsky Date: Sun, 24 May 2020 13:40:54 -0300 Subject: [PATCH] Updating cor include guards and separating things from core.h --- src/cor/alloc.h | 30 ++++++++++++++++++++++++++++++ src/cor/callbacks.h | 33 +++++++++++++++++++++++++++++++++ src/cor/core.h | 41 +++++------------------------------------ src/cor/flags.h | 6 +++--- src/cor/hashtable.h | 6 +++--- 5 files changed, 74 insertions(+), 42 deletions(-) create mode 100644 src/cor/alloc.h create mode 100644 src/cor/callbacks.h diff --git a/src/cor/alloc.h b/src/cor/alloc.h new file mode 100644 index 0000000..734c34e --- /dev/null +++ b/src/cor/alloc.h @@ -0,0 +1,30 @@ +/** + * alloc.h + * + * Creation Date: 24/05/2020 + * + * Authors: + * Leonardo Vencovsky (https://github.com/LeoVen) + * + */ + +#ifndef CMC_COR_ALLOC_H +#define CMC_COR_ALLOC_H + +#include + +/** + * struct cmc_alloc_node + * + * Custom allocation node. Allows collections to use custom allocation + * functions. + */ +static struct cmc_alloc_node +{ + void *(*malloc)(size_t); + void *(*calloc)(size_t, size_t); + void *(*realloc)(void *, size_t); + void (*free)(void *); +} cmc_alloc_node_default = { malloc, calloc, realloc, free }; + +#endif /* CMC_COR_ALLOC_H */ diff --git a/src/cor/callbacks.h b/src/cor/callbacks.h new file mode 100644 index 0000000..613eccc --- /dev/null +++ b/src/cor/callbacks.h @@ -0,0 +1,33 @@ +/** + * callbacks.h + * + * Creation Date: 24/05/2020 + * + * Authors: + * Leonardo Vencovsky (https://github.com/LeoVen) + * + */ + +#ifndef CMC_COR_CALLBACK_H +#define CMC_COR_CALLBACK_H + +/** + * struct cmc_callbacks + * + * Callback node. Each collection will call one of these functions when: + * - create : an element was successfully added to the collection + * - read : the collection was successfully queried about an element + * - update : an element in the collection was successfully updated + * - delete : an element was successfully removed from the collection + * - resize : the collection was full and successfully resized + */ +struct cmc_callbacks +{ + void (*create)(void); + void (*read)(void); + void (*update)(void); + void (*delete)(void); + void (*resize)(void); +}; + +#endif /* CMC_COR_CALLBACK_H */ diff --git a/src/cor/core.h b/src/cor/core.h index 16ba3c6..e63219b 100644 --- a/src/cor/core.h +++ b/src/cor/core.h @@ -18,8 +18,8 @@ * cmc_flags */ -#ifndef CMC_CORE_H -#define CMC_CORE_H +#ifndef CMC_COR_CORE_H +#define CMC_COR_CORE_H #include #include @@ -28,6 +28,8 @@ #include #include +#include "alloc.h" +#include "callbacks.h" #include "flags.h" #define CMC_TO_STRING_(X) #X @@ -45,37 +47,4 @@ struct cmc_string static const size_t cmc_string_len = 400; -/** - * struct cmc_alloc_node - * - * Custom allocation node. Allows collections to use custom allocation - * functions. - */ -static struct cmc_alloc_node -{ - void *(*malloc)(size_t); - void *(*calloc)(size_t, size_t); - void *(*realloc)(void *, size_t); - void (*free)(void *); -} cmc_alloc_node_default = { malloc, calloc, realloc, free }; - -/** - * struct cmc_callbacks - * - * Callback node. Each collection will call one of these functions when: - * - create : an element was successfully added to the collection - * - read : the collection was successfully queried about an element - * - update : an element in the collection was successfully updated - * - delete : an element was successfully removed from the collection - * - resize : the collection was full and successfully resized - */ -struct cmc_callbacks -{ - void (*create)(void); - void (*read)(void); - void (*update)(void); - void (*delete)(void); - void (*resize)(void); -}; - -#endif /* CMC_CORE_H */ +#endif /* CMC_COR_CORE_H */ diff --git a/src/cor/flags.h b/src/cor/flags.h index da41a0b..e007623 100644 --- a/src/cor/flags.h +++ b/src/cor/flags.h @@ -8,8 +8,8 @@ * */ -#ifndef CMC_FLAGS_H -#define CMC_FLAGS_H +#ifndef CMC_COR_FLAGS_H +#define CMC_COR_FLAGS_H /** * cmc_flags @@ -40,4 +40,4 @@ const char *cmc_flags_to_str[10] = { "OK", "ALLOC", "EMPTY", "DUPLICATE", "ERROR", "THREAD", "MUTEX" }; -#endif /* CMC_FLAGS_H */ +#endif /* CMC_COR_FLAGS_H */ diff --git a/src/cor/hashtable.h b/src/cor/hashtable.h index 877a1e5..d44fc51 100644 --- a/src/cor/hashtable.h +++ b/src/cor/hashtable.h @@ -12,8 +12,8 @@ * Things commonly used by hashtable-based collections. */ -#ifndef CMC_IMPL_HASHTABLE_H -#define CMC_IMPL_HASHTABLE_H +#ifndef CMC_COR_HASHTABLE_H +#define CMC_COR_HASHTABLE_H #include "core.h" @@ -83,4 +83,4 @@ static const size_t cmc_hashtable_primes[] = { }; // clang-format on -#endif /* CMC_IMPL_HASHTABLE_H */ +#endif /* CMC_COR_HASHTABLE_H */