memberFunctionSelectionTables.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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2019-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Description
28 Macros to ease declaration of member function selection tables.
29
30Note
31 Uses macros from runTimeSelectionTables.H
32
33\*---------------------------------------------------------------------------*/
34
35#ifndef Foam_memberFunctionSelectionTables_H
36#define Foam_memberFunctionSelectionTables_H
37
39
40// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41
42//
43// Declaration Macros
44//
45
46//- Declare a run-time member-function selection (variables and adder classes)
47#define declareMemberFunctionSelectionTable\
48(returnType,baseType,funcName,argNames,argList,parListUnused) \
49 \
50 declareRunTimeSelectionTableBase( \
51 returnType, funcName##argNames##MemberFunction, argList); \
52 \
53 /* Helper to add funcName to table */ \
54 template<class baseType##Type> \
55 struct add##funcName##argNames##MemberFunctionToTable \
56 { \
57 explicit add##funcName##argNames##MemberFunctionToTable \
58 ( \
59 const ::Foam::word& k = baseType##Type::typeName \
60 ) \
61 { \
62 funcName##argNames##MemberFunctionTablePtr_construct(true); \
63 if \
64 ( \
65 !funcName##argNames##MemberFunctionTablePtr_ \
66 ->insert(k, baseType##Type::funcName) \
67 ) \
68 { \
69 std::cerr \
70 << "Duplicate entry " << k << " in member table " \
71 << #baseType << std::endl; \
72 ::Foam::error::safePrintStack(std::cerr); \
73 } \
74 } \
75 \
76 ~add##funcName##argNames##MemberFunctionToTable() \
77 { \
78 funcName##argNames##MemberFunctionTablePtr_construct(false); \
79 } \
80 \
81 add##funcName##argNames##MemberFunctionToTable \
82 (const add##funcName##argNames##MemberFunctionToTable&) \
83 = delete; \
84 void operator= \
85 (const add##funcName##argNames##MemberFunctionToTable&) \
86 = delete; \
87 }; \
88 \
89 /* Helper to add funcName to table */ \
90 template<class baseType##Type> \
91 struct addRemovable##funcName##argNames##MemberFunctionToTable \
92 { \
93 const ::Foam::word name; /* Retain name for later removal */ \
94 \
95 explicit addRemovable##funcName##argNames##MemberFunctionToTable \
96 ( \
97 const ::Foam::word& k = baseType##Type::typeName \
98 ) \
99 : \
100 name(k) \
101 { \
102 funcName##argNames##MemberFunctionTablePtr_construct(true); \
103 funcName##argNames##MemberFunctionTablePtr_ \
104 ->set(k, baseType##Type::funcName); \
105 } \
106 \
107 ~addRemovable##funcName##argNames##MemberFunctionToTable() \
108 { \
109 if (funcName##argNames##MemberFunctionTablePtr_) \
110 { \
111 funcName##argNames##MemberFunctionTablePtr_->erase(name); \
112 } \
113 } \
114 \
115 addRemovable##funcName##argNames##MemberFunctionToTable \
116 (const addRemovable##funcName##argNames##MemberFunctionToTable&) \
117 = delete; \
118 void operator= \
119 (const addRemovable##funcName##argNames##MemberFunctionToTable&) \
120 = delete; \
121 }; \
122 \
123 /* Helper to add alias for funcName to table */ \
124 template<class baseType##Type> \
125 struct addAlias##funcName##argNames##MemberFunctionToTable \
126 { \
127 explicit addAlias##funcName##argNames##MemberFunctionToTable \
128 ( \
129 const ::Foam::word& k, \
130 const ::Foam::word& alias, \
131 const int ver \
132 ) \
133 { \
134 funcName##argNames##MemberFunctionCompatTable() \
135 .set(alias, std::pair<::Foam::word,int>(k,ver)); \
136 } \
137 };
138
139
140// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141
142//
143// Definition Macros
144//
145
146//- Define run-time selection table
147#define defineMemberFunctionSelectionTable(baseType,funcName,argNames) \
148 \
149 defineRunTimeSelectionTableBase( \
150 baseType,baseType::funcName##argNames##MemberFunction,)
151
152
153//- Define run-time selection table for template classes
154// use when baseType doesn't need a template argument (eg, is a typedef)
155#define defineTemplateMemberFunctionSelectionTable(baseType,funcName,argNames) \
156 \
157 defineRunTimeSelectionTableBase( \
158 baseType,baseType::funcName##argNames##MemberFunction,template<>)
159
160
161//- Define run-time selection table for template classes
162// use when baseType requires the Targ template argument
163#define defineTemplatedMemberFunctionSelectionTable\
164(baseType,funcName,argNames,Targ) \
165 \
166 defineRunTimeSelectionTableBase( \
167 baseType,baseType<Targ>::funcName##argNames##MemberFunction,template<>)
168
169
170// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171
172#endif
173
174// ************************************************************************* //
#define defineTemplateMemberFunctionSelectionTable(baseType, funcName, argNames)
Define run-time selection table for template classes.
Macros to ease declaration of run-time selection tables.