ImfNamespace.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Copyright (c) Contributors to the OpenEXR Project.
  4. //
  5. #ifndef INCLUDED_IMFNAMESPACE_H
  6. #define INCLUDED_IMFNAMESPACE_H
  7. //
  8. // The purpose of this file is to have all of the Imath symbols defined within
  9. // the OPENEXR_IMF_INTERNAL_NAMESPACE namespace rather than the standard Imath
  10. // namespace. Those symbols are made available to client code through the
  11. // OPENEXR_IMF_NAMESPACE in addition to the OPENEXR_IMF_INTERNAL_NAMESPACE.
  12. //
  13. // To ensure source code compatibility, the OPENEXR_IMF_NAMESPACE defaults to
  14. // Imath and then "using namespace OPENEXR_IMF_INTERNAL_NAMESPACE;" brings all
  15. // of the declarations from the OPENEXR_IMF_INTERNAL_NAMESPACE into the
  16. // OPENEXR_IMF_NAMESPACE.
  17. // This means that client code can continue to use syntax like
  18. // Imf::Header, but at link time it will resolve to a
  19. // mangled symbol based on the OPENEXR_IMF_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. // OPENEXR_IMF_INTERNAL_NAMESPACE = Imf_v2
  28. //
  29. // This means that declarations inside Imath headers look like this (after
  30. // the preprocessor has done its work):
  31. //
  32. // namespace Imf_v2 {
  33. // ...
  34. // class declarations
  35. // ...
  36. // }
  37. //
  38. // namespace Imf {
  39. // using namespace IMF_NAMESPACE_v2;
  40. // }
  41. //
  42. //
  43. // Open Source version of this file pulls in the OpenEXRConfig.h file
  44. // for the configure time options.
  45. //
  46. #include "OpenEXRConfig.h"
  47. #ifndef OPENEXR_IMF_NAMESPACE
  48. #define OPENEXR_IMF_NAMESPACE Imf
  49. #endif
  50. #ifndef OPENEXR_IMF_INTERNAL_NAMESPACE
  51. #define OPENEXR_IMF_INTERNAL_NAMESPACE OPENEXR_IMF_NAMESPACE
  52. #endif
  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. // OPENEXR_IMF_INTERNAL_NAMESPACE (so it can be referenced) and then defines
  57. // OPENEXR_IMF_NAMESPACE and pulls the internal symbols into the public
  58. // namespace.
  59. //
  60. namespace OPENEXR_IMF_INTERNAL_NAMESPACE {}
  61. namespace OPENEXR_IMF_NAMESPACE {
  62. using namespace OPENEXR_IMF_INTERNAL_NAMESPACE;
  63. }
  64. //
  65. // There are identical pairs of HEADER/SOURCE ENTER/EXIT macros so that
  66. // future extension to the namespace mechanism is possible without changing
  67. // project source code.
  68. //
  69. #define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER namespace OPENEXR_IMF_INTERNAL_NAMESPACE {
  70. #define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT }
  71. #define OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER namespace OPENEXR_IMF_INTERNAL_NAMESPACE {
  72. #define OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT }
  73. #endif /* INCLUDED_IMFNAMESPACE_H */