From f520c3858314abde20d104726ddc9f10922f65c7 Mon Sep 17 00:00:00 2001 From: Leonardo Date: Thu, 14 May 2020 18:43:43 -0300 Subject: [PATCH] Added flags.h Separated flag definitions from the core header --- src/cor/core.h | 29 ++--------------------------- src/cor/flags.h | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 27 deletions(-) create mode 100644 src/cor/flags.h diff --git a/src/cor/core.h b/src/cor/core.h index fc1e0dd..16ba3c6 100644 --- a/src/cor/core.h +++ b/src/cor/core.h @@ -28,6 +28,8 @@ #include #include +#include "flags.h" + #define CMC_TO_STRING_(X) #X #define CMC_TO_STRING(X) CMC_TO_STRING_(X) @@ -76,31 +78,4 @@ struct cmc_callbacks void (*resize)(void); }; -/** - * cmc_flags - * - * Defines common error codes used by all collections. These are flags that - * indicate if something went wrong in the last operation by the collection. - */ -static struct -{ - int OK; // No errors - int ALLOC; // Allocation failed - int EMPTY; // The collection is empty when it should not - int NOT_FOUND; // Key or value not found - int INVALID; // Invalid argument or operation - int RANGE; // Index out of range - int DUPLICATE; // Duplicate key or value - int ERROR; // Generic error, usually caused by algorithm error -} cmc_flags = { 0, 1, 2, 3, 4, 5, 6, 7 }; - -/** - * cmc_flags_to_str - * - * Maps the error codes to their character representation. - */ -const char *cmc_flags_to_str[8] = { "OK", "ALLOC", "EMPTY", - "NOT_FOUND", "INVALID", "RANGE", - "DUPLICATE", "ERROR" }; - #endif /* CMC_CORE_H */ diff --git a/src/cor/flags.h b/src/cor/flags.h new file mode 100644 index 0000000..31a8074 --- /dev/null +++ b/src/cor/flags.h @@ -0,0 +1,40 @@ +/** + * flags.h + * + * Creation Date: 14/05/2020 + * + * Authors: + * Leonardo Vencovsky (https://github.com/LeoVen) + * + */ + +#ifndef CMC_FLAGS_H +#define CMC_FLAGS_H + +/** + * cmc_flags + * + * Defines common error codes used by the entire library. + */ +static struct +{ + int OK; // No errors + int ALLOC; // Allocation failed + int EMPTY; // The collection is empty when it should not + int NOT_FOUND; // Key or value not found + int INVALID; // Invalid argument or operation + int RANGE; // Index out of range + int DUPLICATE; // Duplicate key or value + int ERROR; // Generic error, usually caused by algorithm error +} cmc_flags = { 0, 1, 2, 3, 4, 5, 6, 7 }; + +/** + * cmc_flags_to_str + * + * Maps the error codes to their character representation. + */ +const char *cmc_flags_to_str[8] = { "OK", "ALLOC", "EMPTY", + "NOT_FOUND", "INVALID", "RANGE", + "DUPLICATE", "ERROR" }; + +#endif /* CMC_FLAGS_H */