ImathNamespace.h 3.0 KB

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