|
1 /* |
|
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
3 * |
|
4 * Copyright 2017 Olaf Wintermann. All rights reserved. |
|
5 * |
|
6 * Redistribution and use in source and binary forms, with or without |
|
7 * modification, are permitted provided that the following conditions are met: |
|
8 * |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * |
|
12 * 2. Redistributions in binary form must reproduce the above copyright |
|
13 * notice, this list of conditions and the following disclaimer in the |
|
14 * documentation and/or other materials provided with the distribution. |
|
15 * |
|
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
26 * POSSIBILITY OF SUCH DAMAGE. |
|
27 */ |
|
28 /** |
|
29 * Main UCX Header providing most common definitions. |
|
30 * |
|
31 * @file ucx.h |
|
32 * @author Mike Becker |
|
33 * @author Olaf Wintermann |
|
34 */ |
|
35 |
|
36 #ifndef UCX_H |
|
37 #define UCX_H |
|
38 |
|
39 /** Major UCX version as integer constant. */ |
|
40 #define UCX_VERSION_MAJOR 0 |
|
41 |
|
42 /** Minor UCX version as integer constant. */ |
|
43 #define UCX_VERSION_MINOR 13 |
|
44 |
|
45 #include <stdlib.h> |
|
46 #include <stdint.h> |
|
47 |
|
48 #ifdef _WIN32 |
|
49 #if !(defined __ssize_t_defined || defined _SSIZE_T_) |
|
50 #include <BaseTsd.h> |
|
51 typedef SSIZE_T ssize_t; |
|
52 #define __ssize_t_defined |
|
53 #define _SSIZE_T_ |
|
54 #endif /* __ssize_t_defined and _SSIZE_T */ |
|
55 #else /* !_WIN32 */ |
|
56 #include <sys/types.h> |
|
57 #endif /* _WIN32 */ |
|
58 |
|
59 #ifdef __cplusplus |
|
60 #ifndef _Bool |
|
61 #define _Bool bool |
|
62 #define restrict |
|
63 #endif |
|
64 /** Use C naming even when compiling with C++. */ |
|
65 #define UCX_EXTERN extern "C" |
|
66 extern "C" { |
|
67 #else |
|
68 /** Pointless in C. */ |
|
69 #define UCX_EXTERN |
|
70 #endif |
|
71 |
|
72 |
|
73 /** |
|
74 * A function pointer to a destructor function. |
|
75 * @see ucx_mempool_setdestr() |
|
76 * @see ucx_mempool_regdestr() |
|
77 */ |
|
78 typedef void(*ucx_destructor)(void*); |
|
79 |
|
80 /** |
|
81 * Function pointer to a compare function. |
|
82 * |
|
83 * The compare function shall take three arguments: the two values that shall be |
|
84 * compared and optional additional data. |
|
85 * The function shall then return -1 if the first argument is less than the |
|
86 * second argument, 1 if the first argument is greater than the second argument |
|
87 * and 0 if both arguments are equal. If the third argument is |
|
88 * <code>NULL</code>, it shall be ignored. |
|
89 */ |
|
90 typedef int(*cmp_func)(const void*,const void*,void*); |
|
91 |
|
92 /** |
|
93 * Function pointer to a distance function. |
|
94 * |
|
95 * The distance function shall take three arguments: the two values for which |
|
96 * the distance shall be computed and optional additional data. |
|
97 * The function shall then return the signed distance as integer value. |
|
98 */ |
|
99 typedef intmax_t(*distance_func)(const void*,const void*,void*); |
|
100 |
|
101 /** |
|
102 * Function pointer to a copy function. |
|
103 * |
|
104 * The copy function shall create a copy of the first argument and may use |
|
105 * additional data provided by the second argument. If the second argument is |
|
106 * <code>NULL</code>, it shall be ignored. |
|
107 |
|
108 * <b>Attention:</b> if pointers returned by functions of this type may be |
|
109 * passed to <code>free()</code> depends on the implementation of the |
|
110 * respective <code>copy_func</code>. |
|
111 */ |
|
112 typedef void*(*copy_func)(const void*,void*); |
|
113 |
|
114 /** |
|
115 * Function pointer to a write function. |
|
116 * |
|
117 * The signature of the write function shall be compatible to the signature |
|
118 * of standard <code>fwrite</code>, though it may use arbitrary data types for |
|
119 * source and destination. |
|
120 * |
|
121 * The arguments shall contain (in ascending order): a pointer to the source, |
|
122 * the length of one element, the element count and a pointer to the |
|
123 * destination. |
|
124 */ |
|
125 typedef size_t(*write_func)(const void*, size_t, size_t, void*); |
|
126 |
|
127 /** |
|
128 * Function pointer to a read function. |
|
129 * |
|
130 * The signature of the read function shall be compatible to the signature |
|
131 * of standard <code>fread</code>, though it may use arbitrary data types for |
|
132 * source and destination. |
|
133 * |
|
134 * The arguments shall contain (in ascending order): a pointer to the |
|
135 * destination, the length of one element, the element count and a pointer to |
|
136 * the source. |
|
137 */ |
|
138 typedef size_t(*read_func)(void*, size_t, size_t, void*); |
|
139 |
|
140 #ifdef __cplusplus |
|
141 } |
|
142 #endif |
|
143 |
|
144 #endif /* UCX_H */ |
|
145 |