1 /* |
1 /* |
2 * File: ucx.h |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 * Author: olaf |
|
4 * |
3 * |
5 * Created on 31. Dezember 2011, 17:17 |
4 * Copyright 2013 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 |
6 */ |
34 */ |
7 |
35 |
8 #ifndef UCX_H |
36 #ifndef UCX_H |
9 #define UCX_H |
37 #define UCX_H |
10 |
38 |
11 #include <stdlib.h> |
39 #include <stdlib.h> |
12 |
40 |
|
41 #ifdef _WIN32 |
|
42 #if !(defined __ssize_t_defined || defined _SSIZE_T_) |
|
43 #include <BaseTsd.h> |
|
44 typedef SSIZE_T ssize_t; |
|
45 #define __ssize_t_defined |
|
46 #define _SSIZE_T_ |
|
47 #endif /* __ssize_t_defined and _SSIZE_T */ |
|
48 #else /* !_WIN32 */ |
|
49 #include <sys/types.h> |
|
50 #endif /* _WIN32 */ |
|
51 |
13 #ifdef __cplusplus |
52 #ifdef __cplusplus |
14 #ifndef _Bool |
53 #ifndef _Bool |
15 #define _Bool bool |
54 #define _Bool bool |
16 #define restrict |
55 #define restrict |
17 #endif |
56 #endif |
|
57 #define UCX_EXTERN extern "C" |
18 extern "C" { |
58 extern "C" { |
|
59 #else |
|
60 #define UCX_EXTERN |
19 #endif |
61 #endif |
20 |
62 |
21 #define UCX_FOREACH(type,list,elem) \ |
63 /** |
22 for (type elem = list ; elem != NULL ; elem = elem->next) |
64 * Function pointer to a compare function. |
23 |
65 * |
24 #ifdef __cplusplus |
66 * The compare function shall take three arguments: the two values that shall be |
25 #define ucx_dynarray_new(type,identifier,length)\ |
67 * compared and optional additional data. |
26 type* identifier; identifier = new type[length] |
68 * The function shall then return -1 if the first argument is less than the |
27 #define ucx_dynarray_free(identifier) delete [] identifier |
69 * second argument, 1 if the first argument is greater than the second argument |
28 #else |
70 * and 0 if both arguments are equal. If the third argument is |
29 #define ucx_dynarray_new(type,identifier,length)\ |
71 * <code>NULL</code>, it shall be ignored. |
30 type identifier[length] |
72 */ |
31 #define ucx_dynarray_free(identifier) |
|
32 #endif |
|
33 |
|
34 /* element1,element2,custom data -> {-1,0,1} */ |
|
35 typedef int(*cmp_func)(void*,void*,void*); |
73 typedef int(*cmp_func)(void*,void*,void*); |
36 |
74 |
37 /* element,custom data -> copy of element */ |
75 /** |
|
76 * Function pointer to a copy function. |
|
77 * |
|
78 * The copy function shall create a copy of the first argument and may use |
|
79 * additional data provided by the second argument. If the second argument is |
|
80 * <code>NULL</code>, it shall be ignored. |
|
81 |
|
82 * <b>Attention:</b> if pointers returned by functions of this type may be |
|
83 * passed to <code>free()</code> depends on the implementation of the |
|
84 * respective <code>copy_func</code>. |
|
85 */ |
38 typedef void*(*copy_func)(void*,void*); |
86 typedef void*(*copy_func)(void*,void*); |
39 |
87 |
40 /* buffer, element size, element count, stream */ |
88 /** |
|
89 * Function pointer to a write function. |
|
90 * |
|
91 * The signature of the write function shall be compatible to the signature |
|
92 * of standard <code>fwrite</code>, though it may use arbitrary data types for |
|
93 * source and destination. |
|
94 * |
|
95 * The arguments shall contain (in ascending order): a pointer to the source, |
|
96 * the length of one element, the element count and a pointer to the |
|
97 * destination. |
|
98 */ |
41 typedef size_t(*write_func)(const void*, size_t, size_t, void*); |
99 typedef size_t(*write_func)(const void*, size_t, size_t, void*); |
42 |
100 |
43 /* buffer, element size, element count, stream */ |
101 /** |
|
102 * Function pointer to a read function. |
|
103 * |
|
104 * The signature of the read function shall be compatible to the signature |
|
105 * of standard <code>fread</code>, though it may use arbitrary data types for |
|
106 * source and destination. |
|
107 * |
|
108 * The arguments shall contain (in ascending order): a pointer to the |
|
109 * destination, the length of one element, the element count and a pointer to |
|
110 * the source. |
|
111 */ |
44 typedef size_t(*read_func)(void*, size_t, size_t, void*); |
112 typedef size_t(*read_func)(void*, size_t, size_t, void*); |
45 |
113 |
46 #ifdef __cplusplus |
114 #ifdef __cplusplus |
47 } |
115 } |
48 #endif |
116 #endif |