From 6dc5b6e935afbc41e2b07f2aad90a9da4a1b7b85 Mon Sep 17 00:00:00 2001 From: henry Date: Fri, 14 Nov 2008 14:24:33 +0000 Subject: [PATCH] Added support for selection tables containing New functions rather than constructors. --- .../runTimeSelection/runTimeSelectionTables.H | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/OpenFOAM/db/runTimeSelection/runTimeSelectionTables.H b/src/OpenFOAM/db/runTimeSelection/runTimeSelectionTables.H index 52eb8a0aff..4ca1293054 100644 --- a/src/OpenFOAM/db/runTimeSelection/runTimeSelectionTables.H +++ b/src/OpenFOAM/db/runTimeSelection/runTimeSelectionTables.H @@ -28,6 +28,12 @@ Class Description Macros to enable the easy declaration of run-time selection tables. + declareRunTimeSelectionTable is used to create a run-time selection table + for a base-class which holds constructor pointers on the table. + + declareRunTimeNewSelectionTable is used to create a run-time selection + table for a derived-class which holds "New" pointers on the table. + \*---------------------------------------------------------------------------*/ #include "token.H" @@ -86,6 +92,56 @@ Description static void destroy##argNames##ConstructorTables() +#define declareRunTimeNewSelectionTable\ +(autoPtr,baseType,argNames,argList,parList) \ + \ + /* Construct from argList function pointer type */ \ + typedef autoPtr (*argNames##ConstructorPtr)argList; \ + \ + /* Construct from argList function table type */ \ + typedef HashTable \ + argNames##ConstructorTable; \ + \ + /* Construct from argList function pointer table pointer */ \ + static argNames##ConstructorTable* argNames##ConstructorTablePtr_; \ + \ + /* Class to add constructor from argList to table */ \ + template \ + class add##argNames##ConstructorToTable \ + { \ + public: \ + \ + static autoPtr New##baseType argList \ + { \ + return autoPtr(baseType##Type::New parList.ptr());\ + } \ + \ + add##argNames##ConstructorToTable \ + ( \ + const word& lookup = baseType##Type::typeName \ + ) \ + { \ + construct##argNames##ConstructorTables(); \ + argNames##ConstructorTablePtr_->insert \ + ( \ + lookup, \ + New##baseType \ + ); \ + } \ + \ + ~add##argNames##ConstructorToTable() \ + { \ + destroy##argNames##ConstructorTables(); \ + } \ + }; \ + \ + /* Table Constructor called from the table add function */ \ + static void construct##argNames##ConstructorTables(); \ + \ + /* Table destructor called from the table add function destructor */\ + static void destroy##argNames##ConstructorTables() + + #define defineRunTimeSelectionTableConstructor(baseType,argNames) \ \ /* Table Constructor called from the table add function */ \