37 #ifndef runTimeSelectionTables_H
38 #define runTimeSelectionTables_H
46 #define declareRunTimeSelectionTable(autoPtr,baseType,argNames,argList,parList)\
49 typedef autoPtr<baseType> (*argNames##ConstructorPtr)argList; \
52 typedef HashTable<argNames##ConstructorPtr, word, string::hash> \
53 argNames##ConstructorTable; \
56 static argNames##ConstructorTable* argNames##ConstructorTablePtr_; \
59 static void construct##argNames##ConstructorTables(); \
62 static void destroy##argNames##ConstructorTables(); \
65 template<class baseType##Type> \
66 class add##argNames##ConstructorToTable \
70 static autoPtr<baseType> New argList \
72 return autoPtr<baseType>(new baseType##Type parList); \
75 add##argNames##ConstructorToTable \
77 const word& lookup = baseType##Type::typeName \
80 construct##argNames##ConstructorTables(); \
81 if (!argNames##ConstructorTablePtr_->insert(lookup, New)) \
83 std::cerr<< "Duplicate entry " << lookup \
84 << " in runtime selection table " << #baseType \
86 error::safePrintStack(std::cerr); \
90 ~add##argNames##ConstructorToTable() \
92 destroy##argNames##ConstructorTables(); \
98 template<class baseType##Type> \
99 class addRemovable##argNames##ConstructorToTable \
102 const word& lookup_; \
106 static autoPtr<baseType> New argList \
108 return autoPtr<baseType>(new baseType##Type parList); \
111 addRemovable##argNames##ConstructorToTable \
113 const word& lookup = baseType##Type::typeName \
118 construct##argNames##ConstructorTables(); \
119 argNames##ConstructorTablePtr_->set(lookup, New); \
122 ~addRemovable##argNames##ConstructorToTable() \
124 if (argNames##ConstructorTablePtr_) \
126 argNames##ConstructorTablePtr_->erase(lookup_); \
134 #define declareRunTimeNewSelectionTable( \
135 autoPtr,baseType,argNames,argList,parList) \
138 typedef autoPtr<baseType> (*argNames##ConstructorPtr)argList; \
141 typedef HashTable<argNames##ConstructorPtr, word, string::hash> \
142 argNames##ConstructorTable; \
145 static argNames##ConstructorTable* argNames##ConstructorTablePtr_; \
148 static void construct##argNames##ConstructorTables(); \
151 static void destroy##argNames##ConstructorTables(); \
154 template<class baseType##Type> \
155 class add##argNames##ConstructorToTable \
159 static autoPtr<baseType> New##baseType argList \
161 return autoPtr<baseType>(baseType##Type::New parList.ptr()); \
164 add##argNames##ConstructorToTable \
166 const word& lookup = baseType##Type::typeName \
169 construct##argNames##ConstructorTables(); \
172 !argNames##ConstructorTablePtr_->insert \
179 std::cerr<< "Duplicate entry " << lookup \
180 << " in runtime selection table " << #baseType \
182 error::safePrintStack(std::cerr); \
186 ~add##argNames##ConstructorToTable() \
188 destroy##argNames##ConstructorTables(); \
193 template<class baseType##Type> \
194 class addRemovable##argNames##ConstructorToTable \
197 const word& lookup_; \
201 static autoPtr<baseType> New##baseType argList \
203 return autoPtr<baseType>(baseType##Type::New parList.ptr()); \
206 addRemovable##argNames##ConstructorToTable \
208 const word& lookup = baseType##Type::typeName \
213 construct##argNames##ConstructorTables(); \
214 argNames##ConstructorTablePtr_->set \
221 ~addRemovable##argNames##ConstructorToTable() \
223 if (argNames##ConstructorTablePtr_) \
225 argNames##ConstructorTablePtr_->erase(lookup_); \
232 #define defineRunTimeSelectionTableConstructor(baseType,argNames) \
235 void baseType::construct##argNames##ConstructorTables() \
237 static bool constructed = false; \
240 constructed = true; \
241 baseType::argNames##ConstructorTablePtr_ \
242 = new baseType::argNames##ConstructorTable; \
248 #define defineRunTimeSelectionTableDestructor(baseType,argNames) \
251 void baseType::destroy##argNames##ConstructorTables() \
253 if (baseType::argNames##ConstructorTablePtr_) \
255 delete baseType::argNames##ConstructorTablePtr_; \
256 baseType::argNames##ConstructorTablePtr_ = nullptr; \
262 #define defineRunTimeSelectionTablePtr(baseType,argNames) \
265 baseType::argNames##ConstructorTable* \
266 baseType::argNames##ConstructorTablePtr_ = nullptr
273 #define defineRunTimeSelectionTable(baseType,argNames) \
275 defineRunTimeSelectionTablePtr(baseType,argNames); \
276 defineRunTimeSelectionTableConstructor(baseType,argNames); \
277 defineRunTimeSelectionTableDestructor(baseType,argNames)
282 #define defineTemplateRunTimeSelectionTable(baseType,argNames) \
285 defineRunTimeSelectionTablePtr(baseType,argNames); \
287 defineRunTimeSelectionTableConstructor(baseType,argNames); \
289 defineRunTimeSelectionTableDestructor(baseType,argNames)
295 #define defineTemplatedRunTimeSelectionTableConstructor(baseType,argNames,Targ)\
298 void baseType<Targ>::construct##argNames##ConstructorTables() \
300 static bool constructed = false; \
303 constructed = true; \
304 baseType<Targ>::argNames##ConstructorTablePtr_ \
305 = new baseType<Targ>::argNames##ConstructorTable; \
311 #define defineTemplatedRunTimeSelectionTableDestructor(baseType,argNames,Targ) \
314 void baseType<Targ>::destroy##argNames##ConstructorTables() \
316 if (baseType<Targ>::argNames##ConstructorTablePtr_) \
318 delete baseType<Targ>::argNames##ConstructorTablePtr_; \
319 baseType<Targ>::argNames##ConstructorTablePtr_ = nullptr; \
326 #define defineTemplatedRunTimeSelectionTablePtr(baseType,argNames,Targ) \
329 baseType<Targ>::argNames##ConstructorTable* \
330 baseType<Targ>::argNames##ConstructorTablePtr_ = nullptr
335 #define defineTemplatedRunTimeSelectionTable(baseType,argNames,Targ) \
338 defineTemplatedRunTimeSelectionTablePtr(baseType,argNames,Targ); \
340 defineTemplatedRunTimeSelectionTableConstructor(baseType,argNames,Targ); \
342 defineTemplatedRunTimeSelectionTableDestructor(baseType,argNames,Targ)