HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImfNamespace.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_IMFNAMESPACE_H
7 #define INCLUDED_IMFNAMESPACE_H
8 
9 //
10 // The purpose of this file is to have all of the Imath symbols defined within
11 // the OPENEXR_IMF_INTERNAL_NAMESPACE namespace rather than the standard Imath
12 // namespace. Those symbols are made available to client code through the
13 // OPENEXR_IMF_NAMESPACE in addition to the OPENEXR_IMF_INTERNAL_NAMESPACE.
14 //
15 // To ensure source code compatibility, the OPENEXR_IMF_NAMESPACE defaults to
16 // Imath and then "using namespace OPENEXR_IMF_INTERNAL_NAMESPACE;" brings all
17 // of the declarations from the OPENEXR_IMF_INTERNAL_NAMESPACE into the
18 // OPENEXR_IMF_NAMESPACE.
19 // This means that client code can continue to use syntax like
20 // Imf::Header, but at link time it will resolve to a
21 // mangled symbol based on the OPENEXR_IMF_INTERNAL_NAMESPACE.
22 //
23 // As an example, if one needed to build against a newer version of Imath 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 Imath symbols and the newer ones. To do this, the
27 // following could be defined at build time:
28 //
29 // OPENEXR_IMF_INTERNAL_NAMESPACE = Imf_v2
30 //
31 // This means that declarations inside Imath headers look like this (after
32 // the preprocessor has done its work):
33 //
34 // namespace Imf_v2 {
35 // ...
36 // class declarations
37 // ...
38 // }
39 //
40 // namespace Imf {
41 // using namespace IMF_NAMESPACE_v2;
42 // }
43 //
44 
45 //
46 // Open Source version of this file pulls in the OpenEXRConfig.h file
47 // for the configure time options.
48 //
49 #include "OpenEXRConfig.h"
50 
51 #ifndef OPENEXR_IMF_NAMESPACE
52 # define OPENEXR_IMF_NAMESPACE Imf
53 #endif
54 
55 #ifndef OPENEXR_IMF_INTERNAL_NAMESPACE
56 # define OPENEXR_IMF_INTERNAL_NAMESPACE OPENEXR_IMF_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 // OPENEXR_IMF_INTERNAL_NAMESPACE (so it can be referenced) and then defines
63 // OPENEXR_IMF_NAMESPACE and pulls the internal symbols into the public
64 // namespace.
65 //
66 
68 {}
70 {
71 using namespace OPENEXR_IMF_INTERNAL_NAMESPACE;
72 }
73 
74 //
75 // There are identical pairs of HEADER/SOURCE ENTER/EXIT macros so that
76 // future extension to the namespace mechanism is possible without changing
77 // project source code.
78 //
79 
80 #define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER \
81  namespace OPENEXR_IMF_INTERNAL_NAMESPACE \
82  {
83 #define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT }
84 
85 #define OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER \
86  namespace OPENEXR_IMF_INTERNAL_NAMESPACE \
87  {
88 #define OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT }
89 
90 #endif /* INCLUDED_IMFNAMESPACE_H */
#define OPENEXR_IMF_INTERNAL_NAMESPACE
Definition: OpenEXRConfig.h:46
#define OPENEXR_IMF_NAMESPACE
Definition: OpenEXRConfig.h:53