FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/word.H>
33 #include <OpenFOAM/debug.H>
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38 // declarations (without debug information)
39 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40 
41 
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
47 
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
53 
54 //- Add typeName information from argument @a TemplateNameString to a template class.
55 // Without debug information.
56 #define TemplateNameNoDebug(TemplateNameString) \
57 class TemplateNameString##Name \
58 { \
59 public: \
60  TemplateNameString##Name() {} \
61  ClassNameNoDebug(#TemplateNameString); \
62 }
63 
64 
65 
66 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67 // declarations (with debug information)
68 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69 
70 
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
76 
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
82 
83 //- Add typeName information from argument @a TypeNameString to a template class.
84 // Also declares debug information.
85 #define TemplateName(TemplateNameString) \
86 class TemplateNameString##Name \
87 { \
88 public: \
89  TemplateNameString##Name() {} \
90  ClassName(#TemplateNameString); \
91 }
92 
93 
94 
95 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96 // definitions (without debug information)
97 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
98 
99 
100 //- Define the typeName, with alternative lookup as @a Name
101 #define defineTypeNameWithName(Type, Name) \
102  const ::Foam::word Type::typeName(Name)
103 
104 //- Define the typeName
105 #define defineTypeName(Type) \
106  defineTypeNameWithName(Type, Type::typeName_())
107 
108 #ifdef __INTEL_COMPILER
109 //- Define the typeName as @a Name for template classes
110 # define defineTemplateTypeNameWithName(Type, Name) \
111  defineTypeNameWithName(Type, Name)
112 #else
113 //- Define the typeName as @a Name for template classes
114 # define defineTemplateTypeNameWithName(Type, Name) \
115  template<> \
116  defineTypeNameWithName(Type, Name)
117 #endif
118 
119 //- Define the typeName for template classes, useful with typedefs
120 #define defineTemplateTypeName(Type) \
121  defineTemplateTypeNameWithName(Type, #Type)
122 
123 //- Define the typeName directly for template classes
124 #define defineNamedTemplateTypeName(Type) \
125  defineTemplateTypeNameWithName(Type, Type::typeName_())
126 
127 
128 
129 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130 // definitions (debug information only)
131 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132 
133 
134 //- Define the debug information, lookup as @a Name
135 #define defineDebugSwitchWithName(Type, Name, DebugSwitch) \
136  int Type::debug(::Foam::debug::debugSwitch(Name, DebugSwitch))
137 
138 //- Define the debug information
139 #define defineDebugSwitch(Type, DebugSwitch) \
140  defineDebugSwitchWithName(Type, Type::typeName_(), DebugSwitch)
141 
142 #ifdef __INTEL_COMPILER
143 //- Define the debug information for templates, lookup as @a Name
144 # define defineTemplateDebugSwitchWithName(Type, Name, DebugSwitch) \
145  defineDebugSwitchWithName(Type, Name, DebugSwitch)
146 #else
147 //- Define the debug information for templates, lookup as @a Name
148 # define defineTemplateDebugSwitchWithName(Type, Name, DebugSwitch) \
149  template<> \
150  defineDebugSwitchWithName(Type, Name, DebugSwitch)
151 #endif
152 
153 //- Define the debug information for templates
154 // Useful with typedefs
155 #define defineTemplateDebugSwitch(Type, DebugSwitch) \
156  defineTemplateDebugSwitchWithName(Type, #Type, DebugSwitch)
157 
158 //- Define the debug information directly for templates
159 #define defineNamedTemplateDebugSwitch(Type, DebugSwitch) \
160  defineTemplateDebugSwitchWithName(Type, Type::typeName_(), DebugSwitch)
161 
162 
163 
164 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
165 // definitions (with debug information)
166 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
167 
168 
169 //- Define the typeName and debug information
170 #define defineTypeNameAndDebug(Type, DebugSwitch) \
171  defineTypeName(Type); \
172  defineDebugSwitch(Type, DebugSwitch)
173 
174 //- Define the typeName and debug information, lookup as @a Name
175 #define defineTemplateTypeNameAndDebugWithName(Type, Name, DebugSwitch) \
176  defineTemplateTypeNameWithName(Type, Name); \
177  defineTemplateDebugSwitchWithName(Type, Name, DebugSwitch)
178 
179 //- Define the typeName and debug information for templates, useful with typedefs
180 #define defineTemplateTypeNameAndDebug(Type, DebugSwitch) \
181  defineTemplateTypeNameAndDebugWithName(Type, #Type, DebugSwitch)
182 
183 //- Define the typeName and debug information for templates
184 #define defineNamedTemplateTypeNameAndDebug(Type, DebugSwitch) \
185  defineNamedTemplateTypeName(Type); \
186  defineNamedTemplateDebugSwitch(Type, DebugSwitch)
187 
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 #endif
192 
193 // ************************ vim: set sw=4 sts=4 et: ************************ //