Report patch name instead of index in debug
[foam-extend-3.2.git] / src / foam / db / memberFunctionSelection / memberFunctionSelectionTables.H
blobad7d1b6d836c6266e36894afbd2ab557d375248e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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/>.
24 Class
25     Foam::memberFunctionSelectionTables
27 Description
28     Macros to enable the easy declaration of member function selection tables.
30 \*---------------------------------------------------------------------------*/
32 #include "token.H"
34 #ifndef memberFunctionSelectionTables_H
35 #define memberFunctionSelectionTables_H
37 #include "HashTable.H"
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 // external use:
43 // ~~~~~~~~~~~~~
44 // declare a run-time selection:
45 #define declareMemberFunctionSelectionTable\
46 (returnType,baseType,memberFunction,argNames,argList,parList)                 \
47                                                                               \
48     /* Construct from argList function pointer type */                        \
49     typedef returnType (*memberFunction##argNames##MemberFunctionPtr)argList; \
50                                                                               \
51     /* Construct from argList function table type */                          \
52     typedef HashTable                                                         \
53         <memberFunction##argNames##MemberFunctionPtr, word, string::hash>     \
54         memberFunction##argNames##MemberFunctionTable;                        \
55                                                                               \
56     /* Construct from argList function pointer table pointer */               \
57     static memberFunction##argNames##MemberFunctionTable*                     \
58         memberFunction##argNames##MemberFunctionTablePtr_;                    \
59                                                                               \
60     /* Class to add constructor from argList to table */                      \
61     template<class baseType##Type>                                            \
62     class add##memberFunction##argNames##MemberFunctionToTable                \
63     {                                                                         \
64     public:                                                                   \
65                                                                               \
66         add##memberFunction##argNames##MemberFunctionToTable                  \
67         (                                                                     \
68             const word& lookup = baseType##Type::typeName                     \
69         )                                                                     \
70         {                                                                     \
71             construct##memberFunction##argNames##MemberFunctionTables();      \
72             memberFunction##argNames##MemberFunctionTablePtr_->insert         \
73             (                                                                 \
74                 lookup,                                                       \
75                 baseType##Type::memberFunction                                \
76             );                                                                \
77         }                                                                     \
78                                                                               \
79         ~add##memberFunction##argNames##MemberFunctionToTable()               \
80         {                                                                     \
81             destroy##memberFunction##argNames##MemberFunctionTables();        \
82         }                                                                     \
83     };                                                                        \
84                                                                               \
85     /* Table memberFunction called from the table add function */             \
86     static void construct##memberFunction##argNames##MemberFunctionTables();  \
87                                                                               \
88     /* Table destructor called from the table add function destructor */      \
89     static void destroy##memberFunction##argNames##MemberFunctionTables()
92 // internal use:
93 // constructor aid
94 #define defineMemberFunctionSelectionTableMemberFunction\
95 (baseType,memberFunction,argNames)                                            \
96                                                                               \
97     /* Table memberFunction called from the table add function */             \
98     void baseType::construct##memberFunction##argNames##MemberFunctionTables()\
99     {                                                                         \
100         static bool constructed = false;                                      \
101                                                                               \
102         if (!constructed)                                                     \
103         {                                                                     \
104             baseType::memberFunction##argNames##MemberFunctionTablePtr_       \
105                 = new baseType::memberFunction##argNames##MemberFunctionTable;\
106                                                                               \
107             constructed = true;                                               \
108         }                                                                     \
109     }
112 // internal use:
113 // destructor aid
114 #define defineMemberFunctionSelectionTableDestructor\
115 (baseType,memberFunction,argNames)                                            \
116                                                                               \
117     /* Table destructor called from the table add function destructor */      \
118     void baseType::destroy##memberFunction##argNames##MemberFunctionTables()  \
119     {                                                                         \
120         if (baseType::memberFunction##argNames##MemberFunctionTablePtr_)      \
121         {                                                                     \
122             delete baseType::memberFunction##argNames##MemberFunctionTablePtr_;\
123             baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL;\
124         }                                                                     \
125     }
128 // internal use:
129 // create pointer to hash-table of functions
130 #define defineMemberFunctionSelectionTablePtr\
131 (baseType,memberFunction,argNames)                                            \
132                                                                               \
133     /* Define the memberFunction table */                                     \
134     baseType::memberFunction##argNames##MemberFunctionTable*                  \
135         baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL
138 // not much in use:
139 #define defineTemplateMemberFunctionSelectionTablePtr\
140 (baseType,memberFunction,argNames)                                            \
141                                                                               \
142     /* Define the memberFunction table */                                     \
143     typename baseType::memberFunction##argNames##MemberFunctionTable*         \
144         baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 // external use:
150 // ~~~~~~~~~~~~~
151 // define run-time selection table
152 #define defineMemberFunctionSelectionTable\
153 (baseType,memberFunction,argNames)                                            \
154                                                                               \
155     defineMemberFunctionSelectionTablePtr                                     \
156         (baseType,memberFunction,argNames);                                   \
157     defineMemberFunctionSelectionTableMemberFunction                          \
158         (baseType,memberFunction,argNames)                                    \
159     defineMemberFunctionSelectionTableDestructor                              \
160         (baseType,memberFunction,argNames)
163 // external use:
164 // ~~~~~~~~~~~~~
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)                                            \
169                                                                               \
170     template<>                                                                \
171     defineMemberFunctionSelectionTablePtr                                     \
172         (baseType,memberFunction,argNames);                                   \
173     template<>                                                                \
174     defineMemberFunctionSelectionTableMemberFunction                          \
175         (baseType,memberFunction,argNames)                                    \
176     template<>                                                                \
177     defineMemberFunctionSelectionTableDestructor                              \
178         (baseType,memberFunction,argNames)
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 // internal use:
184 // constructor aid
185 // use when baseType requires the Targ template argument
186 #define defineTemplatedMemberFunctionSelectionTableMemberFunction\
187 (baseType,memberFunction,argNames,Targ)                                       \
188                                                                               \
189     /* Table memberFunction called from the table add function */             \
190     void baseType<Targ>::construct##memberFunction##argNames##MemberFunctionTables()\
191     {                                                                         \
192         static bool constructed = false;                                      \
193                                                                               \
194         if (!constructed)                                                     \
195         {                                                                     \
196             baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_       \
197                 = new baseType<Targ>::memberFunction##argNames##MemberFunctionTable;\
198                                                                               \
199             constructed = true;                                               \
200         }                                                                     \
201     }
204 // internal use:
205 // destructor aid
206 // use when baseType requires the Targ template argument
207 #define defineTemplatedMemberFunctionSelectionTableDestructor\
208 (baseType,memberFunction,argNames,Targ)                                       \
209                                                                               \
210     /* Table destructor called from the table add function destructor */      \
211     void baseType<Targ>::destroy##memberFunction##argNames##MemberFunctionTables()  \
212     {                                                                         \
213         if (baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_)      \
214         {                                                                     \
215             delete baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_;\
216             baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_ = NULL;\
217         }                                                                     \
218     }
221 // internal use:
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)                                       \
226                                                                               \
227     /* Define the memberFunction table */                                     \
228     baseType<Targ>::memberFunction##argNames##MemberFunctionTable*            \
229         baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_ = NULL
232 // external use:
233 // ~~~~~~~~~~~~~
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)                                       \
238                                                                               \
239     template<>                                                                \
240     defineTemplatedMemberFunctionSelectionTablePtr                            \
241         (baseType,memberFunction,argNames,Targ);                              \
242     template<>                                                                \
243     defineTemplatedMemberFunctionSelectionTableMemberFunction                 \
244         (baseType,memberFunction,argNames,Targ)                               \
245     template<>                                                                \
246     defineTemplatedMemberFunctionSelectionTableDestructor                     \
247         (baseType,memberFunction,argNames,Targ)
249 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
251 #endif
253 // ************************************************************************* //