className.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Macro definitions for declaring ClassName(), NamespaceName(), etc.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #ifndef className_H
30 #define className_H
31 
32 #include "defineDebugSwitch.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 // Declarations (without debug information)
36 
37 //- Add typeName information from argument \a TypeNameString to a class.
38 // Without debug information
39 #define ClassNameNoDebug(TypeNameString) \
40  static const char* typeName_() { return TypeNameString; } \
41  static const ::Foam::word typeName
42 
43 //- Add typeName information from argument \a TypeNameString to a namespace.
44 // Without debug information.
45 #define NamespaceNameNoDebug(TypeNameString) \
46  inline const char* typeName_() { return TypeNameString; } \
47  extern const ::Foam::word typeName
48 
49 //- Add typeName information from argument \a TemplateNameString to a
50 // template class. Without debug information.
51 #define TemplateNameNoDebug(TemplateNameString) \
52 class TemplateNameString##Name \
53 { \
54 public: \
55  TemplateNameString##Name() {} \
56  ClassNameNoDebug(#TemplateNameString); \
57 }
58 
59 
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 // Declarations (with debug information)
62 
63 //- Add typeName information from argument \a TypeNameString to a class.
64 // Also declares debug information.
65 #define ClassName(TypeNameString) \
66  ClassNameNoDebug(TypeNameString); \
67  static int debug
68 
69 //- Add typeName information from argument \a TypeNameString to a namespace.
70 // Also declares debug information.
71 #define NamespaceName(TypeNameString) \
72  NamespaceNameNoDebug(TypeNameString); \
73  extern int debug
74 
75 //- Add typeName information from argument \a TypeNameString to a
76 // template class. Also declares debug information.
77 #define TemplateName(TemplateNameString) \
78 class TemplateNameString##Name \
79 { \
80 public: \
81  TemplateNameString##Name() {} \
82  ClassName(#TemplateNameString); \
83 }
84 
85 
86 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
87 // Definitions (without debug information)
88 
89 //- Define the typeName, with alternative lookup as \a Name
90 #define defineTypeNameWithName(Type, Name) \
91  const ::Foam::word Type::typeName(Name)
92 
93 //- Define the typeName
94 #define defineTypeName(Type) \
95  defineTypeNameWithName(Type, Type::typeName_())
96 
97 //- Define the typeName as \a Name for template classes
98 #define defineTemplateTypeNameWithName(Type, Name) \
99  template<> \
100  defineTypeNameWithName(Type, Name)
101 //- Define the typeName as \a Name for template sub-classes
102 #define defineTemplate2TypeNameWithName(Type, Name) \
103  template<> \
104  defineTypeNameWithName(Type, Name)
105 
106 //- Define the typeName for template classes, useful with typedefs
107 #define defineTemplateTypeName(Type) \
108  defineTemplateTypeNameWithName(Type, #Type)
109 
110 //- Define the typeName directly for template classes
111 #define defineNamedTemplateTypeName(Type) \
112  defineTemplateTypeNameWithName(Type, Type::typeName_())
113 
114 
115 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
116 // Definitions (with debug information)
117 
118 //- Define the typeName and debug information
119 #define defineTypeNameAndDebug(Type, DebugSwitch) \
120  defineTypeName(Type); \
121  defineDebugSwitch(Type, DebugSwitch)
122 
123 //- Define the typeName and debug information, lookup as \a Name
124 #define defineTemplateTypeNameAndDebugWithName(Type, Name, DebugSwitch) \
125  defineTemplateTypeNameWithName(Type, Name); \
126  defineTemplateDebugSwitchWithName(Type, Name, DebugSwitch)
127 
128 //- Define the typeName and debug information for templates, useful
129 // with typedefs
130 #define defineTemplateTypeNameAndDebug(Type, DebugSwitch) \
131  defineTemplateTypeNameAndDebugWithName(Type, #Type, DebugSwitch)
132 
133 //- Define the typeName and debug information for templates
134 #define defineNamedTemplateTypeNameAndDebug(Type, DebugSwitch) \
135  defineNamedTemplateTypeName(Type); \
136  defineNamedTemplateDebugSwitch(Type, DebugSwitch)
137 
138 
139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
140 // For templated sub-classes
141 
142 //- Define the typeName and debug information, lookup as \a Name
143 #define defineTemplate2TypeNameAndDebugWithName(Type, Name, DebugSwitch) \
144  defineTemplate2TypeNameWithName(Type, Name); \
145  defineTemplate2DebugSwitchWithName(Type, Name, DebugSwitch)
146 
147 //- Define the typeName and debug information for templates, useful
148 // with typedefs
149 #define defineTemplate2TypeNameAndDebug(Type, DebugSwitch) \
150  defineTemplate2TypeNameAndDebugWithName(Type, #Type, DebugSwitch)
151 
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 #endif
156 
157 // ************************************************************************* //
Macro definitions for debug switches.