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