8#ifndef META_OCEAN_BASE_BASE_H
9#define META_OCEAN_BASE_BASE_H
21#include <unordered_map>
22#include <unordered_set>
26 #include <TargetConditionals.h>
178#if (!defined(ENABLE_LOGGING) || ENABLE_LOGGING != 1) && (!defined(OCEAN_ACTIVATE_MESSENGER) || OCEAN_ACTIVATE_MESSENGER != 1) && (!defined(PROFILE) || PROFILE != 1)
179 #ifndef OCEAN_DEACTIVATED_MESSENGER
180 #define OCEAN_DEACTIVATED_MESSENGER
191#if !defined(OCEAN_DEBUG) && (defined(DEBUG) || defined(_DEBUG))
200 #ifndef OCEAN_INTENSIVE_DEBUG
209#if defined(__ANDROID__) && !defined(_ANDROID)
217#ifndef OCEAN_RUNTIME_SHARED
218 #ifndef OCEAN_RUNTIME_STATIC
219 #define OCEAN_RUNTIME_STATIC
227#if defined(_ANDROID) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE == 1)
228 #ifndef OCEAN_HARDWARE_REDUCED_PERFORMANCE
229 #define OCEAN_HARDWARE_REDUCED_PERFORMANCE
240#ifndef OCEAN_HARDWARE_NEON_VERSION
241 #if defined(__ARM_NEON__) || defined(__ARM_NEON)
243 #define OCEAN_HARDWARE_NEON_VERSION 10
244 #elif defined(_M_ARM64)
246 #define OCEAN_HARDWARE_NEON_VERSION 10
250#ifndef OCEAN_HARDWARE_NEON_VERSION
251 #define OCEAN_HARDWARE_NEON_VERSION 0
259 #define OCEAN_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100)
261 #define OCEAN_GCC_VERSION 0
266 #define OCEAN_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100)
268 #define OCEAN_CLANG_VERSION 0
274 #define OCEAN_MSC_VERSION (_MSC_VER)
276 #define OCEAN_MSC_VERSION 0
298#if defined(OCEAN_CLANG_VERSION) && OCEAN_CLANG_VERSION > 0
300 #define OCEAN_COMPILER_CLANG 1
303 #if defined(OCEAN_COMPILER_GCC) || defined(OCEAN_COMPILER_MSC)
304 #error Invalid compiler configuration.
309#if defined(OCEAN_GCC_VERSION) && OCEAN_GCC_VERSION > 0
311 #if !defined(OCEAN_CLANG_VERSION) || OCEAN_CLANG_VERSION == 0
313 #define OCEAN_COMPILER_GCC 1
316 #if defined(OCEAN_COMPILER_CLANG) || defined(OCEAN_COMPILER_MSC)
317 #error Invalid compiler configuration.
321 #if defined(OCEAN_MSC_VERSION) && OCEAN_MSC_VERSION > 0
322 #error The GCC compiler is used already, either the usage of gcc or msc is wrong.
327#if defined(OCEAN_MSC_VERSION) && OCEAN_MSC_VERSION > 0
329 #if !defined(OCEAN_CLANG_VERSION) || OCEAN_CLANG_VERSION == 0
330 #if !defined(OCEAN_GCC_VERSION) || OCEAN_GCC_VERSION == 0
332 #define OCEAN_COMPILER_MSC 1
335 #if defined(OCEAN_COMPILER_GCC) || defined(OCEAN_COMPILER_CLANG)
336 #error Invalid compiler configuration.
342#if !defined(OCEAN_COMPILER_GCC) && !defined(OCEAN_COMPILER_CLANG) && !defined(OCEAN_COMPILER_MSC)
344 #error Unknown compiler, either GCC, Clang or the Microsoft compiler must be used.
348#if !defined(OCEAN_POSIX_AVAILABLE)
350 #if defined(OCEAN_COMPILER_GCC) || (defined(OCEAN_COMPILER_CLANG) && !defined(_MSC_VER))
352 #define OCEAN_POSIX_AVAILABLE
359#ifndef OCEAN_HARDWARE_SSE_VERSION
360 #if defined(_MSC_VER) && !defined(__clang__)
362 #if defined(_M_IX86_FP) && _M_IX86_FP >= 1
363 #define OCEAN_HARDWARE_SSE_VERSION 41
368 #define OCEAN_HARDWARE_SSE_VERSION 41
371 #elif defined(_MSC_VER) && defined(__clang__)
373 #if defined(__SSE4_1__)
374 #define OCEAN_HARDWARE_SSE_VERSION 41
377 #elif defined(__APPLE__)
379 #if defined(__SSE4_1__)
380 #define OCEAN_HARDWARE_SSE_VERSION 41
383 #elif defined(__linux__) && !defined(_ANDROID)
385 #if defined(__SSE4_1__)
386 #define OCEAN_HARDWARE_SSE_VERSION 41
392#ifndef OCEAN_HARDWARE_SSE_VERSION
393 #define OCEAN_HARDWARE_SSE_VERSION 0
400#if !defined(OCEAN_HARDWARE_AVX_VERSION) && OCEAN_HARDWARE_SSE_VERSION > 0
401 #if defined(_MSC_VER) || defined(__APPLE__) || (defined(__linux__) && !defined(_ANDROID))
403 #if defined(__AVX2__)
404 #define OCEAN_HARDWARE_AVX_VERSION 20
405 #elif defined(__AVX__)
406 #define OCEAN_HARDWARE_AVX_VERSION 10
412#ifndef OCEAN_HARDWARE_AVX_VERSION
413 #define OCEAN_HARDWARE_AVX_VERSION 0
420#if defined(_WINDOWS) || defined(_ANDROID) || defined(__APPLE__) || defined(__linux__) || defined(__EMSCRIPTEN__)
421 #ifndef OCEAN_LITTLE_ENDIAN
422 #define OCEAN_LITTLE_ENDIAN
430#if defined(_WINDOWS) && defined(OCEAN_RUNTIME_SHARED)
431 #ifdef USE_OCEAN_BASE_EXPORT
432 #define OCEAN_BASE_EXPORT __declspec(dllexport)
434 #define OCEAN_BASE_EXPORT __declspec(dllimport)
437 #define OCEAN_BASE_EXPORT
461 #ifdef OCEAN_REDIRECT_ASSERT_TO_MESSENGER
470 extern OCEAN_BASE_EXPORT
void assertErrorMessage(
const char* file,
const int line,
const char* message);
472 #define ocean_assert(e) ((bool(e) != true) ? Ocean::assertErrorMessage(__FILE__, __LINE__, #e) : ((void)0))
476 #define ocean_assert(e) assert(e)
480 #define ocean_assert(e) ((void)0)
493#ifndef ocean_assert_accuracy
495 #define ocean_assert_accuracy(e) if (bool(e) != true) std::cout << "ocean_assert_accuracy(" << #e << "): in file " << __FILE__ << ", line " << __LINE__ << std::endl
497 #define ocean_assert_accuracy(e) ((void)0)
506#ifndef ocean_assert_and_suppress_unused
508 #define ocean_assert_and_suppress_unused(expression, variable) ocean_assert(expression)
510 #define ocean_assert_and_suppress_unused(expression, variable) ((void)(variable))
517#ifndef OCEAN_SUPPORT_RTTI
518 #if defined(OCEAN_COMPILER_MSC)
520 #define OCEAN_SUPPORT_RTTI
522 #elif defined(OCEAN_COMPILER_GCC) && OCEAN_GCC_VERSION >= 40302
524 #define OCEAN_SUPPORT_RTTI
526 #elif defined(OCEAN_COMPILER_CLANG) && OCEAN_CLANG_VERSION >= 20700
527 #if __has_feature(cxx_rtti)
528 #define OCEAN_SUPPORT_RTTI
537#ifndef OCEAN_SUPPORT_EXCEPTIONS
538 #if defined(OCEAN_COMPILER_MSC)
540 #define OCEAN_SUPPORT_EXCEPTIONS
542 #elif defined(OCEAN_COMPILER_GCC) && OCEAN_GCC_VERSION > 0
543 #if defined(__EXCEPTIONS) && __EXCEPTIONS
544 #define OCEAN_SUPPORT_EXCEPTIONS
546 #elif defined(OCEAN_COMPILER_CLANG) && OCEAN_CLANG_VERSION > 0
547 #if defined(__EXCEPTIONS) && __EXCEPTIONS && __has_feature(cxx_exceptions)
548 #define OCEAN_SUPPORT_EXCEPTIONS
560#ifndef OCEAN_WARNING_MISSING_IMPLEMENTATION
561 #ifdef OCEAN_COMPILETIME_WARNING_MISSING_IMPLEMENTATION
562 #ifdef OCEAN_COMPILER_MSC
563 #define OCEAN_WARNING_MISSING_IMPLEMENTATION __pragma(message("Missing implementation!")); assert(false && "Missing implementation!")
565 #define OCEAN_WARNING_MISSING_IMPLEMENTATION _Pragma ("message \"Missing implementation\""); assert(false && "Missing implementation!")
568 #define OCEAN_WARNING_MISSING_IMPLEMENTATION assert(false && "Missing implementation!")
576#ifndef OCEAN_SUPPRESS_UNUSED_WARNING
577 #define OCEAN_SUPPRESS_UNUSED_WARNING(e) ((void)e)
601 #define OCEAN_PLATFORM_BUILD_WINDOWS
603#elif defined(__APPLE__)
605 #define OCEAN_PLATFORM_BUILD_APPLE
610 #if defined(TARGET_OS_TV) && TARGET_OS_TV == 1
612 #define OCEAN_PLATFORM_BUILD_APPLE_TVOS
614 #elif defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR == 1
616 #define OCEAN_PLATFORM_BUILD_APPLE_IOS_SIMULATOR
618 #elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE == 1
620 #define OCEAN_PLATFORM_BUILD_APPLE_IOS
622 #elif defined(TARGET_OS_MAC) && TARGET_OS_MAC == 1
624 #define OCEAN_PLATFORM_BUILD_APPLE_MACOS
628 #error Missing implementation
632 #if defined(OCEAN_PLATFORM_BUILD_APPLE_IOS_SIMULATOR) || defined(OCEAN_PLATFORM_BUILD_APPLE_IOS)
634 #define OCEAN_PLATFORM_BUILD_APPLE_IOS_ANY
638#elif defined(_ANDROID)
640 #define OCEAN_PLATFORM_BUILD_ANDROID
642#elif defined(__linux__) || defined(__EMSCRIPTEN__)
644 #define OCEAN_PLATFORM_BUILD_LINUX
648 #error Missing implementation
652#if defined(OCEAN_PLATFORM_BUILD_ANDROID) || defined(OCEAN_PLATFORM_BUILD_APPLE_IOS_ANY)
654 #define OCEAN_PLATFORM_BUILD_MOBILE
662#ifndef OCEAN_APPLY_IF_DEBUG
664 #define OCEAN_APPLY_IF_DEBUG(e) e
666 #define OCEAN_APPLY_IF_DEBUG(e) {}
671#ifndef OCEAN_APPLY_IF_WINDOWS
672 #ifdef OCEAN_PLATFORM_BUILD_WINDOWS
673 #define OCEAN_APPLY_IF_WINDOWS(e) e
675 #define OCEAN_APPLY_IF_WINDOWS(e) {}
680#ifndef OCEAN_APPLY_IF_APPLE
681 #ifdef OCEAN_PLATFORM_BUILD_APPLE
682 #define OCEAN_APPLY_IF_APPLE(e) e
684 #define OCEAN_APPLY_IF_APPLE(e) {}
689#ifndef OCEAN_APPLY_IF_LINUX
690 #ifdef OCEAN_PLATFORM_BUILD_LINUX
691 #define OCEAN_APPLY_IF_LINUX(e) e
693 #define OCEAN_APPLY_IF_LINUX(e) {}
698#ifndef OCEAN_APPLY_IF_ANDROID
699 #ifdef OCEAN_PLATFORM_BUILD_ANDROID
700 #define OCEAN_APPLY_IF_ANDROID(e) e
702 #define OCEAN_APPLY_IF_ANDROID(e) {}
707#ifndef OCEAN_APPLY_IF_IPHONE
708 #if defined(OCEAN_PLATFORM_BUILD_APPLE_IOS) || defined(TARGET_IPHONE_SIMULATOR)
709 #define OCEAN_APPLY_IF_IPHONE(e) e
711 #define OCEAN_APPLY_IF_IPHONE(e) {}
716#ifndef OCEAN_APPLY_IF_GCC
717 #if defined(OCEAN_GCC_VERSION) && OCEAN_GCC_VERSION > 0
718 #define OCEAN_APPLY_IF_GCC(e) e
720 #define OCEAN_APPLY_IF_GCC(e) {}
725#ifndef OCEAN_APPLY_IF_SSE
726 #if defined(OCEAN_HARDWARE_SSE_VERSION) && OCEAN_HARDWARE_SSE_VERSION > 0
727 #define OCEAN_APPLY_IF_SSE(e) e
729 #define OCEAN_APPLY_IF_SSE(e) {}
734#ifndef OCEAN_APPLY_IF_AVX
735 #if defined(OCEAN_HARDWARE_AVX_VERSION) && OCEAN_HARDWARE_AVX_VERSION > 0
736 #define OCEAN_APPLY_IF_AVX(e) e
738 #define OCEAN_APPLY_IF_AVX(e) {}
743#ifndef OCEAN_APPLY_IF_NEON
744 #if defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION > 0
745 #define OCEAN_APPLY_IF_NEON(e) e
747 #define OCEAN_APPLY_IF_NEON(e) {}
756#ifndef OCEAN_FORCE_INLINE
757 #if defined(OCEAN_COMPILER_MSC)
758 #define OCEAN_FORCE_INLINE __forceinline
759 #elif defined(OCEAN_COMPILER_CLANG)
760 #if __has_attribute(always_inline)
761 #define OCEAN_FORCE_INLINE inline __attribute__((always_inline))
763 #define OCEAN_FORCE_INLINE inline
765 #elif defined(OCEAN_COMPILER_GCC)
766 #define OCEAN_FORCE_INLINE inline __attribute__((always_inline))
768 #define OCEAN_FORCE_INLINE inline
776#ifndef OCEAN_PREVENT_INLINE
777 #if defined(OCEAN_COMPILER_MSC)
778 #define OCEAN_PREVENT_INLINE __declspec(noinline)
779 #elif defined(OCEAN_COMPILER_CLANG)
780 #if __has_attribute(noinline)
781 #define OCEAN_PREVENT_INLINE __attribute__((noinline))
783 #define OCEAN_PREVENT_INLINE
785 #elif defined(OCEAN_COMPILER_GCC)
786 #define OCEAN_PREVENT_INLINE __attribute__((noinline))
788 #define OCEAN_PREVENT_INLINE
796#ifndef OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION
797 #if defined(OCEAN_COMPILER_MSC)
798 #define OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION _Pragma("loop(no_vector)")
799 #elif defined(OCEAN_COMPILER_CLANG)
800 #define OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION _Pragma("clang loop vectorize(disable) interleave(disable)")
801 #elif defined(OCEAN_COMPILER_GCC)
802 #define OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION _Pragma("GCC unroll 1")
804 #define OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION
809#ifndef OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION_IF_NEON
810 #if defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION > 0
811 #define OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION_IF_NEON OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION
813 #define OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION_IF_NEON
821#ifndef OCEAN_ALIGN_DATA
822 #if defined(OCEAN_COMPILER_MSC)
823 #define OCEAN_ALIGN_DATA(x) __declspec(align(x))
825 #define OCEAN_ALIGN_DATA(x) __attribute__ ((aligned(x)))
833#if (defined(DEBUG) || defined(OCEAN_DEBUG)) && defined(NDEBUG)
834 #error You cannot define both flags (DEBUG and NDEBUG) concurrently
837#if defined(OCEAN_INTENSIVE_DEBUG) && (!defined(DEBUG) || !defined(OCEAN_DEBUG))
838 #error You cannot define OCEAN_INTENSIVE_DEBUG without defining DEBUG/OCEAN_DEBUG
845 #if !defined(OCEAN_DEBUG) || defined(NDEBUG)
854#ifndef OCEAN_DISABLE_DOCUMENTATION_DIAGNOSTIC
855 #if defined(OCEAN_CLANG_VERSION) && OCEAN_CLANG_VERSION > 0
856 #define OCEAN_DISABLE_DOCUMENTATION_DIAGNOSTIC _Pragma("clang diagnostic push") \
857 _Pragma("clang diagnostic ignored \"-Wdocumentation\"")
859 #define OCEAN_DISABLE_DOCUMENTATION_DIAGNOSTIC
864#ifndef OCEAN_RE_ENABLE_DOCUMENTATION_DIAGNOSTIC
865 #if defined(OCEAN_CLANG_VERSION) && OCEAN_CLANG_VERSION > 0
866 #define OCEAN_RE_ENABLE_DOCUMENTATION_DIAGNOSTIC _Pragma("clang diagnostic pop")
868 #define OCEAN_RE_ENABLE_DOCUMENTATION_DIAGNOSTIC
876#ifndef OCEAN_PRINT_MACRO_VALUE
877 #define OCEAN_PRINT_MACRO_VALUE_INTERNAL_INTERNAL(value) #value
878 #define OCEAN_PRINT_MACRO_VALUE_INTERNAL(value) OCEAN_PRINT_MACRO_VALUE_INTERNAL_INTERNAL(value)
880 #define OCEAN_PRAGMA_INTERNAL(value) _Pragma(#value)
881 #define OCEAN_PRAGMA(value) OCEAN_PRAGMA_INTERNAL(value)
883 #define OCEAN_PRINT_MACRO_VALUE(text, value) OCEAN_PRAGMA(message text OCEAN_PRINT_MACRO_VALUE_INTERNAL(value))
std::vector< IndexPair32 > IndexPairs32
Definition of a vector holding 32 bit index pairs.
Definition Base.h:144
std::pair< Index64, Index64 > IndexPair64
Definition of a pair holding 64 bit indices.
Definition Base.h:150
std::set< Index64 > IndexSet64
Definition of a set holding 64 bit indices.
Definition Base.h:120
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition Base.h:96
std::unordered_set< Index64 > UnorderedIndexSet64
Definition of an unordered_set holding 64 bit indices.
Definition Base.h:132
std::vector< IndexPair64 > IndexPairs64
Definition of a vector holding 64 bit index pairs.
Definition Base.h:156
std::vector< Indices32 > IndexGroups32
Definition of a vector holding 32 bit indices, so we have groups of indices.
Definition Base.h:102
std::vector< std::string > Strings
Definition of a vector holding strings.
Definition Base.h:162
constexpr bool oceanFalse()
This function is a helper function returning false any time.
Definition Base.h:590
std::vector< Index64 > Indices64
Definition of a vector holding 64 bit index values.
Definition Base.h:108
uint32_t Index32
Definition of a 32 bit index value.
Definition Base.h:84
std::pair< Index32, Index32 > IndexPair32
Definition of a pair holding 32 bit indices.
Definition Base.h:138
uint64_t Index64
Definition of a 64 bit index value.
Definition Base.h:90
std::set< Index32 > IndexSet32
Definition of a set holding 32 bit indices.
Definition Base.h:114
std::vector< std::wstring > WStrings
Definition of a vector holding strings.
Definition Base.h:168
OCEAN_BASE_EXPORT void assertErrorMessage(const char *file, const int line, const char *message)
Error message function for redirected asserts.
std::unordered_set< Index32 > UnorderedIndexSet32
Definition of an unordered_set holding 32 bit indices.
Definition Base.h:126
The namespace covering the entire Ocean framework.
Definition Accessor.h:15