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-2025 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 //- Add typeName information from argument a TypeNameString to a function class.
60 // Without debug information
61 #define FunctionNameNoDebug(TypeNameString) \
62  static const char* typeName_() { return TypeNameString; } \
63  static const ::Foam::functionName typeName
64 
65 
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67 // Declarations (with debug information)
68 
69 //- Add typeName information from argument a TypeNameString to a class.
70 // Also declares debug information.
71 #define ClassName(TypeNameString) \
72  ClassNameNoDebug(TypeNameString); \
73  static int debug
74 
75 //- Add typeName information from argument a TypeNameString to a namespace.
76 // Also declares debug information.
77 #define NamespaceName(TypeNameString) \
78  NamespaceNameNoDebug(TypeNameString); \
79  extern int debug
80 
81 //- Add typeName information from argument a TypeNameString to a
82 // template class. Also declares debug information.
83 #define TemplateName(TemplateNameString) \
84 class TemplateNameString##Name \
85 { \
86 public: \
87  TemplateNameString##Name() {} \
88  ClassName(#TemplateNameString); \
89 }
90 
91 //- Add typeName information from argument a TypeNameString to a class.
92 // Also declares debug information.
93 #define FunctionName(TypeNameString) \
94  FunctionNameNoDebug(TypeNameString); \
95  static int debug
96 
97 
98 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
99 // Definitions (without debug information)
100 
101 //- Define the typeName, with alternative lookup as a Name
102 #define defineTypeNameWithName(Type, Name) \
103  const ::Foam::word Type::typeName(Name)
104 
105 //- Define the typeName
106 #define defineTypeName(Type) \
107  defineTypeNameWithName(Type, Type::typeName_())
108 
109 //- Define the typeName as a Name for template classes
110 #define defineTemplateTypeNameWithName(Type, Name) \
111  template<> \
112  defineTypeNameWithName(Type, Name)
113 //- Define the typeName as a Name for template sub-classes
114 #define defineTemplate2TypeNameWithName(Type, Name) \
115  template<> \
116  defineTypeNameWithName(Type, Name)
117 
118 //- Define the typeName for template classes, useful with typedefs
119 #define defineTemplateTypeName(Type) \
120  defineTemplateTypeNameWithName(Type, #Type)
121 
122 //- Define the typeName directly for template classes
123 #define defineNamedTemplateTypeName(Type) \
124  defineTemplateTypeNameWithName(Type, Type::typeName_())
125 
126 //- Define the function typeName, with alternative lookup as a Name
127 #define defineFunctionNameWithName(Type, Name) \
128  const ::Foam::functionName Type::typeName(Name)
129 
130 //- Define the function typeName
131 #define defineFunctionTypeName(Type) \
132  defineFunctionNameWithName(Type, Type::typeName_())
133 
134 
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 // Definitions (with debug information)
137 
138 //- Define the typeName and debug information
139 #define defineTypeNameAndDebug(Type, DebugSwitch) \
140  defineTypeName(Type); \
141  defineDebugSwitch(Type, DebugSwitch)
142 
143 //- Define the typeName and debug information, lookup as a Name
144 #define defineTypeNameAndDebugWithName(Type, Name, DebugSwitch) \
145  defineTypeNameWithName(Type, Name); \
146  defineDebugSwitchWithName(Type, Name, DebugSwitch)
147 
148 //- Define the typeName and debug information, lookup as a Name
149 #define defineTemplateTypeNameAndDebugWithName(Type, Name, DebugSwitch) \
150  defineTemplateTypeNameWithName(Type, Name); \
151  defineTemplateDebugSwitchWithName(Type, Name, DebugSwitch)
152 
153 //- Define the typeName and debug information for templates, useful
154 // with typedefs
155 #define defineTemplateTypeNameAndDebug(Type, DebugSwitch) \
156  defineTemplateTypeNameAndDebugWithName(Type, #Type, DebugSwitch)
157 
158 //- Define the typeName and debug information for templates
159 #define defineNamedTemplateTypeNameAndDebug(Type, DebugSwitch) \
160  defineNamedTemplateTypeName(Type); \
161  defineNamedTemplateDebugSwitch(Type, DebugSwitch)
162 
163 //- Define the typeName and debug information
164 #define defineFunctionTypeNameAndDebug(Type, DebugSwitch) \
165  defineFunctionTypeName(Type); \
166  defineDebugSwitch(Type, DebugSwitch)
167 
168 
169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
170 // For templated sub-classes
171 
172 //- Define the typeName and debug information, lookup as a Name
173 #define defineTemplate2TypeNameAndDebugWithName(Type, Name, DebugSwitch) \
174  defineTemplate2TypeNameWithName(Type, Name); \
175  defineTemplate2DebugSwitchWithName(Type, Name, DebugSwitch)
176 
177 //- Define the typeName and debug information for templates, useful
178 // with typedefs
179 #define defineTemplate2TypeNameAndDebug(Type, DebugSwitch) \
180  defineTemplate2TypeNameAndDebugWithName(Type, #Type, DebugSwitch)
181 
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 #endif
186 
187 // ************************************************************************* //
Macro definitions for debug switches.