From 2ff624eae24742faf17889f858dbdaa6d4a064ea Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 20 Oct 2022 21:34:22 -0400 Subject: Split up common header --- include/zix/btree.h | 7 +++--- include/zix/common.h | 57 -------------------------------------------- include/zix/function_types.h | 37 ++++++++++++++++++++++++++++ include/zix/hash.h | 2 +- include/zix/ring.h | 2 +- include/zix/sem.h | 2 +- include/zix/status.h | 50 ++++++++++++++++++++++++++++++++++++++ include/zix/thread.h | 2 +- include/zix/tree.h | 5 ++-- 9 files changed, 98 insertions(+), 66 deletions(-) delete mode 100644 include/zix/common.h create mode 100644 include/zix/function_types.h create mode 100644 include/zix/status.h (limited to 'include') diff --git a/include/zix/btree.h b/include/zix/btree.h index 1b36908..33f47d1 100644 --- a/include/zix/btree.h +++ b/include/zix/btree.h @@ -6,7 +6,8 @@ #include "zix/allocator.h" #include "zix/attributes.h" -#include "zix/common.h" +#include "zix/function_types.h" +#include "zix/status.h" #include #include @@ -74,7 +75,7 @@ static const ZixBTreeIter zix_btree_end_iter = { ZIX_API ZixBTree* ZIX_ALLOCATED zix_btree_new(ZixAllocator* ZIX_NULLABLE allocator, - ZixComparator ZIX_NONNULL cmp, + ZixCompareFunc ZIX_NONNULL cmp, const void* ZIX_NULLABLE cmp_data); /** @@ -166,7 +167,7 @@ zix_btree_find(const ZixBTree* ZIX_NONNULL t, ZIX_API ZixStatus zix_btree_lower_bound(const ZixBTree* ZIX_NONNULL t, - ZixComparator ZIX_NULLABLE compare_key, + ZixCompareFunc ZIX_NULLABLE compare_key, const void* ZIX_NULLABLE compare_key_user_data, const void* ZIX_NULLABLE key, ZixBTreeIter* ZIX_NONNULL ti); diff --git a/include/zix/common.h b/include/zix/common.h deleted file mode 100644 index 788fdaa..0000000 --- a/include/zix/common.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2016-2022 David Robillard -// SPDX-License-Identifier: ISC - -#ifndef ZIX_COMMON_H -#define ZIX_COMMON_H - -#include "zix/attributes.h" - -#include - -/** - @defgroup zix Zix C API - @{ -*/ - -#ifdef __cplusplus -extern "C" { -#endif - -/// A status code returned by functions -typedef enum { - ZIX_STATUS_SUCCESS, ///< Success - ZIX_STATUS_ERROR, ///< Unknown error - ZIX_STATUS_NO_MEM, ///< Out of memory - ZIX_STATUS_NOT_FOUND, ///< Not found - ZIX_STATUS_EXISTS, ///< Exists - ZIX_STATUS_BAD_ARG, ///< Bad argument - ZIX_STATUS_BAD_PERMS, ///< Bad permissions - ZIX_STATUS_REACHED_END, ///< Reached end - ZIX_STATUS_TIMEOUT, ///< Timeout - ZIX_STATUS_OVERFLOW, ///< Overflow - ZIX_STATUS_NOT_SUPPORTED, ///< Not supported - ZIX_STATUS_UNAVAILABLE, ///< Resource unavailable -} ZixStatus; - -/// Return a string describing a status code -ZIX_CONST_API -const char* -zix_strerror(ZixStatus status); - -/// Function for comparing two elements -typedef int (*ZixComparator)(const void* a, - const void* b, - const void* user_data); - -/// Function to destroy an element -typedef void (*ZixDestroyFunc)(void* ptr, const void* user_data); - -/** - @} -*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* ZIX_COMMON_H */ diff --git a/include/zix/function_types.h b/include/zix/function_types.h new file mode 100644 index 0000000..8822847 --- /dev/null +++ b/include/zix/function_types.h @@ -0,0 +1,37 @@ +// Copyright 2016-2022 David Robillard +// SPDX-License-Identifier: ISC + +#ifndef ZIX_FUNCTION_TYPES_H +#define ZIX_FUNCTION_TYPES_H + +#include "zix/attributes.h" + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + @defgroup zix_function_types Function Types + @ingroup zix + @{ +*/ + +/// Function for comparing two elements +typedef int (*ZixCompareFunc)(const void* a, + const void* b, + const void* user_data); + +/// Function to destroy an element +typedef void (*ZixDestroyFunc)(void* ptr, const void* user_data); + +/** + @} +*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* ZIX_FUNCTION_TYPES_H */ diff --git a/include/zix/hash.h b/include/zix/hash.h index c1521e0..397e055 100644 --- a/include/zix/hash.h +++ b/include/zix/hash.h @@ -6,7 +6,7 @@ #include "zix/allocator.h" #include "zix/attributes.h" -#include "zix/common.h" +#include "zix/status.h" #include #include diff --git a/include/zix/ring.h b/include/zix/ring.h index 6fb78ac..66662b7 100644 --- a/include/zix/ring.h +++ b/include/zix/ring.h @@ -6,7 +6,7 @@ #include "zix/allocator.h" #include "zix/attributes.h" -#include "zix/common.h" +#include "zix/status.h" #include diff --git a/include/zix/sem.h b/include/zix/sem.h index 25088bf..3777497 100644 --- a/include/zix/sem.h +++ b/include/zix/sem.h @@ -5,7 +5,7 @@ #define ZIX_SEM_H #include "zix/attributes.h" -#include "zix/common.h" +#include "zix/status.h" #ifdef __APPLE__ # include diff --git a/include/zix/status.h b/include/zix/status.h new file mode 100644 index 0000000..fcd45fb --- /dev/null +++ b/include/zix/status.h @@ -0,0 +1,50 @@ +// Copyright 2016-2022 David Robillard +// SPDX-License-Identifier: ISC + +#ifndef ZIX_STATUS_H +#define ZIX_STATUS_H + +#include "zix/attributes.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + @defgroup zix Zix C API + @{ + @defgroup zix_status Status Codes + @{ +*/ + +/// A status code returned by functions +typedef enum { + ZIX_STATUS_SUCCESS, ///< Success + ZIX_STATUS_ERROR, ///< Unknown error + ZIX_STATUS_NO_MEM, ///< Out of memory + ZIX_STATUS_NOT_FOUND, ///< Not found + ZIX_STATUS_EXISTS, ///< Exists + ZIX_STATUS_BAD_ARG, ///< Bad argument + ZIX_STATUS_BAD_PERMS, ///< Bad permissions + ZIX_STATUS_REACHED_END, ///< Reached end + ZIX_STATUS_TIMEOUT, ///< Timeout + ZIX_STATUS_OVERFLOW, ///< Overflow + ZIX_STATUS_NOT_SUPPORTED, ///< Not supported + ZIX_STATUS_UNAVAILABLE, ///< Resource unavailable +} ZixStatus; + +/// Return a string describing a status code +ZIX_CONST_API +const char* +zix_strerror(ZixStatus status); + +/** + @} + @} +*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* ZIX_STATUS_H */ diff --git a/include/zix/thread.h b/include/zix/thread.h index af036b1..14c525d 100644 --- a/include/zix/thread.h +++ b/include/zix/thread.h @@ -5,7 +5,7 @@ #define ZIX_THREAD_H #include "zix/attributes.h" -#include "zix/common.h" +#include "zix/status.h" #ifdef _WIN32 # include diff --git a/include/zix/tree.h b/include/zix/tree.h index f363ffc..7b77a7c 100644 --- a/include/zix/tree.h +++ b/include/zix/tree.h @@ -6,7 +6,8 @@ #include "zix/allocator.h" #include "zix/attributes.h" -#include "zix/common.h" +#include "zix/function_types.h" +#include "zix/status.h" #include #include @@ -32,7 +33,7 @@ ZIX_API ZixTree* ZIX_ALLOCATED zix_tree_new(ZixAllocator* ZIX_NULLABLE allocator, bool allow_duplicates, - ZixComparator ZIX_NONNULL cmp, + ZixCompareFunc ZIX_NONNULL cmp, void* ZIX_NULLABLE cmp_data, ZixDestroyFunc ZIX_NULLABLE destroy, const void* ZIX_NULLABLE destroy_user_data); -- cgit v1.2.1