1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Foam::memberFunctionSelectionTables
29 Macros to enable the easy declaration of member function selection tables.
31 \*---------------------------------------------------------------------------*/
35 #ifndef memberFunctionSelectionTables_H
36 #define memberFunctionSelectionTables_H
38 #include "HashTable.H"
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 // declare a run-time selection:
46 #define declareMemberFunctionSelectionTable\
47 (returnType,baseType,memberFunction,argNames,argList,parList) \
49 /* Construct from argList function pointer type */ \
50 typedef returnType (*memberFunction##argNames##MemberFunctionPtr)argList; \
52 /* Construct from argList function table type */ \
54 <memberFunction##argNames##MemberFunctionPtr, word, string::hash> \
55 memberFunction##argNames##MemberFunctionTable; \
57 /* Construct from argList function pointer table pointer */ \
58 static memberFunction##argNames##MemberFunctionTable* \
59 memberFunction##argNames##MemberFunctionTablePtr_; \
61 /* Class to add constructor from argList to table */ \
62 template<class baseType##Type> \
63 class add##memberFunction##argNames##MemberFunctionToTable \
67 add##memberFunction##argNames##MemberFunctionToTable \
69 const word& lookup = baseType##Type::typeName \
72 construct##memberFunction##argNames##MemberFunctionTables(); \
73 memberFunction##argNames##MemberFunctionTablePtr_->insert \
76 baseType##Type::memberFunction \
80 ~add##memberFunction##argNames##MemberFunctionToTable() \
82 destroy##memberFunction##argNames##MemberFunctionTables(); \
86 /* Table memberFunction called from the table add function */ \
87 static void construct##memberFunction##argNames##MemberFunctionTables(); \
89 /* Table destructor called from the table add function destructor */ \
90 static void destroy##memberFunction##argNames##MemberFunctionTables()
95 #define defineMemberFunctionSelectionTableMemberFunction\
96 (baseType,memberFunction,argNames) \
98 /* Table memberFunction called from the table add function */ \
99 void baseType::construct##memberFunction##argNames##MemberFunctionTables()\
101 static bool constructed = false; \
105 baseType::memberFunction##argNames##MemberFunctionTablePtr_ \
106 = new baseType::memberFunction##argNames##MemberFunctionTable;\
108 constructed = true; \
115 #define defineMemberFunctionSelectionTableDestructor\
116 (baseType,memberFunction,argNames) \
118 /* Table destructor called from the table add function destructor */ \
119 void baseType::destroy##memberFunction##argNames##MemberFunctionTables() \
121 if (baseType::memberFunction##argNames##MemberFunctionTablePtr_) \
123 delete baseType::memberFunction##argNames##MemberFunctionTablePtr_;\
124 baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL;\
130 // create pointer to hash-table of functions
131 #define defineMemberFunctionSelectionTablePtr\
132 (baseType,memberFunction,argNames) \
134 /* Define the memberFunction table */ \
135 baseType::memberFunction##argNames##MemberFunctionTable* \
136 baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL
140 #define defineTemplateMemberFunctionSelectionTablePtr\
141 (baseType,memberFunction,argNames) \
143 /* Define the memberFunction table */ \
144 typename baseType::memberFunction##argNames##MemberFunctionTable* \
145 baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 // define run-time selection table
153 #define defineMemberFunctionSelectionTable\
154 (baseType,memberFunction,argNames) \
156 defineMemberFunctionSelectionTablePtr \
157 (baseType,memberFunction,argNames); \
158 defineMemberFunctionSelectionTableMemberFunction \
159 (baseType,memberFunction,argNames) \
160 defineMemberFunctionSelectionTableDestructor \
161 (baseType,memberFunction,argNames)
166 // define run-time selection table for template classes
167 // use when baseType doesn't need a template argument (eg, is a typedef)
168 #define defineTemplateMemberFunctionSelectionTable\
169 (baseType,memberFunction,argNames) \
172 defineMemberFunctionSelectionTablePtr \
173 (baseType,memberFunction,argNames); \
175 defineMemberFunctionSelectionTableMemberFunction \
176 (baseType,memberFunction,argNames) \
178 defineMemberFunctionSelectionTableDestructor \
179 (baseType,memberFunction,argNames)
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 // use when baseType requires the Targ template argument
187 #define defineTemplatedMemberFunctionSelectionTableMemberFunction\
188 (baseType,memberFunction,argNames,Targ) \
190 /* Table memberFunction called from the table add function */ \
191 void baseType<Targ>::construct##memberFunction##argNames##MemberFunctionTables()\
193 static bool constructed = false; \
197 baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_ \
198 = new baseType<Targ>::memberFunction##argNames##MemberFunctionTable;\
200 constructed = true; \
207 // use when baseType requires the Targ template argument
208 #define defineTemplatedMemberFunctionSelectionTableDestructor\
209 (baseType,memberFunction,argNames,Targ) \
211 /* Table destructor called from the table add function destructor */ \
212 void baseType<Targ>::destroy##memberFunction##argNames##MemberFunctionTables() \
214 if (baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_) \
216 delete baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_;\
217 baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_ = NULL;\
223 // create pointer to hash-table of functions
224 // use when baseType requires the Targ template argument
225 #define defineTemplatedMemberFunctionSelectionTablePtr\
226 (baseType,memberFunction,argNames,Targ) \
228 /* Define the memberFunction table */ \
229 baseType<Targ>::memberFunction##argNames##MemberFunctionTable* \
230 baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_ = NULL
235 // define run-time selection table for template classes
236 // use when baseType requires the Targ template argument
237 #define defineTemplatedMemberFunctionSelectionTable\
238 (baseType,memberFunction,argNames,Targ) \
241 defineTemplatedMemberFunctionSelectionTablePtr \
242 (baseType,memberFunction,argNames,Targ); \
244 defineTemplatedMemberFunctionSelectionTableMemberFunction \
245 (baseType,memberFunction,argNames,Targ) \
247 defineTemplatedMemberFunctionSelectionTableDestructor \
248 (baseType,memberFunction,argNames,Targ)
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 // ************************************************************************* //