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)
242 #define OCEAN_HARDWARE_NEON_VERSION 10
246 #ifndef OCEAN_HARDWARE_NEON_VERSION
247 #define OCEAN_HARDWARE_NEON_VERSION 0
255 #define OCEAN_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100)
257 #define OCEAN_GCC_VERSION 0
262 #define OCEAN_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100)
264 #define OCEAN_CLANG_VERSION 0
270 #define OCEAN_MSC_VERSION (_MSC_VER)
272 #define OCEAN_MSC_VERSION 0
294 #if defined(OCEAN_CLANG_VERSION) && OCEAN_CLANG_VERSION > 0
296 #define OCEAN_COMPILER_CLANG 1
299 #if defined(OCEAN_COMPILER_GCC) || defined(OCEAN_COMPILER_MSC)
300 #error Invalid compiler configuration.
305 #if defined(OCEAN_GCC_VERSION) && OCEAN_GCC_VERSION > 0
307 #if !defined(OCEAN_CLANG_VERSION) || OCEAN_CLANG_VERSION == 0
309 #define OCEAN_COMPILER_GCC 1
312 #if defined(OCEAN_COMPILER_CLANG) || defined(OCEAN_COMPILER_MSC)
313 #error Invalid compiler configuration.
317 #if defined(OCEAN_MSC_VERSION) && OCEAN_MSC_VERSION > 0
318 #error The GCC compiler is used already, either the usage of gcc or msc is wrong.
323 #if defined(OCEAN_MSC_VERSION) && OCEAN_MSC_VERSION > 0
325 #if !defined(OCEAN_CLANG_VERSION) || OCEAN_CLANG_VERSION == 0
326 #if !defined(OCEAN_GCC_VERSION) || OCEAN_GCC_VERSION == 0
328 #define OCEAN_COMPILER_MSC 1
331 #if defined(OCEAN_COMPILER_GCC) || defined(OCEAN_COMPILER_CLANG)
332 #error Invalid compiler configuration.
338 #if !defined(OCEAN_COMPILER_GCC) && !defined(OCEAN_COMPILER_CLANG) && !defined(OCEAN_COMPILER_MSC)
340 #error Unknown compiler, either GCC, Clang or the Microsoft compiler must be used.
344 #if !defined(OCEAN_POSIX_AVAILABLE)
346 #if defined(OCEAN_COMPILER_GCC) || (defined(OCEAN_COMPILER_CLANG) && !defined(_MSC_VER))
348 #define OCEAN_POSIX_AVAILABLE
355 #ifndef OCEAN_HARDWARE_SSE_VERSION
356 #if defined(_MSC_VER) && !defined(__clang__)
358 #if defined(_M_IX86_FP) && _M_IX86_FP >= 1
359 #define OCEAN_HARDWARE_SSE_VERSION 41
364 #define OCEAN_HARDWARE_SSE_VERSION 41
367 #elif defined(_MSC_VER) && defined(__clang__)
369 #if defined(__SSE4_1__)
370 #define OCEAN_HARDWARE_SSE_VERSION 41
373 #elif defined(__APPLE__)
375 #if defined(__SSE4_1__)
376 #define OCEAN_HARDWARE_SSE_VERSION 41
379 #elif defined(__linux__) && !defined(_ANDROID)
381 #if defined(__SSE4_1__)
382 #define OCEAN_HARDWARE_SSE_VERSION 41
388 #ifndef OCEAN_HARDWARE_SSE_VERSION
389 #define OCEAN_HARDWARE_SSE_VERSION 0
396 #if !defined(OCEAN_HARDWARE_AVX_VERSION) && OCEAN_HARDWARE_SSE_VERSION > 0
397 #if defined(_MSC_VER) || defined(__APPLE__) || (defined(__linux__) && !defined(_ANDROID))
399 #if defined(__AVX2__)
400 #define OCEAN_HARDWARE_AVX_VERSION 20
401 #elif defined(__AVX__)
402 #define OCEAN_HARDWARE_AVX_VERSION 10
408 #ifndef OCEAN_HARDWARE_AVX_VERSION
409 #define OCEAN_HARDWARE_AVX_VERSION 0
416 #if defined(_WINDOWS) || defined(_ANDROID) || defined(__APPLE__) || defined(__linux__) || defined(__EMSCRIPTEN__)
417 #ifndef OCEAN_LITTLE_ENDIAN
418 #define OCEAN_LITTLE_ENDIAN
426 #if defined(_WINDOWS) && defined(OCEAN_RUNTIME_SHARED)
427 #ifdef USE_OCEAN_BASE_EXPORT
428 #define OCEAN_BASE_EXPORT __declspec(dllexport)
430 #define OCEAN_BASE_EXPORT __declspec(dllimport)
433 #define OCEAN_BASE_EXPORT
440 #if defined(_ANDROID)
457 #ifdef OCEAN_REDIRECT_ASSERT_TO_MESSENGER
466 extern OCEAN_BASE_EXPORT
void assertErrorMessage(
const char* file,
const int line,
const char* message);
468 #define ocean_assert(e) ((bool(e) != true) ? Ocean::assertErrorMessage(__FILE__, __LINE__, #e) : ((void)0))
472 #define ocean_assert(e) assert(e)
476 #define ocean_assert(e) ((void)0)
489 #ifndef ocean_assert_accuracy
491 #define ocean_assert_accuracy(e) if (bool(e) != true) std::cout << "ocean_assert_accuracy(" << #e << "): in file " << __FILE__ << ", line " << __LINE__ << std::endl
493 #define ocean_assert_accuracy(e) ((void)0)
502 #ifndef ocean_assert_and_suppress_unused
504 #define ocean_assert_and_suppress_unused(expression, variable) ocean_assert(expression)
506 #define ocean_assert_and_suppress_unused(expression, variable) ((void)(variable))
513 #ifndef OCEAN_SUPPORT_RTTI
514 #if defined(OCEAN_COMPILER_MSC)
516 #define OCEAN_SUPPORT_RTTI
518 #elif defined(OCEAN_COMPILER_GCC) && OCEAN_GCC_VERSION >= 40302
520 #define OCEAN_SUPPORT_RTTI
522 #elif defined(OCEAN_COMPILER_CLANG) && OCEAN_CLANG_VERSION >= 20700
523 #if __has_feature(cxx_rtti)
524 #define OCEAN_SUPPORT_RTTI
533 #ifndef OCEAN_SUPPORT_EXCEPTIONS
534 #if defined(OCEAN_COMPILER_MSC)
536 #define OCEAN_SUPPORT_EXCEPTIONS
538 #elif defined(OCEAN_COMPILER_GCC) && OCEAN_GCC_VERSION > 0
539 #if defined(__EXCEPTIONS) && __EXCEPTIONS
540 #define OCEAN_SUPPORT_EXCEPTIONS
542 #elif defined(OCEAN_COMPILER_CLANG) && OCEAN_CLANG_VERSION > 0
543 #if defined(__EXCEPTIONS) && __EXCEPTIONS && __has_feature(cxx_exceptions)
544 #define OCEAN_SUPPORT_EXCEPTIONS
556 #ifndef OCEAN_WARNING_MISSING_IMPLEMENTATION
557 #ifdef OCEAN_COMPILETIME_WARNING_MISSING_IMPLEMENTATION
558 #ifdef OCEAN_COMPILER_MSC
559 #define OCEAN_WARNING_MISSING_IMPLEMENTATION __pragma(message("Missing implementation!")); assert(false && "Missing implementation!")
561 #define OCEAN_WARNING_MISSING_IMPLEMENTATION _Pragma ("message \"Missing implementation\""); assert(false && "Missing implementation!")
564 #define OCEAN_WARNING_MISSING_IMPLEMENTATION assert(false && "Missing implementation!")
572 #ifndef OCEAN_SUPPRESS_UNUSED_WARNING
573 #define OCEAN_SUPPRESS_UNUSED_WARNING(e) ((void)e)
585 template <
typename T>
595 #if defined(_WINDOWS)
597 #define OCEAN_PLATFORM_BUILD_WINDOWS
599 #elif defined(__APPLE__)
601 #define OCEAN_PLATFORM_BUILD_APPLE
603 #if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR == 1
605 #define OCEAN_PLATFORM_BUILD_APPLE_IOS_SUMULATOR
607 #elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE == 1
609 #define OCEAN_PLATFORM_BUILD_APPLE_IOS
611 #elif defined(TARGET_OS_MAC) && TARGET_OS_MAC == 1
613 #define OCEAN_PLATFORM_BUILD_APPLE_MACOS
617 #error Missing implementation
621 #if defined(OCEAN_PLATFORM_BUILD_APPLE_IOS_SUMULATOR) || defined(OCEAN_PLATFORM_BUILD_APPLE_IOS)
623 #define OCEAN_PLATFORM_BUILD_APPLE_IOS_ANY
627 #elif defined(_ANDROID)
629 #define OCEAN_PLATFORM_BUILD_ANDROID
631 #elif defined(__linux__) || defined(__EMSCRIPTEN__)
633 #define OCEAN_PLATFORM_BUILD_LINUX
637 #error Missing implementation
641 #if defined(OCEAN_PLATFORM_BUILD_ANDROID) || defined(OCEAN_PLATFORM_BUILD_APPLE_IOS_ANY)
643 #define OCEAN_PLATFORM_BUILD_MOBILE
651 #ifndef OCEAN_APPLY_IF_DEBUG
653 #define OCEAN_APPLY_IF_DEBUG(e) e
655 #define OCEAN_APPLY_IF_DEBUG(e) {}
660 #ifndef OCEAN_APPLY_IF_WINDOWS
661 #ifdef OCEAN_PLATFORM_BUILD_WINDOWS
662 #define OCEAN_APPLY_IF_WINDOWS(e) e
664 #define OCEAN_APPLY_IF_WINDOWS(e) {}
669 #ifndef OCEAN_APPLY_IF_APPLE
670 #ifdef OCEAN_PLATFORM_BUILD_APPLE
671 #define OCEAN_APPLY_IF_APPLE(e) e
673 #define OCEAN_APPLY_IF_APPLE(e) {}
678 #ifndef OCEAN_APPLY_IF_LINUX
679 #ifdef OCEAN_PLATFORM_BUILD_LINUX
680 #define OCEAN_APPLY_IF_LINUX(e) e
682 #define OCEAN_APPLY_IF_LINUX(e) {}
687 #ifndef OCEAN_APPLY_IF_ANDROID
688 #ifdef OCEAN_PLATFORM_BUILD_ANDROID
689 #define OCEAN_APPLY_IF_ANDROID(e) e
691 #define OCEAN_APPLY_IF_ANDROID(e) {}
696 #ifndef OCEAN_APPLY_IF_IPHONE
697 #if defined(OCEAN_PLATFORM_BUILD_APPLE_IOS) || defined(TARGET_IPHONE_SIMULATOR)
698 #define OCEAN_APPLY_IF_IPHONE(e) e
700 #define OCEAN_APPLY_IF_IPHONE(e) {}
705 #ifndef OCEAN_APPLY_IF_GCC
706 #if defined(OCEAN_GCC_VERSION) && OCEAN_GCC_VERSION > 0
707 #define OCEAN_APPLY_IF_GCC(e) e
709 #define OCEAN_APPLY_IF_GCC(e) {}
714 #ifndef OCEAN_APPLY_IF_SSE
715 #if defined(OCEAN_HARDWARE_SSE_VERSION) && OCEAN_HARDWARE_SSE_VERSION > 0
716 #define OCEAN_APPLY_IF_SSE(e) e
718 #define OCEAN_APPLY_IF_SSE(e) {}
723 #ifndef OCEAN_APPLY_IF_AVX
724 #if defined(OCEAN_HARDWARE_AVX_VERSION) && OCEAN_HARDWARE_AVX_VERSION > 0
725 #define OCEAN_APPLY_IF_AVX(e) e
727 #define OCEAN_APPLY_IF_AVX(e) {}
732 #ifndef OCEAN_APPLY_IF_NEON
733 #if defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION > 0
734 #define OCEAN_APPLY_IF_NEON(e) e
736 #define OCEAN_APPLY_IF_NEON(e) {}
745 #ifndef OCEAN_FORCE_INLINE
746 #if defined(OCEAN_COMPILER_MSC)
747 #define OCEAN_FORCE_INLINE __forceinline
748 #elif defined(OCEAN_COMPILER_CLANG)
749 #if __has_attribute(always_inline)
750 #define OCEAN_FORCE_INLINE inline __attribute__((always_inline))
752 #define OCEAN_FORCE_INLINE inline
754 #elif defined(OCEAN_COMPILER_GCC)
755 #define OCEAN_FORCE_INLINE inline __attribute__((always_inline))
757 #define OCEAN_FORCE_INLINE inline
765 #ifndef OCEAN_PREVENT_INLINE
766 #if defined(OCEAN_COMPILER_MSC)
767 #define OCEAN_PREVENT_INLINE __declspec(noinline)
768 #elif defined(OCEAN_COMPILER_CLANG)
769 #if __has_attribute(noinline)
770 #define OCEAN_PREVENT_INLINE __attribute__((noinline))
772 #define OCEAN_PREVENT_INLINE
774 #elif defined(OCEAN_COMPILER_GCC)
775 #define OCEAN_PREVENT_INLINE __attribute__((noinline))
777 #define OCEAN_PREVENT_INLINE
785 #ifndef OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION
786 #if defined(OCEAN_COMPILER_MSC)
787 #define OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION _Pragma("loop(no_vector)")
788 #elif defined(OCEAN_COMPILER_CLANG)
789 #define OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION _Pragma("clang loop vectorize(disable) interleave(disable)")
790 #elif defined(OCEAN_COMPILER_GCC)
791 #define OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION _Pragma("GCC unroll 1")
793 #define OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION
798 #ifndef OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION_IF_NEON
799 #if defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION > 0
800 #define OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION_IF_NEON OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION
802 #define OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION_IF_NEON
810 #ifndef OCEAN_ALIGN_DATA
811 #if defined(OCEAN_COMPILER_MSC)
812 #define OCEAN_ALIGN_DATA(x) __declspec(align(x))
814 #define OCEAN_ALIGN_DATA(x) __attribute__ ((aligned(x)))
822 #if (defined(DEBUG) || defined(OCEAN_DEBUG)) && defined(NDEBUG)
823 #error You cannot define both flags (DEBUG and NDEBUG) concurrently
826 #if defined(OCEAN_INTENSIVE_DEBUG) && (!defined(DEBUG) || !defined(OCEAN_DEBUG))
827 #error You cannot define OCEAN_INTENSIVE_DEBUG without defining DEBUG/OCEAN_DEBUG
834 #if !defined(OCEAN_DEBUG) || defined(NDEBUG)
843 #ifndef OCEAN_DISABLE_DOCUMENTATION_DIAGNOSTIC
844 #if defined(OCEAN_CLANG_VERSION) && OCEAN_CLANG_VERSION > 0
845 #define OCEAN_DISABLE_DOCUMENTATION_DIAGNOSTIC _Pragma("clang diagnostic push") \
846 _Pragma("clang diagnostic ignored \"-Wdocumentation\"")
848 #define OCEAN_DISABLE_DOCUMENTATION_DIAGNOSTIC
853 #ifndef OCEAN_RE_ENABLE_DOCUMENTATION_DIAGNOSTIC
854 #if defined(OCEAN_CLANG_VERSION) && OCEAN_CLANG_VERSION > 0
855 #define OCEAN_RE_ENABLE_DOCUMENTATION_DIAGNOSTIC _Pragma("clang diagnostic pop")
857 #define OCEAN_RE_ENABLE_DOCUMENTATION_DIAGNOSTIC
865 #ifndef OCEAN_PRINT_MACRO_VALUE
866 #define OCEAN_PRINT_MACRO_VALUE_INTERNAL_INTERNAL(value) #value
867 #define OCEAN_PRINT_MACRO_VALUE_INTERNAL(value) OCEAN_PRINT_MACRO_VALUE_INTERNAL_INTERNAL(value)
869 #define OCEAN_PRAGMA_INTERNAL(value) _Pragma(#value)
870 #define OCEAN_PRAGMA(value) OCEAN_PRAGMA_INTERNAL(value)
872 #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::set< Index32 > IndexSet32
Definition of a set holding 32 bit indices.
Definition: Base.h:114
uint64_t Index64
Definition of a 64 bit index value.
Definition: Base.h:90
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:586
std::vector< std::wstring > WStrings
Definition of a vector holding strings.
Definition: Base.h:168
std::vector< Indices32 > IndexGroups32
Definition of a vector holding 32 bit indices, so we have groups of indices.
Definition: Base.h:102
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition: Base.h:96
std::vector< Index64 > Indices64
Definition of a vector holding 64 bit index values.
Definition: Base.h:108
std::unordered_set< Index32 > UnorderedIndexSet32
Definition of an unordered_set holding 32 bit indices.
Definition: Base.h:126
OCEAN_BASE_EXPORT void assertErrorMessage(const char *file, const int line, const char *message)
Error message function for redirected asserts.
std::set< Index64 > IndexSet64
Definition of a set holding 64 bit indices.
Definition: Base.h:120
std::pair< Index64, Index64 > IndexPair64
Definition of a pair holding 64 bit indices.
Definition: Base.h:150
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::pair< Index32, Index32 > IndexPair32
Definition of a pair holding 32 bit indices.
Definition: Base.h:138
uint32_t Index32
Definition of a 32 bit index value.
Definition: Base.h:84
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15