1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 Foam::memberFunctionSelectionTables
28 Macros to enable the easy declaration of member function selection tables.
30 \*---------------------------------------------------------------------------*/
34 #ifndef memberFunctionSelectionTables_H
35 #define memberFunctionSelectionTables_H
37 #include "HashTable.H"
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 // declare a run-time selection:
45 #define declareMemberFunctionSelectionTable\
46 (returnType,baseType,memberFunction,argNames,argList,parList) \
48 /* Construct from argList function pointer type */ \
49 typedef returnType (*memberFunction##argNames##MemberFunctionPtr)argList; \
51 /* Construct from argList function table type */ \
53 <memberFunction##argNames##MemberFunctionPtr, word, string::hash> \
54 memberFunction##argNames##MemberFunctionTable; \
56 /* Construct from argList function pointer table pointer */ \
57 static memberFunction##argNames##MemberFunctionTable* \
58 memberFunction##argNames##MemberFunctionTablePtr_; \
60 /* Class to add constructor from argList to table */ \
61 template<class baseType##Type> \
62 class add##memberFunction##argNames##MemberFunctionToTable \
66 add##memberFunction##argNames##MemberFunctionToTable \
68 const word& lookup = baseType##Type::typeName \
71 construct##memberFunction##argNames##MemberFunctionTables(); \
72 memberFunction##argNames##MemberFunctionTablePtr_->insert \
75 baseType##Type::memberFunction \
79 ~add##memberFunction##argNames##MemberFunctionToTable() \
81 destroy##memberFunction##argNames##MemberFunctionTables(); \
85 /* Table memberFunction called from the table add function */ \
86 static void construct##memberFunction##argNames##MemberFunctionTables(); \
88 /* Table destructor called from the table add function destructor */ \
89 static void destroy##memberFunction##argNames##MemberFunctionTables()
94 #define defineMemberFunctionSelectionTableMemberFunction\
95 (baseType,memberFunction,argNames) \
97 /* Table memberFunction called from the table add function */ \
98 void baseType::construct##memberFunction##argNames##MemberFunctionTables()\
100 static bool constructed = false; \
104 baseType::memberFunction##argNames##MemberFunctionTablePtr_ \
105 = new baseType::memberFunction##argNames##MemberFunctionTable;\
107 constructed = true; \
114 #define defineMemberFunctionSelectionTableDestructor\
115 (baseType,memberFunction,argNames) \
117 /* Table destructor called from the table add function destructor */ \
118 void baseType::destroy##memberFunction##argNames##MemberFunctionTables() \
120 if (baseType::memberFunction##argNames##MemberFunctionTablePtr_) \
122 delete baseType::memberFunction##argNames##MemberFunctionTablePtr_;\
123 baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL;\
129 // create pointer to hash-table of functions
130 #define defineMemberFunctionSelectionTablePtr\
131 (baseType,memberFunction,argNames) \
133 /* Define the memberFunction table */ \
134 baseType::memberFunction##argNames##MemberFunctionTable* \
135 baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL
139 #define defineTemplateMemberFunctionSelectionTablePtr\
140 (baseType,memberFunction,argNames) \
142 /* Define the memberFunction table */ \
143 typename baseType::memberFunction##argNames##MemberFunctionTable* \
144 baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 // define run-time selection table
152 #define defineMemberFunctionSelectionTable\
153 (baseType,memberFunction,argNames) \
155 defineMemberFunctionSelectionTablePtr \
156 (baseType,memberFunction,argNames); \
157 defineMemberFunctionSelectionTableMemberFunction \
158 (baseType,memberFunction,argNames) \
159 defineMemberFunctionSelectionTableDestructor \
160 (baseType,memberFunction,argNames)
165 // define run-time selection table for template classes
166 // use when baseType doesn't need a template argument (eg, is a typedef)
167 #define defineTemplateMemberFunctionSelectionTable\
168 (baseType,memberFunction,argNames) \
171 defineMemberFunctionSelectionTablePtr \
172 (baseType,memberFunction,argNames); \
174 defineMemberFunctionSelectionTableMemberFunction \
175 (baseType,memberFunction,argNames) \
177 defineMemberFunctionSelectionTableDestructor \
178 (baseType,memberFunction,argNames)
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 // use when baseType requires the Targ template argument
186 #define defineTemplatedMemberFunctionSelectionTableMemberFunction\
187 (baseType,memberFunction,argNames,Targ) \
189 /* Table memberFunction called from the table add function */ \
190 void baseType<Targ>::construct##memberFunction##argNames##MemberFunctionTables()\
192 static bool constructed = false; \
196 baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_ \
197 = new baseType<Targ>::memberFunction##argNames##MemberFunctionTable;\
199 constructed = true; \
206 // use when baseType requires the Targ template argument
207 #define defineTemplatedMemberFunctionSelectionTableDestructor\
208 (baseType,memberFunction,argNames,Targ) \
210 /* Table destructor called from the table add function destructor */ \
211 void baseType<Targ>::destroy##memberFunction##argNames##MemberFunctionTables() \
213 if (baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_) \
215 delete baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_;\
216 baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_ = NULL;\
222 // create pointer to hash-table of functions
223 // use when baseType requires the Targ template argument
224 #define defineTemplatedMemberFunctionSelectionTablePtr\
225 (baseType,memberFunction,argNames,Targ) \
227 /* Define the memberFunction table */ \
228 baseType<Targ>::memberFunction##argNames##MemberFunctionTable* \
229 baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_ = NULL
234 // define run-time selection table for template classes
235 // use when baseType requires the Targ template argument
236 #define defineTemplatedMemberFunctionSelectionTable\
237 (baseType,memberFunction,argNames,Targ) \
240 defineTemplatedMemberFunctionSelectionTablePtr \
241 (baseType,memberFunction,argNames,Targ); \
243 defineTemplatedMemberFunctionSelectionTableMemberFunction \
244 (baseType,memberFunction,argNames,Targ) \
246 defineTemplatedMemberFunctionSelectionTableDestructor \
247 (baseType,memberFunction,argNames,Targ)
249 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
253 // ************************************************************************* //