2015-03-03 00:38:33 +08:00
|
|
|
/****************************************************************************
|
2016-07-05 18:46:22 +08:00
|
|
|
** Copyright (c) 2016, Fougue Ltd. <http://www.fougue.pro>
|
|
|
|
** All rights reserved.
|
2015-03-03 00:38:33 +08:00
|
|
|
**
|
2016-07-05 18:46:22 +08:00
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
2015-03-03 00:38:33 +08:00
|
|
|
**
|
2016-07-05 18:46:22 +08:00
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
**
|
|
|
|
** 2. Redistributions in binary form must reproduce the above
|
|
|
|
** copyright notice, this list of conditions and the following
|
|
|
|
** disclaimer in the documentation and/or other materials provided
|
|
|
|
** with the distribution.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2015-03-03 00:38:33 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
2015-03-05 01:25:51 +08:00
|
|
|
/*! \file global.h
|
2015-11-06 21:15:22 +08:00
|
|
|
* Fundamental global declarations, included by almost all other header/source
|
|
|
|
* files
|
2015-09-09 17:44:34 +08:00
|
|
|
*
|
|
|
|
* \defgroup gmio_core gmioCore
|
|
|
|
* All other gmio modules rely on this module
|
|
|
|
*
|
|
|
|
* \addtogroup gmio_core
|
|
|
|
* @{
|
2015-03-05 01:25:51 +08:00
|
|
|
*/
|
|
|
|
|
2014-03-28 23:33:35 +08:00
|
|
|
#ifndef GMIO_GLOBAL_H
|
|
|
|
#define GMIO_GLOBAL_H
|
2013-01-11 01:48:46 +08:00
|
|
|
|
2015-11-20 00:43:07 +08:00
|
|
|
/* "config.h" is generated by cmake, it should reside in the out-of-source
|
|
|
|
* build dir.
|
|
|
|
* In CMakeFiles.txt, the directory where resides "config.h" is added to the
|
|
|
|
* include path list
|
|
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
|
2015-11-06 21:15:22 +08:00
|
|
|
/* GMIO_OS_WIN */
|
2013-01-25 22:37:06 +08:00
|
|
|
#if defined(WIN64) || defined(_WIN64) || defined(__WIN64__) \
|
2015-03-03 18:35:15 +08:00
|
|
|
|| defined(WIN32) || defined(_WIN32) || defined(__WIN32__) \
|
|
|
|
|| defined(__NT__)
|
2015-04-01 21:39:00 +08:00
|
|
|
# define GMIO_OS_WIN
|
2015-11-06 21:15:22 +08:00
|
|
|
#endif
|
2015-04-01 21:39:00 +08:00
|
|
|
|
2015-11-06 21:15:22 +08:00
|
|
|
/* GMIO_OS_LINUX */
|
2015-04-01 21:39:00 +08:00
|
|
|
#if defined(__linux) || defined(__linux__) || defined(linux)
|
|
|
|
# define GMIO_OS_LINUX
|
2015-11-06 21:15:22 +08:00
|
|
|
#endif
|
2015-04-01 21:39:00 +08:00
|
|
|
|
2015-11-06 21:15:22 +08:00
|
|
|
/* GMIO_OS_MAC */
|
2015-04-01 21:39:00 +08:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
# define GMIO_OS_MAC
|
2015-11-06 21:15:22 +08:00
|
|
|
#endif
|
2015-04-01 21:39:00 +08:00
|
|
|
|
2015-11-06 21:15:22 +08:00
|
|
|
/* GMIO_DECL_IMPORT */
|
|
|
|
/* GMIO_DECL_EXPORT */
|
2015-04-01 21:39:00 +08:00
|
|
|
#ifdef GMIO_OS_WIN
|
2015-03-03 17:38:49 +08:00
|
|
|
# define GMIO_DECL_EXPORT __declspec(dllexport)
|
|
|
|
# define GMIO_DECL_IMPORT __declspec(dllimport)
|
2013-01-11 01:48:46 +08:00
|
|
|
#else
|
2015-03-05 01:25:51 +08:00
|
|
|
/*! Expands to the C compiler extension to export functions to a DLL */
|
2015-03-03 17:38:49 +08:00
|
|
|
# define GMIO_DECL_EXPORT
|
2015-03-05 01:25:51 +08:00
|
|
|
/*! Expands to the C compiler extension to import functions from a DLL */
|
2015-03-03 17:38:49 +08:00
|
|
|
# define GMIO_DECL_IMPORT
|
2015-11-06 21:15:22 +08:00
|
|
|
#endif
|
2013-01-11 01:48:46 +08:00
|
|
|
|
2016-03-11 19:43:30 +08:00
|
|
|
/* GMIO_API */
|
|
|
|
#ifdef GMIO_DLL
|
|
|
|
# ifdef GMIO_MAKING_DLL
|
|
|
|
# define GMIO_API GMIO_DECL_EXPORT
|
2015-03-03 17:38:49 +08:00
|
|
|
# else
|
2016-03-11 19:43:30 +08:00
|
|
|
# define GMIO_API GMIO_DECL_IMPORT
|
|
|
|
# endif /* GMIO_MAKING_DLL */
|
2013-01-15 23:45:01 +08:00
|
|
|
#else
|
2015-03-05 01:25:51 +08:00
|
|
|
/*! Expands either to GMIO_DECL_EXPORT or GMIO_DECL_IMPORT when respectively
|
|
|
|
* compiling/using the DLL */
|
2016-03-11 19:43:30 +08:00
|
|
|
# define GMIO_API
|
2015-11-06 21:15:22 +08:00
|
|
|
#endif
|
2013-01-15 23:45:01 +08:00
|
|
|
|
2016-04-07 16:13:32 +08:00
|
|
|
/* GMIO_HAVE_INT64_TYPE */
|
|
|
|
#if defined(GMIO_HAVE_INT64_T) \
|
2016-07-29 19:16:25 +08:00
|
|
|
|| defined(GMIO_HAVE_MSVC_INT64) \
|
|
|
|
|| defined(GMIO_HAVE_LONG_LONG)
|
2016-04-07 16:13:32 +08:00
|
|
|
# define GMIO_HAVE_INT64_TYPE
|
|
|
|
#endif
|
|
|
|
|
2015-11-06 21:15:22 +08:00
|
|
|
/* Typedefs for specific width integers */
|
2014-03-28 23:33:35 +08:00
|
|
|
#ifdef GMIO_HAVE_STDINT_H
|
2015-03-03 17:38:49 +08:00
|
|
|
# include <stdint.h>
|
2013-01-15 02:30:42 +08:00
|
|
|
#else
|
2014-01-21 17:49:24 +08:00
|
|
|
typedef char int8_t;
|
2013-01-15 02:30:42 +08:00
|
|
|
typedef unsigned char uint8_t;
|
2013-01-11 01:48:46 +08:00
|
|
|
|
2015-11-20 00:43:07 +08:00
|
|
|
# if GMIO_SIZEOF_SHORT == 2
|
2014-01-21 17:49:24 +08:00
|
|
|
typedef short int16_t;
|
2013-01-15 02:30:42 +08:00
|
|
|
typedef unsigned short uint16_t;
|
2015-11-20 00:43:07 +08:00
|
|
|
# else
|
|
|
|
# error Not supported: sizeof(short) != 2
|
|
|
|
# endif
|
2013-01-11 01:48:46 +08:00
|
|
|
|
2015-11-20 00:43:07 +08:00
|
|
|
# if GMIO_SIZEOF_INT == 4
|
2014-01-21 17:49:24 +08:00
|
|
|
typedef int int32_t;
|
2013-01-15 02:30:42 +08:00
|
|
|
typedef unsigned int uint32_t;
|
2015-11-20 00:43:07 +08:00
|
|
|
# elif GMIO_SIZEOF_LONG == 4
|
|
|
|
typedef long int32_t;
|
|
|
|
typedef unsigned long uint32_t;
|
|
|
|
# else
|
|
|
|
# error Failed to find a 32bit integer type with 'int' and 'long'
|
|
|
|
# endif
|
|
|
|
|
2016-04-07 16:13:32 +08:00
|
|
|
# ifndef GMIO_HAVE_INT64_T
|
|
|
|
# if defined(GMIO_HAVE_MSVC_INT64)
|
2015-11-06 19:40:57 +08:00
|
|
|
typedef __int64_t int64_t;
|
|
|
|
typedef unsigned __int64_t uint64_t;
|
2016-04-07 16:13:32 +08:00
|
|
|
# elif defined(GMIO_HAVE_LONG_LONG)
|
2015-11-06 19:40:57 +08:00
|
|
|
typedef long long int64_t;
|
2013-01-15 02:30:42 +08:00
|
|
|
typedef unsigned long long uint64_t;
|
2016-04-07 16:13:32 +08:00
|
|
|
# endif
|
2015-11-06 21:15:22 +08:00
|
|
|
#endif
|
2013-01-11 01:48:46 +08:00
|
|
|
|
2016-04-07 16:13:32 +08:00
|
|
|
# ifdef GMIO_HAVE_INT64_TYPE
|
|
|
|
typedef int64_t intmax_t;
|
|
|
|
typedef uint64_t uintmax_t;
|
|
|
|
# else
|
|
|
|
typedef int32_t intmax_t;
|
|
|
|
typedef uint32_t uintmax_t;
|
|
|
|
# endif
|
|
|
|
|
2015-11-06 19:40:57 +08:00
|
|
|
#endif
|
2013-01-11 01:48:46 +08:00
|
|
|
|
2016-01-27 00:03:58 +08:00
|
|
|
/* GMIO_HAVE_STDBOOL_H */
|
2014-11-11 01:31:44 +08:00
|
|
|
#ifdef GMIO_HAVE_STDBOOL_H
|
2015-03-03 17:38:49 +08:00
|
|
|
# include <stdbool.h>
|
2016-01-27 00:03:58 +08:00
|
|
|
#elif !defined(DOXYGEN) && !defined(__cplusplus)
|
|
|
|
typedef int bool;
|
2014-03-28 23:33:35 +08:00
|
|
|
enum gmio_bool_value
|
2014-01-30 17:19:22 +08:00
|
|
|
{
|
2016-01-27 00:03:58 +08:00
|
|
|
false = 0,
|
|
|
|
true = 1
|
2014-01-30 17:19:22 +08:00
|
|
|
};
|
2016-01-27 00:03:58 +08:00
|
|
|
#endif
|
2014-11-11 01:31:44 +08:00
|
|
|
|
2015-11-06 21:15:22 +08:00
|
|
|
/* GMIO_UNUSED */
|
2014-11-21 18:40:49 +08:00
|
|
|
/*! Tells the compiler that a parameter is not used in the body of a function */
|
|
|
|
#define GMIO_UNUSED(x) (void)x;
|
|
|
|
|
2015-11-06 21:15:22 +08:00
|
|
|
/* GMIO_INLINE */
|
2014-03-28 23:33:35 +08:00
|
|
|
#ifndef GMIO_INLINE
|
2015-03-03 17:38:49 +08:00
|
|
|
# if defined(__GNUC__)
|
2015-03-31 16:10:26 +08:00
|
|
|
# define GMIO_INLINE __inline__ static /* Compatible with C90 */
|
2015-03-03 17:38:49 +08:00
|
|
|
# elif defined(_MSC_VER)
|
2015-03-31 16:10:26 +08:00
|
|
|
# define GMIO_INLINE __inline static
|
|
|
|
# elif !defined(DOXYGEN)
|
2015-04-01 21:39:00 +08:00
|
|
|
# define GMIO_INLINE static
|
2015-03-03 17:38:49 +08:00
|
|
|
# else
|
2015-03-05 01:25:51 +08:00
|
|
|
/*! Expands to the C compiler specific inline keyword (if any) */
|
2015-03-03 17:38:49 +08:00
|
|
|
# define GMIO_INLINE
|
|
|
|
# endif
|
2015-11-06 21:15:22 +08:00
|
|
|
#endif
|
2014-01-29 02:06:24 +08:00
|
|
|
|
2015-11-06 21:15:22 +08:00
|
|
|
/* GMIO_RESTRICT */
|
2015-04-10 21:07:22 +08:00
|
|
|
#ifndef GMIO_RESTRICT
|
|
|
|
# if defined(__GNUC__)
|
|
|
|
# define GMIO_RESTRICT __restrict__ /* Compatible with C90 */
|
|
|
|
# elif defined(_MSC_VER)
|
|
|
|
# define GMIO_RESTRICT __restrict
|
|
|
|
# elif defined(GMIO_HAVE_C99_RESTRICT) /* TODO: add cmake detectection */
|
|
|
|
# define GMIO_RESTRICT restrict
|
|
|
|
# else
|
|
|
|
/*! Expands to the C compiler specific restrict keyword (if any) */
|
|
|
|
# define GMIO_RESTRICT
|
|
|
|
# endif
|
2015-11-06 21:15:22 +08:00
|
|
|
#endif
|
2015-04-10 21:07:22 +08:00
|
|
|
|
2015-11-06 21:15:22 +08:00
|
|
|
/* GMIO_C_LINKAGE_BEGIN */
|
|
|
|
/* GMIO_C_LINKAGE_END */
|
2014-03-13 22:57:04 +08:00
|
|
|
#ifdef __cplusplus
|
2015-03-03 17:38:49 +08:00
|
|
|
# define GMIO_C_LINKAGE_BEGIN extern "C" {
|
|
|
|
# define GMIO_C_LINKAGE_END }
|
2014-03-13 22:57:04 +08:00
|
|
|
#else
|
2015-03-05 01:25:51 +08:00
|
|
|
/*! Expands to <tt>extern "C" {</tt> when building with a C++ compiler */
|
2015-03-03 17:38:49 +08:00
|
|
|
# define GMIO_C_LINKAGE_BEGIN
|
2015-03-05 01:25:51 +08:00
|
|
|
/*! Expands to \c } when building with a C++ compiler */
|
2015-03-03 17:38:49 +08:00
|
|
|
# define GMIO_C_LINKAGE_END
|
2015-11-06 21:15:22 +08:00
|
|
|
#endif
|
2014-03-13 22:57:04 +08:00
|
|
|
|
2015-11-06 21:15:22 +08:00
|
|
|
/* GMIO_PRAGMA_MSVC_WARNING_PUSH_AND_DISABLE */
|
|
|
|
/* GMIO_PRAGMA_MSVC_WARNING_POP */
|
2015-11-06 20:56:16 +08:00
|
|
|
#if defined(_MSC_VER) && _MSC_VER >= 1400 /* Visual C++ 2008 */
|
|
|
|
# define GMIO_PRAGMA_MSVC_WARNING_PUSH_AND_DISABLE(__code__) \
|
|
|
|
__pragma(warning(push)) \
|
|
|
|
__pragma(warning(disable: __code__))
|
|
|
|
# define GMIO_PRAGMA_MSVC_WARNING_POP() \
|
|
|
|
__pragma(warning(pop))
|
|
|
|
#else
|
|
|
|
/*! MSVC specific macro that disable the compiler warning of code \p __code__
|
|
|
|
*
|
|
|
|
* With Visual C++, expands to :
|
2016-04-06 23:33:05 +08:00
|
|
|
* \code{.c}
|
2015-11-06 20:56:16 +08:00
|
|
|
* #pragma warning(push)
|
|
|
|
* #pragma warning(disable: __code__)
|
|
|
|
* \endcode
|
|
|
|
*/
|
|
|
|
# define GMIO_PRAGMA_MSVC_WARNING_PUSH_AND_DISABLE(__code__)
|
|
|
|
/*! MSVC specific macro that pop the changes made after last warning(pop)
|
|
|
|
*
|
|
|
|
* With Visual C++, expands to :
|
2016-04-06 23:33:05 +08:00
|
|
|
* \code{.c}
|
2015-11-06 20:56:16 +08:00
|
|
|
* #pragma warning(pop)
|
|
|
|
* \endcode
|
|
|
|
*/
|
|
|
|
# define GMIO_PRAGMA_MSVC_WARNING_POP()
|
|
|
|
#endif
|
|
|
|
|
2016-01-05 18:50:17 +08:00
|
|
|
/*! Expands to the size(item count) of an array */
|
|
|
|
#define GMIO_ARRAY_SIZE(array) sizeof(array) / sizeof(*array)
|
|
|
|
|
2014-03-28 23:33:35 +08:00
|
|
|
#endif /* GMIO_GLOBAL_H */
|
2015-09-09 17:44:34 +08:00
|
|
|
/*! @} */
|