diff --git a/docs/Examples/examples.html b/docs/Examples/examples.html index 9850512..c20ede7 100644 --- a/docs/Examples/examples.html +++ b/docs/Examples/examples.html @@ -81,7 +81,7 @@ diff --git a/docs/Introduction/how_to_install.html b/docs/Introduction/how_to_install.html index 8b372df..7027fdf 100644 --- a/docs/Introduction/how_to_install.html +++ b/docs/Introduction/how_to_install.html @@ -81,7 +81,7 @@ diff --git a/docs/Introduction/how_to_use_the_library.html b/docs/Introduction/how_to_use_the_library.html index 8b26a45..bad27ff 100644 --- a/docs/Introduction/how_to_use_the_library.html +++ b/docs/Introduction/how_to_use_the_library.html @@ -81,7 +81,7 @@ diff --git a/docs/Introduction/introduction.html b/docs/Introduction/introduction.html index eb6865f..7b658b6 100644 --- a/docs/Introduction/introduction.html +++ b/docs/Introduction/introduction.html @@ -81,7 +81,7 @@ diff --git a/docs/Introduction/library_structure.html b/docs/Introduction/library_structure.html index ea8a560..8776487 100644 --- a/docs/Introduction/library_structure.html +++ b/docs/Introduction/library_structure.html @@ -81,7 +81,7 @@ diff --git a/docs/Introduction/understanding_the_library.html b/docs/Introduction/understanding_the_library.html index 55aa864..1576c2d 100644 --- a/docs/Introduction/understanding_the_library.html +++ b/docs/Introduction/understanding_the_library.html @@ -81,7 +81,7 @@ diff --git a/docs/Introduction/why_this_library.html b/docs/Introduction/why_this_library.html index 00d8f5b..c682a15 100644 --- a/docs/Introduction/why_this_library.html +++ b/docs/Introduction/why_this_library.html @@ -81,7 +81,7 @@ diff --git a/docs/Overview/collections_overview.html b/docs/Overview/collections_overview.html index a0864aa..e25bc25 100644 --- a/docs/Overview/collections_overview.html +++ b/docs/Overview/collections_overview.html @@ -81,7 +81,7 @@ diff --git a/docs/Overview/features_overview.html b/docs/Overview/features_overview.html index d577249..30bf959 100644 --- a/docs/Overview/features_overview.html +++ b/docs/Overview/features_overview.html @@ -81,7 +81,7 @@ @@ -153,6 +153,7 @@ +
FeatureDescription
CallbacksCallbacks are functions that are called when an operation is successful. These operations are divided in 5 categories (create, read, update, delete, resize).
Custom AllocationAllows you to use your own custom dynamic memory allocation functions inside the collections.
Error CodesError codes that can be used to treat certain common errors when operating on a collection.
Functions TableA standard way to access required behaviors from the custom data types. Things like hash, comparison, freeing from memory if needed, etc.
IteratorsIterators are a simplified access to the values of a collection.
diff --git a/docs/Overview/index.html b/docs/Overview/index.html index 49e9065..6a69bf2 100644 --- a/docs/Overview/index.html +++ b/docs/Overview/index.html @@ -81,7 +81,7 @@ diff --git a/docs/cmc/deque.h/index.html b/docs/cmc/deque.h/index.html index d300188..871cadf 100644 --- a/docs/cmc/deque.h/index.html +++ b/docs/cmc/deque.h/index.html @@ -81,7 +81,7 @@ diff --git a/docs/cmc/index.html b/docs/cmc/index.html index e54c0c2..c8d8562 100644 --- a/docs/cmc/index.html +++ b/docs/cmc/index.html @@ -81,7 +81,7 @@ diff --git a/docs/cor/callbacks/index.html b/docs/cor/callbacks/index.html index 1db5632..e61f21e 100644 --- a/docs/cor/callbacks/index.html +++ b/docs/cor/callbacks/index.html @@ -81,7 +81,7 @@ diff --git a/docs/cor/custom_allocation/index.html b/docs/cor/custom_allocation/index.html index a899baf..fefa5ec 100644 --- a/docs/cor/custom_allocation/index.html +++ b/docs/cor/custom_allocation/index.html @@ -81,7 +81,7 @@ @@ -240,7 +240,7 @@ int main(void) - @@ -258,7 +258,7 @@ int main(void) - diff --git a/docs/cor/error_codes/index.html b/docs/cor/error_codes/index.html new file mode 100644 index 0000000..1116521 --- /dev/null +++ b/docs/cor/error_codes/index.html @@ -0,0 +1,281 @@ + + + + + + Error Codes - C Macro Collections + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + +
+
+

Error Codes

+

Error codes are ways to signal errors or success. It is accessed through the flag component of a struct or through a function that is present in every collection:

+
int PFX##_flag(struct SNAME *_collection_);
+
+

Some functions have a return type of bool indicating if it exited successfully or not. These error codes can be used for further error handling.

+

cmc_flags

+

It is a global struct with default values for error codes.

+
static struct
+{
+    int OK;
+    int ALLOC;
+    int EMPTY;
+    int NOT_FOUND;
+    int INVALID;
+    int RANGE;
+    int DUPLICATE;
+    int ERROR;
+} cmc_flags = { 0, 1, 2, 3, 4, 5, 6, 7 };
+
+
    +
  • OK - No errors. The operation exited successfully.
  • +
  • ALLOC - Allocation failed.
  • +
  • EMPTY - The collection is empty when it shouldn't.
  • +
  • NOT_FOUND - Key or value not found.
  • +
  • INVALID - Invalid argument or operation given the collection's state
  • +
  • RANGE - Index out of range.
  • +
  • DUPLICATE - Duplicate key or value.
  • +
  • ERROR - Generic error. Usually caused by algorithm errors.
  • +
+

cmc_flags_to_str

+

Maps the integer representation of error codes to their character representation.

+
const char *cmc_flags_to_str[8] = { "OK",        "ALLOC",   "EMPTY",
+                                    "NOT_FOUND", "INVALID", "RANGE",
+                                    "DUPLICATE", "ERROR" };
+
+

Example

+
#include "cmc/treeset.h"
+#include "utl/futils.h" // cmc_i32_cmp
+
+// Generate a sorted set of integers
+CMC_GENERATE_TREESET(tset, sortedset, int)
+
+int main(void)
+{
+    struct sortedset *set =
+        tset_new(&(struct sortedset_fval){ .cmp = cmc_i32_cmp });
+
+    if (!tset_insert(set, 10))
+        printf("Error! %s\n", cmc_flags_to_str[tset_flag(set)]);
+
+    if (!tset_insert(set, 10))
+        printf("Error! %s\n", cmc_flags_to_str[tset_flag(set)]);
+
+    if (!tset_remove(set, 10))
+        printf("Error! %s\n", cmc_flags_to_str[tset_flag(set)]);
+
+    if (!tset_remove(set, 10))
+        printf("Error! %s\n", cmc_flags_to_str[tset_flag(set)]);
+
+    tset_free(set);
+}
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/cor/functions_table/index.html b/docs/cor/functions_table/index.html index 9acd31c..720c509 100644 --- a/docs/cor/functions_table/index.html +++ b/docs/cor/functions_table/index.html @@ -81,7 +81,7 @@ @@ -263,7 +263,7 @@ struct SNAME##_fkey \