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