IlmThreadNamespace.h 2.9 KB

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