EFL 1.7 svn doobies
[profile/ivi/eina.git] / src / include / eina_types.h
1 /* EINA - EFL data type library
2  * Copyright (C) 2007-2008 Carsten Haitzler, Vincent Torri, Jorge Luis Zapata Muga
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library;
16  * if not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifndef EINA_TYPES_H_
20 #define EINA_TYPES_H_
21
22 /**
23  * @addtogroup Eina_Core_Group Core
24  *
25  * @{
26  */
27
28 /**
29  * @defgroup Eina_Types_Group Types
30  *
31  * @{
32  */
33
34 #ifdef EAPI
35 # undef EAPI
36 #endif
37
38 #ifdef _WIN32
39 # ifdef EFL_EINA_BUILD
40 #  ifdef DLL_EXPORT
41 #   define EAPI __declspec(dllexport)
42 #  else
43 #   define EAPI
44 #  endif /* ! DLL_EXPORT */
45 # else
46 #  define EAPI __declspec(dllimport)
47 # endif /* ! EFL_EINA_BUILD */
48 #else
49 # ifdef __GNUC__
50 #  if __GNUC__ >= 4
51 #   define EAPI __attribute__ ((visibility("default")))
52 #  else
53 #   define EAPI
54 #  endif
55 # else
56 /**
57  * @def EAPI
58  * @brief Used to export functions(by changing visibility).
59  */
60 #  define EAPI
61 # endif
62 #endif
63
64 #include "eina_config.h"
65
66 #ifdef EINA_WARN_UNUSED_RESULT
67 # undef EINA_WARN_UNUSED_RESULT
68 #endif
69 #ifdef EINA_ARG_NONNULL
70 # undef EINA_ARG_NONNULL
71 #endif
72 #ifdef EINA_DEPRECATED
73 # undef EINA_DEPRECATED
74 #endif
75 #ifdef EINA_MALLOC
76 # undef EINA_MALLOC
77 #endif
78 #ifdef EINA_PURE
79 # undef EINA_PURE
80 #endif
81 #ifdef EINA_PRINTF
82 # undef EINA_PRINTF
83 #endif
84 #ifdef EINA_SCANF
85 # undef EINA_SCANF
86 #endif
87 #ifdef EINA_FORMAT
88 # undef EINA_FORMAT
89 #endif
90 #ifdef EINA_CONST
91 # undef EINA_CONST
92 #endif
93 #ifdef EINA_NOINSTRUMENT
94 # undef EINA_NOINSTRUMENT
95 #endif
96 #ifdef EINA_UNLIKELY
97 # undef EINA_UNLIKELY
98 #endif
99 #ifdef EINA_LIKELY
100 # undef EINA_LIKELY
101 #endif
102 #ifdef EINA_SENTINEL
103 # undef EINA_SENTINEL
104 #endif
105
106 #ifdef __GNUC__
107 # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
108 #  define EINA_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__))
109 # else
110 #  define EINA_WARN_UNUSED_RESULT
111 # endif
112
113 # if (!defined(EINA_SAFETY_CHECKS)) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))
114 #  define EINA_ARG_NONNULL(...) __attribute__ ((__nonnull__(__VA_ARGS__)))
115 # else
116 #  define EINA_ARG_NONNULL(...)
117 # endif
118
119 # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
120 #  define EINA_DEPRECATED __attribute__ ((__deprecated__))
121 # else
122 #  define EINA_DEPRECATED
123 # endif
124
125 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
126 #  define EINA_MALLOC __attribute__ ((__malloc__))
127 #  define EINA_PURE   __attribute__ ((__pure__))
128 # else
129 #  define EINA_MALLOC
130 #  define EINA_PURE
131 # endif
132
133 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
134 #  if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 3)
135 #   define EINA_PRINTF(fmt, arg) __attribute__((__format__ (__gnu_printf__, fmt, arg)))
136 #  else
137 #   define EINA_PRINTF(fmt, arg) __attribute__((__format__ (__printf__, fmt, arg)))
138 #  endif
139 #  define EINA_SCANF(fmt, arg)  __attribute__((__format__ (__scanf__, fmt, arg)))
140 #  define EINA_FORMAT(fmt)      __attribute__((__format_arg__(fmt)))
141 #  define EINA_CONST        __attribute__((__const__))
142 #  define EINA_NOINSTRUMENT __attribute__((__no_instrument_function__))
143 #  define EINA_UNLIKELY(exp)    __builtin_expect((exp), 0)
144 #  define EINA_LIKELY(exp)      __builtin_expect((exp), 1)
145 #  define EINA_SENTINEL __attribute__((__sentinel__))
146 # else
147 #  define EINA_PRINTF(fmt, arg)
148 #  define EINA_SCANF(fmt, arg)
149 #  define EINA_FORMAT(fmt)
150 #  define EINA_CONST
151 #  define EINA_NOINSTRUMENT
152 #  define EINA_UNLIKELY(exp) exp
153 #  define EINA_LIKELY(exp)   exp
154 #  define EINA_SENTINEL
155 # endif
156
157 #elif defined(_WIN32)
158 # define EINA_WARN_UNUSED_RESULT
159 # define EINA_ARG_NONNULL(...)
160 # if defined(_MSC_VER) && _MSC_VER >= 1300
161 #  define EINA_DEPRECATED __declspec(deprecated)
162 # else
163 #  define EINA_DEPRECATED
164 # endif
165 # define EINA_MALLOC
166 # define EINA_PURE
167 # define EINA_PRINTF(fmt, arg)
168 # define EINA_SCANF(fmt, arg)
169 # define EINA_FORMAT(fmt)
170 # define EINA_CONST
171 # define EINA_NOINSTRUMENT
172 # define EINA_UNLIKELY(exp) exp
173 # define EINA_LIKELY(exp)   exp
174 # define EINA_SENTINEL
175
176 #elif defined(__SUNPRO_C)
177 # define EINA_WARN_UNUSED_RESULT
178 # define EINA_ARG_NONNULL(...)
179 # define EINA_DEPRECATED
180 # if __SUNPRO_C >= 0x590
181 #  define EINA_MALLOC __attribute__ ((malloc))
182 #  define EINA_PURE   __attribute__ ((pure))
183 # else
184 #  define EINA_MALLOC
185 #  define EINA_PURE
186 # endif
187 # define EINA_PRINTF(fmt, arg)
188 # define EINA_SCANF(fmt, arg)
189 # define EINA_FORMAT(fmt)
190 # if __SUNPRO_C >= 0x590
191 #  define EINA_CONST __attribute__ ((const))
192 # else
193 #  define EINA_CONST
194 # endif
195 # define EINA_NOINSTRUMENT
196 # define EINA_UNLIKELY(exp) exp
197 # define EINA_LIKELY(exp)   exp
198 # define EINA_SENTINEL
199
200 #else /* ! __GNUC__ && ! _WIN32 && ! __SUNPRO_C */
201
202 /**
203  * @def EINA_WARN_UNUSED_RESULT
204  * Used to warn when the returned value of the function is not used.
205  */
206 # define EINA_WARN_UNUSED_RESULT
207
208 /**
209  * @def EINA_ARG_NONNULL
210  * Used to warn when the specified arguments of the function are @c NULL.
211  */
212 # define EINA_ARG_NONNULL(...)
213
214 /**
215  * @def EINA_DEPRECATED
216  * Used to warn when the function is considered as deprecated.
217  */
218 # define EINA_DEPRECATED
219 /**
220  * @def EINA_MALLOC
221  * @brief EINA_MALLOC is used to tell the compiler that a function may be treated
222  * as if any non-NULL pointer it returns cannot alias any other pointer valid when
223  * the function returns and that the memory has undefined content.
224  */
225 # define EINA_MALLOC
226 /**
227  * @def EINA_PURE
228  * @brief EINA_PURE is used to tell the compiler this functions has no effects
229  * except the return value and their return value depends only on the parameters
230  * and/or global variables.
231  */
232 # define EINA_PURE
233 /**
234  * @def EINA_PRINTF
235  * @param fmt The format to be used.
236  * @param arg The argument to be used.
237  */
238 # define EINA_PRINTF(fmt, arg)
239 /**
240  * @def EINA_SCANF
241  * @param fmt The format to be used.
242  * @param arg The argument to be used.
243  */
244 # define EINA_SCANF(fmt, arg)
245 /**
246  * @def EINA_FORMAT
247  * @param fmt The format to be used.
248  */
249 # define EINA_FORMAT(fmt)
250 /**
251  * @def EINA_CONST
252  * @brief Attribute from gcc to prevent the function to read/modify any global memory.
253  */
254 # define EINA_CONST
255 /**
256  * @def EINA_NOINSTRUMENT
257  * @brief Attribute from gcc to disable instrumentation for a specific function.
258  */
259 # define EINA_NOINSTRUMENT
260 /**
261  * @def EINA_UNLIKELY
262  * @param exp The expression to be used.
263  */
264 # define EINA_UNLIKELY(exp) exp
265 /**
266  * @def EINA_LIKELY
267  * @param exp The expression to be used.
268  */
269 # define EINA_LIKELY(exp)   exp
270 /**
271  * @def EINA_SENTINEL
272  * @brief Attribute from gcc to prevent calls without the necessary NULL
273  * sentinel in certain variadic functions
274  * @since 1.7.0
275  */
276 # define EINA_SENTINEL
277 #endif /* ! __GNUC__ && ! _WIN32 && ! __SUNPRO_C */
278
279 /**
280  * @typedef Eina_Bool
281  * Type to mimic a boolean.
282  *
283  * @note it differs from stdbool.h as this is defined as an unsigned
284  *       char to make it usable by bitfields (Eina_Bool name:1) and
285  *       also take as few bytes as possible.
286  */
287 typedef unsigned char Eina_Bool;
288
289 /**
290  * @def EINA_FALSE
291  * boolean value FALSE (numerical value 0)
292  */
293 #define EINA_FALSE ((Eina_Bool)0)
294
295 /**
296  * @def EINA_TRUE
297  * boolean value TRUE (numerical value 1)
298  */
299 #define EINA_TRUE  ((Eina_Bool)1)
300
301 EAPI extern const unsigned int eina_prime_table[];
302
303 /**
304  * @typedef Eina_Compare_Cb
305  * Function used in functions using sorting. It compares @p data1 and
306  * @p data2. If @p data1 is 'less' than @p data2, -1 must be returned,
307  * if it is 'greater', 1 must be returned, and if they are equal, 0
308  * must be returned.
309  */
310 typedef int (*Eina_Compare_Cb)(const void *data1, const void *data2);
311
312 /**
313  * @def EINA_COMPARE_CB
314  * Macro to cast to Eina_Compare_Cb.
315  */
316 #define EINA_COMPARE_CB(function) ((Eina_Compare_Cb)function)
317
318 /**
319  * @typedef Eina_Each_Cb
320  * A callback type used when iterating over a container.
321  */
322 typedef Eina_Bool (*Eina_Each_Cb)(const void *container, void *data, void *fdata);
323
324 /**
325  * @def EINA_EACH_CB
326  * Macro to cast to Eina_Each.
327  */
328 #define EINA_EACH_CB(Function) ((Eina_Each_Cb)Function)
329
330 /**
331  * @typedef Eina_Free_Cb
332  * A callback type used to free data when iterating over a container.
333  */
334 typedef void (*Eina_Free_Cb)(void *data);
335
336 /**
337  * @def EINA_FREE_CB
338  * Macro to cast to Eina_Free_Cb.
339  */
340 #define EINA_FREE_CB(Function) ((Eina_Free_Cb)Function)
341
342 /**
343  * @def EINA_C_ARRAY_LENGTH
344  * Macro to return the array length of a standard c array.
345  * For example:
346  * int foo[] = { 0, 1, 2, 3 };
347  * would return 4 and not 4 * sizeof(int).
348  * @since 1.2.0
349  */
350 #define EINA_C_ARRAY_LENGTH(arr) (sizeof(arr) / sizeof((arr)[0]))
351
352 /**
353  * @}
354  */
355
356 /**
357  * @}
358  */
359
360 #endif /* EINA_TYPES_H_ */