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 | Copyright (C) 2011-2015 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 
36 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37 // declarations (without debug information)
38 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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() {} \
59  ClassNameNoDebug(#TemplateNameString); \
60 }
61 
62 
63 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
64 // declarations (with debug information)
65 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66 
67 //- Add typeName information from argument \a TypeNameString to a class.
68 // Also declares debug information.
69 #define ClassName(TypeNameString) \
70  ClassNameNoDebug(TypeNameString); \
71  static int debug
72 
73 //- Add typeName information from argument \a TypeNameString to a namespace.
74 // Also declares debug information.
75 #define NamespaceName(TypeNameString) \
76  NamespaceNameNoDebug(TypeNameString); \
77  extern int debug
78 
79 //- Add typeName information from argument \a TypeNameString to a
80 // template class. Also declares debug information.
81 #define TemplateName(TemplateNameString) \
82 class TemplateNameString##Name \
83 { \
84 public: \
85  TemplateNameString##Name() {} \
86  ClassName(#TemplateNameString); \
87 }
88 
89 
90 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91 // definitions (without debug information)
92 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93 
94 //- Define the typeName, with alternative lookup as \a Name
95 #define defineTypeNameWithName(Type, Name) \
96  const ::Foam::word Type::typeName(Name)
97 
98 //- Define the typeName
99 #define defineTypeName(Type) \
100  defineTypeNameWithName(Type, Type::typeName_())
101 
102 //- Define the typeName as \a Name for template classes
103 # define defineTemplateTypeNameWithName(Type, Name) \
104  template<> \
105  defineTypeNameWithName(Type, Name)
106 //- Define the typeName as \a Name for template sub-classes
107 # define defineTemplate2TypeNameWithName(Type, Name) \
108  template<> \
109  defineTypeNameWithName(Type, Name)
110 
111 //- Define the typeName for template classes, useful with typedefs
112 #define defineTemplateTypeName(Type) \
113  defineTemplateTypeNameWithName(Type, #Type)
114 
115 //- Define the typeName directly for template classes
116 #define defineNamedTemplateTypeName(Type) \
117  defineTemplateTypeNameWithName(Type, Type::typeName_())
118 
119 
120 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
121 // definitions (with debug information)
122 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123 
124 //- Define the typeName and debug information
125 #define defineTypeNameAndDebug(Type, DebugSwitch) \
126  defineTypeName(Type); \
127  defineDebugSwitch(Type, DebugSwitch)
128 
129 //- Define the typeName and debug information, lookup as \a Name
130 #define defineTemplateTypeNameAndDebugWithName(Type, Name, DebugSwitch) \
131  defineTemplateTypeNameWithName(Type, Name); \
132  defineTemplateDebugSwitchWithName(Type, Name, DebugSwitch)
133 
134 //- Define the typeName and debug information for templates, useful
135 // with typedefs
136 #define defineTemplateTypeNameAndDebug(Type, DebugSwitch) \
137  defineTemplateTypeNameAndDebugWithName(Type, #Type, DebugSwitch)
138 
139 //- Define the typeName and debug information for templates
140 #define defineNamedTemplateTypeNameAndDebug(Type, DebugSwitch) \
141  defineNamedTemplateTypeName(Type); \
142  defineNamedTemplateDebugSwitch(Type, DebugSwitch)
143 
144 // for templated sub-classes
145 
146 //- Define the typeName and debug information, lookup as \a Name
147 #define defineTemplate2TypeNameAndDebugWithName(Type, Name, DebugSwitch) \
148  defineTemplate2TypeNameWithName(Type, Name); \
149  defineTemplate2DebugSwitchWithName(Type, Name, DebugSwitch)
150 
151 //- Define the typeName and debug information for templates, useful
152 // with typedefs
153 #define defineTemplate2TypeNameAndDebug(Type, DebugSwitch) \
154  defineTemplate2TypeNameAndDebugWithName(Type, #Type, DebugSwitch)
155 
156 
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 
159 #endif
160 
161 // ************************************************************************* //
Macro definitions for debug switches.