Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / OpenFOAM / db / typeInfo / className.H
blobf14cc6100c124809065acf8b1cfe2e1f6050ef65
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2011 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 Description
25     Macro definitions for declaring ClassName(), NamespaceName(), etc.
27 \*---------------------------------------------------------------------------*/
29 #ifndef className_H
30 #define className_H
32 #include "word.H"
33 #include "debug.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38 // declarations (without debug information)
39 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42 //- Add typeName information from argument \a TypeNameString to a class.
43 //  Without debug information
44 #define ClassNameNoDebug(TypeNameString)                                      \
45     static const char* typeName_() { return TypeNameString; }                 \
46     static const ::Foam::word typeName
48 //- Add typeName information from argument \a TypeNameString to a namespace.
49 //  Without debug information.
50 #define NamespaceNameNoDebug(TypeNameString)                                  \
51     inline const char* typeName_() { return TypeNameString; }                 \
52     extern const ::Foam::word typeName
54 //- Add typeName information from argument \a TemplateNameString to a
55 //  template class.  Without debug information.
56 #define TemplateNameNoDebug(TemplateNameString)                               \
57 class TemplateNameString##Name                                                \
58 {                                                                             \
59 public:                                                                       \
60     TemplateNameString##Name() {}                                             \
61     ClassNameNoDebug(#TemplateNameString);                                    \
66 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67 // declarations (with debug information)
68 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
71 //- Add typeName information from argument \a TypeNameString to a class.
72 //  Also declares debug information.
73 #define ClassName(TypeNameString)                                             \
74     ClassNameNoDebug(TypeNameString);                                         \
75     static int debug
77 //- Add typeName information from argument \a TypeNameString to a namespace.
78 //  Also declares debug information.
79 #define NamespaceName(TypeNameString)                                         \
80     NamespaceNameNoDebug(TypeNameString);                                     \
81     extern int debug
83 //- Add typeName information from argument \a TypeNameString to a
84 //  template class.  Also declares debug information.
85 #define TemplateName(TemplateNameString)                                      \
86 class TemplateNameString##Name                                                \
87 {                                                                             \
88 public:                                                                       \
89     TemplateNameString##Name() {}                                             \
90     ClassName(#TemplateNameString);                                           \
95 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96 // definitions (without debug information)
97 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100 //- Define the typeName, with alternative lookup as \a Name
101 #define defineTypeNameWithName(Type, Name)                                    \
102     const ::Foam::word Type::typeName(Name)
104 //- Define the typeName
105 #define defineTypeName(Type)                                                  \
106     defineTypeNameWithName(Type, Type::typeName_())
108 #ifdef __INTEL_COMPILER
109 //- Define the typeName as \a Name for template classes
110 # define defineTemplateTypeNameWithName(Type, Name)                           \
111     defineTypeNameWithName(Type, Name)
112 //- Define the typeName as \a Name for template sub-classes
113 # define defineTemplate2TypeNameWithName(Type, Name)                          \
114     defineTypeNameWithName(Type, Name)
115 #else
116 //- Define the typeName as \a Name for template classes
117 # define defineTemplateTypeNameWithName(Type, Name)                           \
118     template<>                                                                \
119     defineTypeNameWithName(Type, Name)
120 //- Define the typeName as \a Name for template sub-classes
121 # define defineTemplate2TypeNameWithName(Type, Name)                          \
122     template<>                                                                \
123     template<>                                                                \
124     defineTypeNameWithName(Type, Name)
125 #endif
127 //- Define the typeName for template classes, useful with typedefs
128 #define defineTemplateTypeName(Type)                                          \
129     defineTemplateTypeNameWithName(Type, #Type)
131 //- Define the typeName directly for template classes
132 #define defineNamedTemplateTypeName(Type)                                     \
133     defineTemplateTypeNameWithName(Type, Type::typeName_())
137 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
138 // definitions (debug information only)
139 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
142 //- Define the debug information, lookup as \a Name
143 #define defineDebugSwitchWithName(Type, Name, DebugSwitch)                    \
144     int Type::debug(::Foam::debug::debugSwitch(Name, DebugSwitch))
146 //- Define the debug information
147 #define defineDebugSwitch(Type, DebugSwitch)                                  \
148     defineDebugSwitchWithName(Type, Type::typeName_(), DebugSwitch)
150 #ifdef __INTEL_COMPILER
151 //- Define the debug information for templates, lookup as \a Name
152 # define defineTemplateDebugSwitchWithName(Type, Name, DebugSwitch)           \
153     defineDebugSwitchWithName(Type, Name, DebugSwitch)
154 //- Define the debug information for templates sub-classes, lookup as \a Name
155 # define defineTemplate2DebugSwitchWithName(Type, Name, DebugSwitch)          \
156     defineDebugSwitchWithName(Type, Name, DebugSwitch)
157 #else
158 //- Define the debug information for templates, lookup as \a Name
159 # define defineTemplateDebugSwitchWithName(Type, Name, DebugSwitch)           \
160     template<>                                                                \
161     defineDebugSwitchWithName(Type, Name, DebugSwitch)
162 //- Define the debug information for templates sub-classes, lookup as \a Name
163 # define defineTemplate2DebugSwitchWithName(Type, Name, DebugSwitch)          \
164     template<>                                                                \
165     template<>                                                                \
166     defineDebugSwitchWithName(Type, Name, DebugSwitch)
167 #endif
169 //- Define the debug information for templates
170 //  Useful with typedefs
171 #define defineTemplateDebugSwitch(Type, DebugSwitch)                          \
172     defineTemplateDebugSwitchWithName(Type, #Type, DebugSwitch)
174 //- Define the debug information directly for templates
175 #define defineNamedTemplateDebugSwitch(Type, DebugSwitch)                     \
176     defineTemplateDebugSwitchWithName(Type, Type::typeName_(), DebugSwitch)
179 // for templated sub-classes
181 //- Define the debug information for templates
182 //  Useful with typedefs
183 #define defineTemplate2DebugSwitch(Type, DebugSwitch)                         \
184     defineTemplate2DebugSwitchWithName(Type, #Type, DebugSwitch)
186 //- Define the debug information directly for templates
187 #define defineNamedTemplate2DebugSwitch(Type, DebugSwitch)                    \
188     defineTemplate2DebugSwitchWithName(Type, Type::typeName_(), DebugSwitch)
192 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
193 // definitions (with debug information)
194 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
197 //- Define the typeName and debug information
198 #define defineTypeNameAndDebug(Type, DebugSwitch)                             \
199     defineTypeName(Type);                                                     \
200     defineDebugSwitch(Type, DebugSwitch)
202 //- Define the typeName and debug information, lookup as \a Name
203 #define defineTemplateTypeNameAndDebugWithName(Type, Name, DebugSwitch)       \
204     defineTemplateTypeNameWithName(Type, Name);                               \
205     defineTemplateDebugSwitchWithName(Type, Name, DebugSwitch)
207 //- Define the typeName and debug information for templates, useful
208 //  with typedefs
209 #define defineTemplateTypeNameAndDebug(Type, DebugSwitch)                     \
210     defineTemplateTypeNameAndDebugWithName(Type, #Type, DebugSwitch)
212 //- Define the typeName and debug information for templates
213 #define defineNamedTemplateTypeNameAndDebug(Type, DebugSwitch)                \
214     defineNamedTemplateTypeName(Type);                                        \
215     defineNamedTemplateDebugSwitch(Type, DebugSwitch)
217 // for templated sub-classes
219 //- Define the typeName and debug information, lookup as \a Name
220 #define defineTemplate2TypeNameAndDebugWithName(Type, Name, DebugSwitch)      \
221     defineTemplate2TypeNameWithName(Type, Name);                              \
222     defineTemplate2DebugSwitchWithName(Type, Name, DebugSwitch)
224 //- Define the typeName and debug information for templates, useful
225 //  with typedefs
226 #define defineTemplate2TypeNameAndDebug(Type, DebugSwitch)                    \
227     defineTemplate2TypeNameAndDebugWithName(Type, #Type, DebugSwitch)
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
233 #endif
235 // ************************************************************************* //