IexNamespace.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Copyright (c) Contributors to the OpenEXR Project.
  4. //
  5. #ifndef INCLUDED_IEXNAMESPACE_H
  6. #define INCLUDED_IEXNAMESPACE_H
  7. //
  8. // The purpose of this file is to make it possible to specify an
  9. // IEX_INTERNAL_NAMESPACE as a preprocessor definition and have all of the
  10. // Iex symbols defined within that namespace rather than the standard
  11. // Iex namespace. Those symbols are made available to client code through
  12. // the IEX_NAMESPACE in addition to the IEX_INTERNAL_NAMESPACE.
  13. //
  14. // To ensure source code compatibility, the IEX_NAMESPACE defaults to Iex
  15. // and then "using namespace IEX_INTERNAL_NAMESPACE;" brings all of the
  16. // declarations from the IEX_INTERNAL_NAMESPACE into the IEX_NAMESPACE. This
  17. // means that client code can continue to use syntax like Iex::BaseExc, but
  18. // at link time it will resolve to a mangled symbol based on the
  19. // IEX_INTERNAL_NAMESPACE.
  20. //
  21. // As an example, if one needed to build against a newer version of Iex 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 Iex symbols and the newer ones. To do this, the
  25. // following could be defined at build time:
  26. //
  27. // IEX_INTERNAL_NAMESPACE = Iex_v2
  28. //
  29. // This means that declarations inside Iex headers look like this (after the
  30. // preprocessor has done its work):
  31. //
  32. // namespace Iex_v2 {
  33. // ...
  34. // class declarations
  35. // ...
  36. // }
  37. //
  38. // namespace Iex {
  39. // using namespace Iex_v2;
  40. // }
  41. //
  42. //
  43. // Open Source version of this file pulls in the IexConfig.h file
  44. // for the configure time options.
  45. //
  46. #include "IexConfig.h"
  47. #ifndef IEX_NAMESPACE
  48. #define IEX_NAMESPACE Iex
  49. #endif
  50. #ifndef IEX_INTERNAL_NAMESPACE
  51. #define IEX_INTERNAL_NAMESPACE IEX_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. // IEX_INTERNAL_NAMESPACE (so it can be referenced) and then defines
  57. // IEX_NAMESPACE and pulls the internal symbols into the public namespace.
  58. //
  59. namespace IEX_INTERNAL_NAMESPACE {}
  60. namespace IEX_NAMESPACE {
  61. using namespace IEX_INTERNAL_NAMESPACE;
  62. }
  63. //
  64. // There are identical pairs of HEADER/SOURCE ENTER/EXIT macros so that
  65. // future extension to the namespace mechanism is possible without changing
  66. // project source code.
  67. //
  68. #define IEX_INTERNAL_NAMESPACE_HEADER_ENTER namespace IEX_INTERNAL_NAMESPACE {
  69. #define IEX_INTERNAL_NAMESPACE_HEADER_EXIT }
  70. #define IEX_INTERNAL_NAMESPACE_SOURCE_ENTER namespace IEX_INTERNAL_NAMESPACE {
  71. #define IEX_INTERNAL_NAMESPACE_SOURCE_EXIT }
  72. #endif // INCLUDED_IEXNAMESPACE_H