1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2010-2011 OpenCFD Ltd.
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
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
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/>.
25 Foam::staticMemberFunctionSelectionTables
28 Macros to enable the easy declaration of member function selection tables.
30 \*---------------------------------------------------------------------------*/
32 #ifndef staticMemberFunctionSelectionTables_H
33 #define staticMemberFunctionSelectionTables_H
35 #include "memberFunctionSelectionTables.H"
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 // declare a run-time selection:
42 #define declareStaticMemberFunctionSelectionTable\
43 (returnType,baseType,memberFunction,argNames,argList,parList) \
45 /* Construct from argList function pointer type */ \
46 typedef returnType (*memberFunction##argNames##MemberFunctionPtr)argList; \
48 /* Construct from argList function table type */ \
50 <memberFunction##argNames##MemberFunctionPtr, word, string::hash> \
51 memberFunction##argNames##MemberFunctionTable; \
53 /* Construct from argList function pointer table pointer */ \
54 static memberFunction##argNames##MemberFunctionTable* \
55 memberFunction##argNames##MemberFunctionTablePtr_; \
57 /* Table memberFunction called from the table add function */ \
58 static void construct##memberFunction##argNames##MemberFunctionTables(); \
60 /* Table destructor called from the table add function destructor */ \
61 static void destroy##memberFunction##argNames##MemberFunctionTables(); \
63 /* Class to add constructor from argList to table */ \
64 template<class baseType##Type> \
65 class add##memberFunction##argNames##StaticMemberFunctionToTable \
69 add##memberFunction##argNames##StaticMemberFunctionToTable \
72 memberFunction##argNames##MemberFunctionPtr function \
75 construct##memberFunction##argNames##MemberFunctionTables(); \
76 memberFunction##argNames##MemberFunctionTablePtr_->insert \
83 ~add##memberFunction##argNames##StaticMemberFunctionToTable() \
85 destroy##memberFunction##argNames##MemberFunctionTables(); \
91 // constructor/destructor aid
92 #define defineStaticMemberFunctionSelectionTableConstructDestruct\
93 (baseType,memberFunction,argNames) \
95 /* Table constructor called from the table add function constructor */ \
96 void baseType::construct##memberFunction##argNames##MemberFunctionTables()\
98 static bool constructed = false; \
101 constructed = true; \
102 baseType::memberFunction##argNames##MemberFunctionTablePtr_ \
103 = new baseType::memberFunction##argNames##MemberFunctionTable;\
107 /* Table destructor called from the table add function destructor */ \
108 void baseType::destroy##memberFunction##argNames##MemberFunctionTables() \
110 if (baseType::memberFunction##argNames##MemberFunctionTablePtr_) \
112 delete baseType::memberFunction##argNames##MemberFunctionTablePtr_;\
113 baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL;\
119 // create pointer to hash-table of functions
120 #define defineStaticMemberFunctionSelectionTablePtr\
121 (baseType,memberFunction,argNames) \
123 /* Define the memberFunction table */ \
124 baseType::memberFunction##argNames##MemberFunctionTable* \
125 baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL
128 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
132 // define run-time selection table
133 #define defineStaticMemberFunctionSelectionTable\
134 (baseType,memberFunction,argNames) \
136 defineStaticMemberFunctionSelectionTablePtr \
137 (baseType,memberFunction,argNames); \
138 defineStaticMemberFunctionSelectionTableConstructDestruct \
139 (baseType,memberFunction,argNames) \
141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 // ************************************************************************* //