Added flags.h

Separated flag definitions from the core header
This commit is contained in:
Leonardo committed 2020-05-14 18:43:43 -03:00
1 parent 1380d131ea
commit f520c38583
2 files changed
+42 -27

No files matched your search

+2 -27
View File
@@ -28,6 +28,8 @@
#include <stdlib.h>
#include <string.h>
#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 */
+40
View File
@@ -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 */