1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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::globalFunctionSelectionTables
28 Macros to enable the easy declaration of global function selection tables.
30 \*---------------------------------------------------------------------------*/
32 #ifndef globalMemberFunctionSelectionTables_H
33 #define globalMemberFunctionSelectionTables_H
35 #include "memberFunctionSelectionTables.H"
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 // declare a run-time selection:
42 #define declareGlobalFunctionSelectionTable\
43 (returnType,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 extern memberFunction##argNames##MemberFunctionTable* \
55 memberFunction##argNames##MemberFunctionTablePtr_; \
57 /* Table memberFunction called from the table add function */ \
58 void construct##memberFunction##argNames##MemberFunctionTables(); \
60 /* Table destructor called from the table add function destructor */ \
61 void destroy##memberFunction##argNames##MemberFunctionTables(); \
63 /* Class to add constructor from argList to table */ \
64 class add##memberFunction##argNames##GlobalMemberFunctionToTable \
68 add##memberFunction##argNames##GlobalMemberFunctionToTable \
71 memberFunction##argNames##MemberFunctionPtr function \
74 construct##memberFunction##argNames##MemberFunctionTables(); \
75 memberFunction##argNames##MemberFunctionTablePtr_->insert \
82 ~add##memberFunction##argNames##GlobalMemberFunctionToTable() \
84 destroy##memberFunction##argNames##MemberFunctionTables(); \
90 // constructor/destructor aid
91 #define defineGlobalFunctionSelectionTableConstructDestruct\
92 (memberFunction,argNames) \
94 /* Table constructor called from the table add function */ \
95 void construct##memberFunction##argNames##MemberFunctionTables() \
97 static bool constructed = false; \
100 constructed = true; \
101 memberFunction##argNames##MemberFunctionTablePtr_ \
102 = new memberFunction##argNames##MemberFunctionTable; \
106 /* Table destructor called from the table add function destructor */ \
107 void destroy##memberFunction##argNames##MemberFunctionTables() \
109 if (memberFunction##argNames##MemberFunctionTablePtr_) \
111 delete memberFunction##argNames##MemberFunctionTablePtr_; \
112 memberFunction##argNames##MemberFunctionTablePtr_ = NULL; \
118 // create pointer to hash-table of functions
119 #define defineGlobalFunctionSelectionTablePtr\
120 (memberFunction,argNames) \
122 /* Define the memberFunction table */ \
123 memberFunction##argNames##MemberFunctionTable* \
124 memberFunction##argNames##MemberFunctionTablePtr_ = NULL
127 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 // define run-time selection table
132 #define defineGlobalFunctionSelectionTable\
133 (memberFunction,argNames) \
135 defineGlobalFunctionSelectionTablePtr \
136 (memberFunction,argNames); \
137 defineGlobalFunctionSelectionTableConstructDestruct \
138 (memberFunction,argNames)
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
144 // ************************************************************************* //