Files

175 lines
6.3 KiB
C++

/**
* @file include/ActivMiddleware/ActivMiddleware.h
*
* @brief Main header file. Sets up environment and various useful macros.
*/
#if (!defined ACTIV_MIDDLEWARE_H)
#define ACTIV_MIDDLEWARE_H
//! Macro to make an ACTIV-style a.b.c.d version value.
#define ACTIV_MAKE_VERSION_VALUE(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
//! Current ActivMiddleware version value.
#define ACTIV_MIDDLEWARE_VERSION_VALUE ACTIV_MAKE_VERSION_VALUE(2, 13, 2, 7)
//! Current ActivMiddleware version string.
#define ACTIV_MIDDLEWARE_VERSION_STRING "2.13.2.7"
//! Current ActivMiddleware version wide string.
#define ACTIV_MIDDLEWARE_VERSION_WIDE_STRING L"2.13.2.7"
//! Information string (product and version string).
#define ACTIV_MIDDLEWARE_INFO_STRING "ActivMiddleware" ACTIV_MIDDLEWARE_VERSION_STRING
// ---------------------------------------------------------------------------------------------------------------------------------
//! Calculate the number of elements in an array.
#define ACTIV_ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
//! Retrieve the first element of a macro pair.
#define ACTIV_DECLARE_ELEMENT_1_WITH_COMMA(a, b) a,
//! Retrieve the second element of a macro pair.
#define ACTIV_DECLARE_ELEMENT_2_WITH_COMMA(a, b) b,
//! Retrieve the macro parameter.
#define ACTIV_DECLARE_VALUE_WITH_COMMA(a) a,
//! Retrieve the macro parameter and prepend with 4 underscores.
#define ACTIV_DECLARE_HIDDEN_VALUE_WITH_COMMA(a) ____##a,
//! Retrieve the first element of a macro pair and prepend with 4 underscores.
#define ACTIV_DECLARE_HIDDEN_ELEMENT_1(a, b) ____##a,
//! Retrieve the second element of a macro pair and prepend with 4 underscores.
#define ACTIV_DECLARE_HIDDEN_ELEMENT_2(a, b) ____##b,
//! Declare a constant value from a hidden enumeration value declared with ACTIV_DECLARE_HIDDEN_ELEMENT_1.
#define ACTIV_DECLARE_CONSTANT_ELEMENT_1(type, a, b) const type a = ____##a;
//! Declare a static constant value from a hidden enumeration value declared with ACTIV_DECLARE_HIDDEN_ELEMENT_1.
#define ACTIV_DECLARE_STATIC_CONSTANT_ELEMENT_1(type, a, b) static const type a = ____##a;
#define ACTIV_DO_STRINGIZE(a) #a
//! Converts parameter a to a string after macro replacement on a has been performed.
#define ACTIV_STRINGIZE(a) ACTIV_DO_STRINGIZE(a)
//! Converts parameter a to a string after macro replacement on a has been performed and appends a comma.
#define ACTIV_STRINGIZE_WITH_COMMA(a) ACTIV_DO_STRINGIZE(a),
#define ACTIV_DO_JOIN(a, b) a##b
//! Concatenates two tokens after macro replacement has been performed.
#define ACTIV_JOIN(a, b) ACTIV_DO_JOIN(a, b)
//! Determines the offset of a member from the beginning of its parent structure.
#define ACTIV_FIELD_OFFSET(type, field) \
(reinterpret_cast<size_t>(&(reinterpret_cast<type *>(0)->*(&type::field))))
//! Determines the size of a member in its parent structure.
#define ACTIV_FIELD_SIZE(type, field) (sizeof(reinterpret_cast<type *>(0)->*(&type::field)))
//! Determines the minimum size of a structure to hold a member.
#define ACTIV_MIN_STRUCTURE_SIZE(type, field) (ACTIV_FIELD_OFFSET(type, field) + ACTIV_FIELD_SIZE(type, field))
//! Helper to define an accessor method for Boost parameter tags.
#define ACTIV_DECLARE_PARAMETER_ACCESSOR(namespaceName, parameterName) \
static const Boost::parameter::keyword<namespaceName::tag::parameterName> &parameterName() \
{ return namespaceName::_##parameterName; }
// ---------------------------------------------------------------------------------------------------------------------------------
//! Debug only macros.
#if (defined _DEBUG)
#define ACTIV_DEBUG_ONLY(a) a
#else
#define ACTIV_DEBUG_ONLY(a)
#endif
//! Release only macros.
#if (defined NDEBUG)
#define ACTIV_RELEASE_ONLY(a) a
#else
#define ACTIV_RELEASE_ONLY(a)
#endif
//! Enhanced debug macros.
#if (defined _DEBUG) && (defined ACTIV_ENABLE_ENHANCED_DEBUG)
#define ACTIV_ENHANCED_DEBUG_ONLY(a) a
#else
#define ACTIV_ENHANCED_DEBUG_ONLY(a)
#endif
//! If debug a else b.
#define ACTIV_IF_DEBUG_ELSE(a, b) ACTIV_DEBUG_ONLY(a) ACTIV_RELEASE_ONLY(b)
// ---------------------------------------------------------------------------------------------------------------------------------
// Set up environment.
#include "Config/Config.h"
// To ensure _STLPORT_VERSION is defined in an STLport build.
#include <cassert>
#if (defined _STLPORT_VERSION) && (!defined ACTIV_STLPORT)
#error Non STLport build specified but STLport headers found
#endif
#if (defined ACTIV_STLPORT) && (!defined _STLPORT_VERSION)
#error STLport build specified but non STLport headers found
#endif
#include "ActivMiddleware/Config/Boost.h"
#include "ActivMiddleware/Config/Suffix.h"
// ---------------------------------------------------------------------------------------------------------------------------------
// Essentials always available.
#include "ActivMiddleware/CxxYZ/utility.h"
#include "ActivMiddleware/Optimizations.h"
#include "ActivMiddleware/BasicTypes.h"
#include "ActivMiddleware/FormatSpecifiers.h"
#include "ActivMiddleware/StatusCodes.h"
#include ACTIV_BOOST_INCLUDE(noncopyable.hpp)
// ---------------------------------------------------------------------------------------------------------------------------------
#if (defined ACTIV_COMPILER_GCC)
#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4))
// For abi::__forced_unwind. It needs to come after BasicTypes.h to avoid issues with Boost; hence not in GCC.h.
#include <cxxabi.h>
//! Catch-all helper that includes catching and rethrowing abi::__forced_unwind. Use instead of "catch (...)".
#define ACTIV_CATCH_ALL() \
catch (const abi::__forced_unwind &) { throw; } \
catch (...)
#endif
#endif // (defined ACTIV_COMPILER_GCC)
#if (!defined ACTIV_CATCH_ALL)
//! Catch-all helper for compilers without abi::__forced_unwind. Use instead of "catch (...)".
#define ACTIV_CATCH_ALL() catch (...)
#endif // (!defined ACTIV_CATCH_ALL)
#if (ACTIV_CPLUSPLUS >= ACTIV_CPLUSPLUS_17)
//! Compatibility macro for the [[fallthrough]] attribute
#define ACTIV_FALLTHROUGH [[fallthrough]]
#else
// Note: the fallback would warn if it was empty as fallthrough requires a semi colon after it.
//! Compatibility macro for the [[fallthrough]] attribute
#define ACTIV_FALLTHROUGH ((void)0)
#endif
#endif // (!defined ACTIV_MIDDLEWARE_H)