| 1 | // |
| 2 | // SPDX-License-Identifier: BSD-3-Clause |
| 3 | // Copyright Contributors to the OpenEXR Project. |
| 4 | // |
| 5 | |
| 6 | // |
| 7 | // The Imath library namespace |
| 8 | // |
| 9 | // The purpose of this file is to make it possible to specify an |
| 10 | // IMATH_INTERNAL_NAMESPACE as a preprocessor definition and have all of the |
| 11 | // Imath symbols defined within that namespace rather than the standard |
| 12 | // Imath namespace. Those symbols are made available to client code through |
| 13 | // the IMATH_NAMESPACE in addition to the IMATH_INTERNAL_NAMESPACE. |
| 14 | // |
| 15 | // To ensure source code compatibility, the IMATH_NAMESPACE defaults to Imath |
| 16 | // and then "using namespace IMATH_INTERNAL_NAMESPACE;" brings all of the |
| 17 | // declarations from the IMATH_INTERNAL_NAMESPACE into the IMATH_NAMESPACE. |
| 18 | // This means that client code can continue to use syntax like Imath::V3f, |
| 19 | // but at link time it will resolve to a mangled symbol based on the |
| 20 | // IMATH_INTERNAL_NAMESPACE. |
| 21 | // |
| 22 | // As an example, if one needed to build against a newer version of Imath and |
| 23 | // have it run alongside an older version in the same application, it is now |
| 24 | // possible to use an internal namespace to prevent collisions between the |
| 25 | // older versions of Imath symbols and the newer ones. To do this, the |
| 26 | // following could be defined at build time: |
| 27 | // |
| 28 | // IMATH_INTERNAL_NAMESPACE = Imath_v2 |
| 29 | // |
| 30 | // This means that declarations inside Imath headers look like this (after |
| 31 | // the preprocessor has done its work): |
| 32 | // |
| 33 | // namespace Imath_v2 { |
| 34 | // ... |
| 35 | // class declarations |
| 36 | // ... |
| 37 | // } |
| 38 | // |
| 39 | // namespace Imath { |
| 40 | // using namespace Imath_v2; |
| 41 | // } |
| 42 | // |
| 43 | |
| 44 | #ifndef INCLUDED_IMATHNAMESPACE_H |
| 45 | #define INCLUDED_IMATHNAMESPACE_H |
| 46 | |
| 47 | /// @cond Doxygen_Suppress |
| 48 | |
| 49 | #include "ImathConfig.h" |
| 50 | |
| 51 | #ifndef IMATH_NAMESPACE |
| 52 | # define IMATH_NAMESPACE Imath |
| 53 | #endif |
| 54 | |
| 55 | #ifndef IMATH_INTERNAL_NAMESPACE |
| 56 | # define IMATH_INTERNAL_NAMESPACE IMATH_NAMESPACE |
| 57 | #endif |
| 58 | |
| 59 | #ifdef __cplusplus |
| 60 | |
| 61 | // |
| 62 | // We need to be sure that we import the internal namespace into the public one. |
| 63 | // To do this, we use the small bit of code below which initially defines |
| 64 | // IMATH_INTERNAL_NAMESPACE (so it can be referenced) and then defines |
| 65 | // IMATH_NAMESPACE and pulls the internal symbols into the public |
| 66 | // namespace. |
| 67 | // |
| 68 | |
| 69 | namespace IMATH_INTERNAL_NAMESPACE |
| 70 | {} |
| 71 | namespace IMATH_NAMESPACE |
| 72 | { |
| 73 | using namespace IMATH_INTERNAL_NAMESPACE; |
| 74 | } |
| 75 | |
| 76 | // |
| 77 | // There are identical pairs of HEADER/SOURCE ENTER/EXIT macros so that |
| 78 | // future extension to the namespace mechanism is possible without changing |
| 79 | // project source code. |
| 80 | // |
| 81 | |
| 82 | #define \ |
| 83 | namespace IMATH_INTERNAL_NAMESPACE \ |
| 84 | { |
| 85 | #define } |
| 86 | |
| 87 | #define IMATH_INTERNAL_NAMESPACE_SOURCE_ENTER \ |
| 88 | namespace IMATH_INTERNAL_NAMESPACE \ |
| 89 | { |
| 90 | #define IMATH_INTERNAL_NAMESPACE_SOURCE_EXIT } |
| 91 | |
| 92 | #endif // __cplusplus |
| 93 | |
| 94 | /// @endcond |
| 95 | |
| 96 | #endif /* INCLUDED_IMATHNAMESPACE_H */ |
| 97 | |