Ocean
Loading...
Searching...
No Matches
Base.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_BASE_BASE_H
9#define META_OCEAN_BASE_BASE_H
10
11#include <algorithm>
12#include <array>
13#include <cassert>
14#include <cstdint>
15#include <cstdlib>
16#include <cstring>
17#include <map>
18#include <memory>
19#include <set>
20#include <string>
21#include <unordered_map>
22#include <unordered_set>
23#include <vector>
24
25#ifdef __APPLE__
26 #include <TargetConditionals.h>
27#endif
28
29namespace Ocean
30{
31
32/**
33 * @defgroup base Ocean Base Library
34 * @{
35 * The Ocean Base Library provides all base functionalities needed in the Ocean framework.
36 * The library is platform independent.
37 *
38 * The DateTime, Timestamp and HighPerformanceTimer classes provide date and time functionalities.<br>
39 *
40 * The Thread, Lock, Signal, Thread, ThreadPool, Worker and WorkerPool classes provide threading, mutex, signal and critical section functionalities.<br>
41 *
42 * Callback and Caller realize callback functions and the Scheduler can be applied to implement regular timer events.<br>
43 *
44 * The StaticBuffer, StaticVector, ShiftVector, KdTree, HashSet, HasMap, RingMap and Triple classes provide possibilities to store and access data elements within individual structures.<br>
45 *
46 * The RandomI and RandomGenerator classes provide capabilities to create random numbers.<br>
47 *
48 * The ObjectRef and SmartObjectRef classes encapsulate individual objects by object references with reference counters.<br>
49 *
50 * Use the Frame class to store arbitrary 2D (image) information.<br>
51 *
52 * Singletons can be realized by application of the Singleton class.<br>
53 *
54 * Several helper classes exist providing template-based solutions to e.g., create data types with specific size or to create data types larger than a specific data type.
55 * Some of this classes are: DataType, SquareValueTyper, DifferenceValueTyper, NextLargerTyper, UnsignedTyper, TypeNamer.
56 * @}
57 */
58
59/**
60 * @namespace Ocean The namespace covering the entire Ocean framework.<p>
61 * Ocean is the base namespace for the Ocean framework.<br>
62 * The Namespace Ocean is used in the Base and Math library directly.
63 */
64
65// Do not use windows min-max functionality
66#ifndef NOMINMAX
67 #define NOMINMAX
68#endif
69
70/**
71 * Using min from std.
72 */
73using std::min;
74
75/**
76 * Using max from std.
77 */
78using std::max;
79
80/**
81 * Definition of a 32 bit index value.
82 * @ingroup base
83 */
84using Index32 = uint32_t;
85
86/**
87 * Definition of a 64 bit index value.
88 * @ingroup base
89 */
90using Index64 = uint64_t;
91
92/**
93 * Definition of a vector holding 32 bit index values.
94 * @ingroup base
95 */
96using Indices32 = std::vector<Index32>;
97
98/**
99 * Definition of a vector holding 32 bit indices, so we have groups of indices.
100 * @ingroup base
101 */
102using IndexGroups32 = std::vector<Indices32>;
103
104/**
105 * Definition of a vector holding 64 bit index values.
106 * @ingroup base
107 */
108using Indices64 = std::vector<Index64>;
109
110/**
111 * Definition of a set holding 32 bit indices.
112 * @ingroup base
113 */
114using IndexSet32 = std::set<Index32>;
115
116/**
117 * Definition of a set holding 64 bit indices.
118 * @ingroup base
119 */
120using IndexSet64 = std::set<Index64>;
121
122/**
123 * Definition of an unordered_set holding 32 bit indices.
124 * @ingroup base
125 */
126using UnorderedIndexSet32 = std::unordered_set<Index32>;
127
128/**
129 * Definition of an unordered_set holding 64 bit indices.
130 * @ingroup base
131 */
132using UnorderedIndexSet64 = std::unordered_set<Index64>;
133
134/**
135 * Definition of a pair holding 32 bit indices.
136 * @ingroup base
137 */
138using IndexPair32 = std::pair<Index32, Index32>;
139
140/**
141 * Definition of a vector holding 32 bit index pairs.
142 * @ingroup base
143 */
144using IndexPairs32 = std::vector<IndexPair32>;
145
146/**
147 * Definition of a pair holding 64 bit indices.
148 * @ingroup base
149 */
150using IndexPair64 = std::pair<Index64, Index64>;
151
152/**
153 * Definition of a vector holding 64 bit index pairs.
154 * @ingroup base
155 */
156using IndexPairs64 = std::vector<IndexPair64>;
157
158/**
159 * Definition of a vector holding strings.
160 * @ingroup base
161 */
162using Strings = std::vector<std::string>;
163
164/**
165 * Definition of a vector holding strings.
166 * @ingroup base
167 */
168using WStrings = std::vector<std::wstring>;
169
170
171
172// Define OCEAN_DEACTIVATED_MESSENGER to disable the messenger capabilities in the entire framework.
173// Disabling the messenger in the release build also ensures that message strings will not be part of the release binaries.
174// ENABLE_LOGGING should be enabled in local, rc, and master (but not in profile) builds
175// PROFILE should be enabled in profile builds
176// Thus, we use Ocean's messenger in local, profile, rc and master - but not in production
177// OCEAN_ACTIVATE_MESSENGER can be defined to explicitly avoid deactivating Ocean's messenger
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
181 #endif
182#else
183 // #define OCEAN_DEACTIVATED_MESSENGER
184#endif
185
186
187
188
189// we ensure that OCEAN_DEBUG is also defined as long as DEBUG is defined or _DEBUG is defined
190// but do not define OCEAN_DEBUG in fuzzing mode.
191#if !defined(OCEAN_DEBUG) && (defined(DEBUG) || defined(_DEBUG))
192 #define OCEAN_DEBUG
193#endif
194
195
196
197
198// Define OCEAN_INTENSIVE_DEBUG to activate code blocks intensively checking the correctness/accuracy of some specific function which is disabled by default.
199#ifdef OCEAN_DEBUG
200 #ifndef OCEAN_INTENSIVE_DEBUG
201 //#define OCEAN_INTENSIVE_DEBUG
202 #endif
203#endif
204
205
206
207
208// we ensure that _ANDROID is also defined as long as __ANDROID__ is defined
209#if defined(__ANDROID__) && !defined(_ANDROID)
210 #define _ANDROID
211#endif
212
213
214
215
216// Defines OCEAN_RUNTIME_STATIC for static runtimes
217#ifndef OCEAN_RUNTIME_SHARED
218 #ifndef OCEAN_RUNTIME_STATIC
219 #define OCEAN_RUNTIME_STATIC
220 #endif
221#endif
222
223
224
225
226// Defines OCEAN_HARDWARE_REDUCED_PERFORMANCE to allow the usage of specific code for hardware with reduced computational power.
227#if defined(_ANDROID) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE == 1)
228 #ifndef OCEAN_HARDWARE_REDUCED_PERFORMANCE
229 #define OCEAN_HARDWARE_REDUCED_PERFORMANCE
230 #endif
231#else
232 //#define OCEAN_HARDWARE_REDUCED_PERFORMANCE
233#endif
234
235
236
237
238
239// Defines OCEAN_HARDWARE_NEON_VERSION for platforms supporting NEON instructions
240#ifndef OCEAN_HARDWARE_NEON_VERSION
241 #if defined(__ARM_NEON__) || defined(__ARM_NEON)
242 // Clang and GCC
243 #define OCEAN_HARDWARE_NEON_VERSION 10
244 #elif defined(_M_ARM64)
245 // MSVC
246 #define OCEAN_HARDWARE_NEON_VERSION 10
247 #endif
248#endif
249
250#ifndef OCEAN_HARDWARE_NEON_VERSION
251 #define OCEAN_HARDWARE_NEON_VERSION 0
252#endif
253
254
255
256
257// Defines OCEAN_GCC_VERSION according to the given GCC version
258#ifdef __GNUC__
259 #define OCEAN_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100)
260#else
261 #define OCEAN_GCC_VERSION 0
262#endif
263
264// Defines OCEAN_CLANG_VERSION according to the given Clang version
265#ifdef __clang__
266 #define OCEAN_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100)
267#else
268 #define OCEAN_CLANG_VERSION 0
269#endif
270
271// Defines OCEAN_MSC_VERSION according to the given _MSC_VER version
272// Beware: _MSC_VER may be defined although the Microsoft compiler is not applied e.g., when using clang for Windows platforms.
273#ifdef _MSC_VER
274 #define OCEAN_MSC_VERSION (_MSC_VER)
275#else
276 #define OCEAN_MSC_VERSION 0
277#endif
278
279
280
281
282/**
283 * Ocean supports the following compilers:
284 * GCC, Clang, Microsoft
285 * As macros like `_MSC_VER` can be defined by the Clang compiler (when compiling for Windows platforms),
286 * Ocean defines an own macro `OCEAN_COMPILER_***` to identify the individual compiler.
287 * The macro is defined as follows:
288 * <pre>
289 * Active compiler macro: __GNUC__: __clang__: _MSC_VER:
290 * OCEAN_COMPILER_CLANG do not care defined do not care
291 * OCEAN_COMPILER_GCC defined undefined undefined
292 * OCEAN_COMPILER_MSC undefined undefined defined
293 * </pre>
294 * @ingroup base
295 */
296
297// Defines OCEAN_COMPILER_CLANG if the clang compiler is used
298#if defined(OCEAN_CLANG_VERSION) && OCEAN_CLANG_VERSION > 0
299 /// \cond DOXYGEN_DO_NOT_DOCUMENT
300 #define OCEAN_COMPILER_CLANG 1
301 /// \endcond
302
303 #if defined(OCEAN_COMPILER_GCC) || defined(OCEAN_COMPILER_MSC)
304 #error Invalid compiler configuration.
305 #endif
306#endif
307
308// Defines OCEAN_COMPILER_GCC if the gcc compiler is used
309#if defined(OCEAN_GCC_VERSION) && OCEAN_GCC_VERSION > 0
310
311 #if !defined(OCEAN_CLANG_VERSION) || OCEAN_CLANG_VERSION == 0
312 /// \cond DOXYGEN_DO_NOT_DOCUMENT
313 #define OCEAN_COMPILER_GCC 1
314 /// \endcond
315
316 #if defined(OCEAN_COMPILER_CLANG) || defined(OCEAN_COMPILER_MSC)
317 #error Invalid compiler configuration.
318 #endif
319 #endif
320
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.
323 #endif
324#endif
325
326// Defines OCEAN_COMPILER_MSC if the Microsoft compiler is used
327#if defined(OCEAN_MSC_VERSION) && OCEAN_MSC_VERSION > 0
328
329 #if !defined(OCEAN_CLANG_VERSION) || OCEAN_CLANG_VERSION == 0
330 #if !defined(OCEAN_GCC_VERSION) || OCEAN_GCC_VERSION == 0
331 /// \cond DOXYGEN_DO_NOT_DOCUMENT
332 #define OCEAN_COMPILER_MSC 1
333 /// \endcond
334
335 #if defined(OCEAN_COMPILER_GCC) || defined(OCEAN_COMPILER_CLANG)
336 #error Invalid compiler configuration.
337 #endif
338 #endif
339 #endif
340#endif
341
342#if !defined(OCEAN_COMPILER_GCC) && !defined(OCEAN_COMPILER_CLANG) && !defined(OCEAN_COMPILER_MSC)
343 // we ensure that one of the compilers is defined
344 #error Unknown compiler, either GCC, Clang or the Microsoft compiler must be used.
345#endif
346
347
348#if !defined(OCEAN_POSIX_AVAILABLE)
349 // Clang on Windows uses standard library from MSVC.
350 #if defined(OCEAN_COMPILER_GCC) || (defined(OCEAN_COMPILER_CLANG) && !defined(_MSC_VER))
351 /// \cond DOXYGEN_DO_NOT_DOCUMENT
352 #define OCEAN_POSIX_AVAILABLE
353 /// \endcond
354 #endif
355#endif
356
357
358// Defines OCEAN_HARDWARE_SSE_VERSION for platforms supporting SSE instructions
359#ifndef OCEAN_HARDWARE_SSE_VERSION
360 #if defined(_MSC_VER) && !defined(__clang__)
361
362 #if defined(_M_IX86_FP) && _M_IX86_FP >= 1
363 #define OCEAN_HARDWARE_SSE_VERSION 41
364 #endif
365
366 // The 64 bit compiler (x64) provides SSE support by default
367 #if defined(_M_X64)
368 #define OCEAN_HARDWARE_SSE_VERSION 41
369 #endif
370
371 #elif defined(_MSC_VER) && defined(__clang__)
372
373 #if defined(__SSE4_1__)
374 #define OCEAN_HARDWARE_SSE_VERSION 41
375 #endif
376
377 #elif defined(__APPLE__)
378
379 #if defined(__SSE4_1__)
380 #define OCEAN_HARDWARE_SSE_VERSION 41
381 #endif
382
383 #elif defined(__linux__) && !defined(_ANDROID)
384
385 #if defined(__SSE4_1__)
386 #define OCEAN_HARDWARE_SSE_VERSION 41
387 #endif
388
389 #endif
390#endif
391
392#ifndef OCEAN_HARDWARE_SSE_VERSION
393 #define OCEAN_HARDWARE_SSE_VERSION 0
394#endif
395
396
397
398
399// Defines OCEAN_HARDWARE_AVX_VERSION for platforms supporting AVX instructions
400#if !defined(OCEAN_HARDWARE_AVX_VERSION) && OCEAN_HARDWARE_SSE_VERSION > 0
401 #if defined(_MSC_VER) || defined(__APPLE__) || (defined(__linux__) && !defined(_ANDROID))
402
403 #if defined(__AVX2__)
404 #define OCEAN_HARDWARE_AVX_VERSION 20
405 #elif defined(__AVX__)
406 #define OCEAN_HARDWARE_AVX_VERSION 10
407 #endif
408
409 #endif
410#endif
411
412#ifndef OCEAN_HARDWARE_AVX_VERSION
413 #define OCEAN_HARDWARE_AVX_VERSION 0
414#endif
415
416
417
418
419// Defines OCEAN_LITTLE_ENDIAN on platforms with little endian byte order, do not define it on big endian platforms
420#if defined(_WINDOWS) || defined(_ANDROID) || defined(__APPLE__) || defined(__linux__) || defined(__EMSCRIPTEN__)
421 #ifndef OCEAN_LITTLE_ENDIAN
422 #define OCEAN_LITTLE_ENDIAN
423 #endif
424#endif
425
426
427
428
429// Defines OCEAN_BASE_EXPORT for dll export and import.
430#if defined(_WINDOWS) && defined(OCEAN_RUNTIME_SHARED)
431 #ifdef USE_OCEAN_BASE_EXPORT
432 #define OCEAN_BASE_EXPORT __declspec(dllexport)
433 #else
434 #define OCEAN_BASE_EXPORT __declspec(dllimport)
435 #endif
436#else
437 #define OCEAN_BASE_EXPORT
438#endif
439
440
441
442
443// Defines OCEAN_REDIRECT_ASSERT_TO_MESSENGER on platforms not providing useful assert handling
444#if defined(_ANDROID)
445 //#define OCEAN_REDIRECT_ASSERT_TO_MESSENGER
446#endif
447
448// Defines the ocean_assert() macro
449//
450// The 'ocean_assert' or 'ocean_assert_accuracy' macro should be used instead of the standard C assert() directly.
451//
452// ocean_assert will be active as long as OCEAN_DEBUG is not defined
453// In case, OCEAN_DEBUG is not defined, the expression of the assert will disappear, so that compilers may come up with warnings regarding unused variables.
454//
455// Use 'ocean_assert' to ensure that a program state is correct e.g., ocean_assert(pointer != nullptr);
456// Use 'ocean_assert_accuracy' to ensure that the accuracy of a parameter is good enough for the following code
457#ifndef ocean_assert
458 #ifdef OCEAN_DEBUG
459
460 // Overwrites the assert for platforms not allowing for senseful debugging
461 #ifdef OCEAN_REDIRECT_ASSERT_TO_MESSENGER
462
463 /**
464 * Error message function for redirected asserts.
465 * @param file Source file in that the assert occurred
466 * @param line Number of the line in that the assert occurred
467 * @param message The message to be redirected
468 * @ingroup base
469 */
470 extern OCEAN_BASE_EXPORT void assertErrorMessage(const char* file, const int line, const char* message);
471
472 #define ocean_assert(e) ((bool(e) != true) ? Ocean::assertErrorMessage(__FILE__, __LINE__, #e) : ((void)0))
473
474 #else
475
476 #define ocean_assert(e) assert(e)
477
478 #endif
479 #else
480 #define ocean_assert(e) ((void)0)
481 #endif
482#endif
483
484// Defines the ocean_assert_accuracy() macro
485//
486// The 'ocean_assert' or 'ocean_assert_accuracy' macro should be used instead of the standard C assert() directly.
487//
488// ocean_assert_accuracy will be active as long as OCEAN_DEBUG is not defined
489// In case, OCEAN_DEBUG is not defined, the expression of the assert will disappear, so that compilers may come up with warnings regarding unused variables.
490//
491// Use 'ocean_assert' to ensure that a program state is correct e.g., ocean_assert(pointer != nullptr);
492// Use 'ocean_assert_accuracy' to ensure that the accuracy of a parameter is good enough for the following code
493#ifndef ocean_assert_accuracy
494 #ifdef OCEAN_DEBUG
495 #define ocean_assert_accuracy(e) if (bool(e) != true) std::cout << "ocean_assert_accuracy(" << #e << "): in file " << __FILE__ << ", line " << __LINE__ << std::endl
496 #else
497 #define ocean_assert_accuracy(e) ((void)0)
498 #endif
499#endif
500
501// Defines the ocean_assert_and_suppress_unused() macro
502//
503// ocean_assert_and_suppress_unused behaves like ocean_assert.
504// In addition, in case, OCEAN_DEBUG is not defined, ocean_assert_and_suppress_unused suppressed the warning of an unused variable.
505// Thus, ocean_assert_and_suppress_unused(expression, variable) does mainly `ocean_assert(expression), OCEAN_SUPPRESS_UNUSED_WARNING(variable)`
506#ifndef ocean_assert_and_suppress_unused
507 #ifdef OCEAN_DEBUG
508 #define ocean_assert_and_suppress_unused(expression, variable) ocean_assert(expression)
509 #else
510 #define ocean_assert_and_suppress_unused(expression, variable) ((void)(variable))
511 #endif
512#endif
513
514
515
516// Defines OCEAN_SUPPORT_RTTI state for compiler configurations supporting e.g., the usage of typeid.
517#ifndef OCEAN_SUPPORT_RTTI
518 #if defined(OCEAN_COMPILER_MSC)
519 #ifdef _CPPRTTI
520 #define OCEAN_SUPPORT_RTTI
521 #endif
522 #elif defined(OCEAN_COMPILER_GCC) && OCEAN_GCC_VERSION >= 40302
523 #ifdef __GXX_RTTI
524 #define OCEAN_SUPPORT_RTTI
525 #endif
526 #elif defined(OCEAN_COMPILER_CLANG) && OCEAN_CLANG_VERSION >= 20700
527 #if __has_feature(cxx_rtti)
528 #define OCEAN_SUPPORT_RTTI
529 #endif
530 #endif
531#endif // OCEAN_SUPPORT_RTTI
532
533
534
535
536// Defines OCEAN_SUPPORT_EXCEPTIONS state for compiler configurations supporting exceptions.
537#ifndef OCEAN_SUPPORT_EXCEPTIONS
538 #if defined(OCEAN_COMPILER_MSC)
539 #ifdef _CPPUNWIND
540 #define OCEAN_SUPPORT_EXCEPTIONS
541 #endif
542 #elif defined(OCEAN_COMPILER_GCC) && OCEAN_GCC_VERSION > 0
543 #if defined(__EXCEPTIONS) && __EXCEPTIONS
544 #define OCEAN_SUPPORT_EXCEPTIONS
545 #endif
546 #elif defined(OCEAN_COMPILER_CLANG) && OCEAN_CLANG_VERSION > 0
547 #if defined(__EXCEPTIONS) && __EXCEPTIONS && __has_feature(cxx_exceptions)
548 #define OCEAN_SUPPORT_EXCEPTIONS
549 #endif
550 #endif
551#endif // OCEAN_SUPPORT_EXCEPTIONS
552
553
554
555
556// Define OCEAN_COMPILETIME_WARNING_MISSING_IMPLEMENTATION to create compile time warnings for missing implementations
557// #define OCEAN_COMPILETIME_WARNING_MISSING_IMPLEMENTATION
558
559// Defines the OCEAN_WARNING_MISSING_IMPLEMENTATION state either creating a compile time warning or a runtime warning (an assert).
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!")
564 #else
565 #define OCEAN_WARNING_MISSING_IMPLEMENTATION _Pragma ("message \"Missing implementation\""); assert(false && "Missing implementation!")
566 #endif
567 #else
568 #define OCEAN_WARNING_MISSING_IMPLEMENTATION assert(false && "Missing implementation!")
569 #endif
570#endif // OCEAN_WARNING_MISSING_IMPLEMENTATION
571
572
573
574
575// Defines the OCEAN_SUPPRESS_UNUSED_WARNING state that allows to suppress warnings regarding unused variables.
576#ifndef OCEAN_SUPPRESS_UNUSED_WARNING
577 #define OCEAN_SUPPRESS_UNUSED_WARNING(e) ((void)e)
578#endif
579
580
581
582
583/**
584 * This function is a helper function returning false any time.
585 * @return False, any the time
586 * @tparam T Template parameter that can be used, however it does not have any impact
587 * @ingroup base
588 */
589template <typename T>
590inline constexpr bool oceanFalse()
591{
592 return false;
593}
594
595
596
597
598// Definition of OCEAN_PLATFORM_BUILD_XXX for individual platforms
599#if defined(_WINDOWS)
600
601 #define OCEAN_PLATFORM_BUILD_WINDOWS
602
603#elif defined(__APPLE__)
604
605 #define OCEAN_PLATFORM_BUILD_APPLE
606
607 #if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR == 1
608
609 #define OCEAN_PLATFORM_BUILD_APPLE_IOS_SIMULATOR
610
611 #elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE == 1
612
613 #define OCEAN_PLATFORM_BUILD_APPLE_IOS
614
615 #elif defined(TARGET_OS_MAC) && TARGET_OS_MAC == 1
616
617 #define OCEAN_PLATFORM_BUILD_APPLE_MACOS
618
619 #else
620
621 #error Missing implementation
622
623 #endif
624
625 #if defined(OCEAN_PLATFORM_BUILD_APPLE_IOS_SIMULATOR) || defined(OCEAN_PLATFORM_BUILD_APPLE_IOS)
626
627 #define OCEAN_PLATFORM_BUILD_APPLE_IOS_ANY
628
629 #endif
630
631#elif defined(_ANDROID)
632
633 #define OCEAN_PLATFORM_BUILD_ANDROID
634
635#elif defined(__linux__) || defined(__EMSCRIPTEN__)
636
637 #define OCEAN_PLATFORM_BUILD_LINUX
638
639#else
640
641 #error Missing implementation
642
643#endif
644
645#if defined(OCEAN_PLATFORM_BUILD_ANDROID) || defined(OCEAN_PLATFORM_BUILD_APPLE_IOS_ANY)
646
647 #define OCEAN_PLATFORM_BUILD_MOBILE
648
649#endif
650
651
652
653
654// The OCEAN_APPLY_IF_DEBUG allows to invoke an expression in debug builds.
655#ifndef OCEAN_APPLY_IF_DEBUG
656 #ifdef OCEAN_DEBUG
657 #define OCEAN_APPLY_IF_DEBUG(e) e
658 #else
659 #define OCEAN_APPLY_IF_DEBUG(e) {}
660 #endif
661#endif
662
663// The OCEAN_APPLY_IF_WINDOWS allows to invoke an expression on windows platforms only.
664#ifndef OCEAN_APPLY_IF_WINDOWS
665 #ifdef OCEAN_PLATFORM_BUILD_WINDOWS
666 #define OCEAN_APPLY_IF_WINDOWS(e) e
667 #else
668 #define OCEAN_APPLY_IF_WINDOWS(e) {}
669 #endif
670#endif
671
672// The OCEAN_APPLY_IF_APPLE allows to invoke an expression on apple platforms only.
673#ifndef OCEAN_APPLY_IF_APPLE
674 #ifdef OCEAN_PLATFORM_BUILD_APPLE
675 #define OCEAN_APPLY_IF_APPLE(e) e
676 #else
677 #define OCEAN_APPLY_IF_APPLE(e) {}
678 #endif
679#endif
680
681// The OCEAN_APPLY_IF_LINUX allows to invoke an expression on apple platforms only.
682#ifndef OCEAN_APPLY_IF_LINUX
683 #ifdef OCEAN_PLATFORM_BUILD_LINUX
684 #define OCEAN_APPLY_IF_LINUX(e) e
685 #else
686 #define OCEAN_APPLY_IF_LINUX(e) {}
687 #endif
688#endif
689
690// The OCEAN_APPLY_IF_ANDROID allows to invoke an expression on android platforms only.
691#ifndef OCEAN_APPLY_IF_ANDROID
692 #ifdef OCEAN_PLATFORM_BUILD_ANDROID
693 #define OCEAN_APPLY_IF_ANDROID(e) e
694 #else
695 #define OCEAN_APPLY_IF_ANDROID(e) {}
696 #endif
697#endif
698
699// The OCEAN_APPLY_IF_IPHONE allows to invoke an expression on iOS platforms only.
700#ifndef OCEAN_APPLY_IF_IPHONE
701 #if defined(OCEAN_PLATFORM_BUILD_APPLE_IOS) || defined(TARGET_IPHONE_SIMULATOR)
702 #define OCEAN_APPLY_IF_IPHONE(e) e
703 #else
704 #define OCEAN_APPLY_IF_IPHONE(e) {}
705 #endif
706#endif
707
708// The OCEAN_APPLY_IF_GCC allows to invoke an expression with GCC compilers only.
709#ifndef OCEAN_APPLY_IF_GCC
710 #if defined(OCEAN_GCC_VERSION) && OCEAN_GCC_VERSION > 0
711 #define OCEAN_APPLY_IF_GCC(e) e
712 #else
713 #define OCEAN_APPLY_IF_GCC(e) {}
714 #endif
715#endif
716
717// The OCEAN_APPLY_IF_SSE allows to invoke an expression if any valid SSE version is defined.
718#ifndef OCEAN_APPLY_IF_SSE
719 #if defined(OCEAN_HARDWARE_SSE_VERSION) && OCEAN_HARDWARE_SSE_VERSION > 0
720 #define OCEAN_APPLY_IF_SSE(e) e
721 #else
722 #define OCEAN_APPLY_IF_SSE(e) {}
723 #endif
724#endif
725
726// The OCEAN_APPLY_IF_AVX allows to invoke an expression if any valid AVX version is defined.
727#ifndef OCEAN_APPLY_IF_AVX
728 #if defined(OCEAN_HARDWARE_AVX_VERSION) && OCEAN_HARDWARE_AVX_VERSION > 0
729 #define OCEAN_APPLY_IF_AVX(e) e
730 #else
731 #define OCEAN_APPLY_IF_AVX(e) {}
732 #endif
733#endif
734
735// The OCEAN_APPLY_IF_NEON allows to invoke an expression if any valid NEON version is defined.
736#ifndef OCEAN_APPLY_IF_NEON
737 #if defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION > 0
738 #define OCEAN_APPLY_IF_NEON(e) e
739 #else
740 #define OCEAN_APPLY_IF_NEON(e) {}
741 #endif
742#endif
743
744
745
746
747
748// The OCEAN_FORCE_INLINE macro allows to overwrite the compiler's inline analysis and forces a function to be inlined in any situation, as long as supported by the compiler
749#ifndef OCEAN_FORCE_INLINE
750 #if defined(OCEAN_COMPILER_MSC)
751 #define OCEAN_FORCE_INLINE __forceinline
752 #elif defined(OCEAN_COMPILER_CLANG)
753 #if __has_attribute(always_inline)
754 #define OCEAN_FORCE_INLINE inline __attribute__((always_inline))
755 #else
756 #define OCEAN_FORCE_INLINE inline
757 #endif
758 #elif defined(OCEAN_COMPILER_GCC)
759 #define OCEAN_FORCE_INLINE inline __attribute__((always_inline))
760 #else
761 #define OCEAN_FORCE_INLINE inline
762 #endif
763#endif
764
765
766
767
768// The OCEAN_PREVENT_INLINE macro allows to overwrite the compiler's inline analysis and forces a function from being inlined in any situation, as long as supported by the compiler
769#ifndef OCEAN_PREVENT_INLINE
770 #if defined(OCEAN_COMPILER_MSC)
771 #define OCEAN_PREVENT_INLINE __declspec(noinline)
772 #elif defined(OCEAN_COMPILER_CLANG)
773 #if __has_attribute(noinline)
774 #define OCEAN_PREVENT_INLINE __attribute__((noinline))
775 #else
776 #define OCEAN_PREVENT_INLINE
777 #endif
778 #elif defined(OCEAN_COMPILER_GCC)
779 #define OCEAN_PREVENT_INLINE __attribute__((noinline))
780 #else
781 #define OCEAN_PREVENT_INLINE
782 #endif
783#endif
784
785
786
787
788// The OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION macro allows to disable loop optimizations in the subsequent loop
789#ifndef OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION
790 #if defined(OCEAN_COMPILER_MSC)
791 #define OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION _Pragma("loop(no_vector)")
792 #elif defined(OCEAN_COMPILER_CLANG)
793 #define OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION _Pragma("clang loop vectorize(disable) interleave(disable)")
794 #elif defined(OCEAN_COMPILER_GCC)
795 #define OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION _Pragma("GCC unroll 1")
796 #else
797 #define OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION
798 #endif
799#endif
800
801// The OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION_IF_NEON macro allows to disable loop optimizations in the subsequent loop in case NEON is supported
802#ifndef OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION_IF_NEON
803 #if defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION > 0
804 #define OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION_IF_NEON OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION
805 #else
806 #define OCEAN_DISABLE_SUBSEQUENT_LOOP_OPTIMIZATION_IF_NEON
807 #endif
808#endif
809
810
811
812
813// The OCEAN_ALIGN_DATA macro allows to force the alignment of data to a specified byte boundary
814#ifndef OCEAN_ALIGN_DATA
815 #if defined(OCEAN_COMPILER_MSC)
816 #define OCEAN_ALIGN_DATA(x) __declspec(align(x))
817 #else
818 #define OCEAN_ALIGN_DATA(x) __attribute__ ((aligned(x)))
819 #endif
820#endif
821
822
823
824
825
826#if (defined(DEBUG) || defined(OCEAN_DEBUG)) && defined(NDEBUG)
827 #error You cannot define both flags (DEBUG and NDEBUG) concurrently
828#endif
829
830#if defined(OCEAN_INTENSIVE_DEBUG) && (!defined(DEBUG) || !defined(OCEAN_DEBUG))
831 #error You cannot define OCEAN_INTENSIVE_DEBUG without defining DEBUG/OCEAN_DEBUG
832#endif
833
834
835
836
837#ifndef OCEAN_NDEBUG
838 #if !defined(OCEAN_DEBUG) || defined(NDEBUG)
839 #define OCEAN_NDEBUG
840 #endif
841#endif
842
843
844
845
846// The OCEAN_DISABLE_DOCUMENTATION_DIAGNOSTIC macro allows to disable Clang's code documentation diagnostic, must be balanced with a following usage of `OCEAN_RE_ENABLE_DOCUMENTATION_DIAGNOSTIC`
847#ifndef OCEAN_DISABLE_DOCUMENTATION_DIAGNOSTIC
848 #if defined(OCEAN_CLANG_VERSION) && OCEAN_CLANG_VERSION > 0
849 #define OCEAN_DISABLE_DOCUMENTATION_DIAGNOSTIC _Pragma("clang diagnostic push") \
850 _Pragma("clang diagnostic ignored \"-Wdocumentation\"")
851 #else
852 #define OCEAN_DISABLE_DOCUMENTATION_DIAGNOSTIC
853 #endif
854#endif
855
856// The OCEAN_RE_ENABLE_DOCUMENTATION_DIAGNOSTIC macro allows to re-enabled Clang's code documentation diagnostic, must be balanced with earlier usage of `OCEAN_DISABLE_DOCUMENTATION_DIAGNOSTIC`
857#ifndef OCEAN_RE_ENABLE_DOCUMENTATION_DIAGNOSTIC
858 #if defined(OCEAN_CLANG_VERSION) && OCEAN_CLANG_VERSION > 0
859 #define OCEAN_RE_ENABLE_DOCUMENTATION_DIAGNOSTIC _Pragma("clang diagnostic pop")
860 #else
861 #define OCEAN_RE_ENABLE_DOCUMENTATION_DIAGNOSTIC
862 #endif
863#endif
864
865
866
867
868// The OCEAN_PRINT_MACRO_VALUE macro allows to print a macro value at compile time, usage e.g., `OCEAN_PRINT_MACRO_VALUE("This is a version number: ", OCEAN_CLANG_VERSION)`
869#ifndef OCEAN_PRINT_MACRO_VALUE
870 #define OCEAN_PRINT_MACRO_VALUE_INTERNAL_INTERNAL(value) #value
871 #define OCEAN_PRINT_MACRO_VALUE_INTERNAL(value) OCEAN_PRINT_MACRO_VALUE_INTERNAL_INTERNAL(value)
872
873 #define OCEAN_PRAGMA_INTERNAL(value) _Pragma(#value)
874 #define OCEAN_PRAGMA(value) OCEAN_PRAGMA_INTERNAL(value)
875
876 #define OCEAN_PRINT_MACRO_VALUE(text, value) OCEAN_PRAGMA(message text OCEAN_PRINT_MACRO_VALUE_INTERNAL(value))
877#endif
878
879}
880
881#endif // META_OCEAN_BASE_BASE_H
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