From 051eee5caa9eee6344d80b64ffa4aa8c21cead49 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 13 Nov 2008 09:44:03 +0100 Subject: [PATCH] runTimeSelection/memberFunctionSelection templated forms - useful when the baseType isn't a typedef and thus requires the same template argument as the derived class --- .../addToMemberFunctionSelectionTable.H | 26 ++- .../memberFunctionSelectionTables.H | 8 +- .../addToRunTimeSelectionTable.H | 31 +++- .../runTimeSelection/runTimeSelectionTables.H | 170 +++++++++--------- 4 files changed, 137 insertions(+), 98 deletions(-) diff --git a/src/OpenFOAM/db/memberFunctionSelection/addToMemberFunctionSelectionTable.H b/src/OpenFOAM/db/memberFunctionSelection/addToMemberFunctionSelectionTable.H index c9f3080a07..03f2a1ea58 100644 --- a/src/OpenFOAM/db/memberFunctionSelection/addToMemberFunctionSelectionTable.H +++ b/src/OpenFOAM/db/memberFunctionSelection/addToMemberFunctionSelectionTable.H @@ -38,31 +38,49 @@ Description #define addToMemberFunctionSelectionTable\ (baseType,thisType,memberFunction,argNames) \ \ - /* Add the thisType constructor function to the table */ \ + /* Add the thisType memberFunction to the table */ \ baseType::add##memberFunction##argNames##MemberFunctionToTable \ add##thisType##memberFunction##argNames##MemberFunctionTo##baseType##Table_ #define addNamedToMemberFunctionSelectionTable\ (baseType,thisType,memberFunction,argNames,lookup) \ \ - /* Add the thisType constructor function to the table */ \ + /* Add the thisType memberFunction to the table, find by lookup name */ \ baseType::add##memberFunction##argNames##MemberFunctionToTable \ add_##lookup##_##thisType##memberFunction##argNames##MemberFunctionTo##baseType##Table_(#lookup) +// use when baseType doesn't need a template argument (eg, is a typedef) #define addTemplateToMemberFunctionSelectionTable\ (baseType,thisType,Targ,memberFunction,argNames) \ \ - /* Add the thisType constructor function to the table */ \ + /* Add the thisType memberFunction to the table */ \ baseType::add##memberFunction##argNames##MemberFunctionToTable > \ add##thisType##Targ##memberFunction##argNames##MemberFunctionTo##baseType##Table_ +// use when baseType doesn't need a template argument (eg, is a typedef) #define addNamedTemplateToMemberFunctionSelectionTable\ (baseType,thisType,Targ,memberFunction,argNames,lookup) \ \ - /* Add the thisType constructor function to the table */ \ + /* Add the thisType memberFunction to the table, find by lookup name */ \ baseType::add##memberFunction##argNames##MemberFunctionToTable > \ add_##lookup##_##thisType##Targ##memberFunction##argNames##MemberFunctionTo##baseType##Table_(#lookup) +// use when baseType requires the Targ template argument as well +#define addTemplatedToMemberFunctionSelectionTable\ +(baseType,thisType,Targ,memberFunction,argNames) \ + \ + /* Add the thisType memberFunction to the table */ \ + baseType::add##memberFunction##argNames##MemberFunctionToTable > \ + add##thisType##Targ##memberFunction##argNames##MemberFunctionTo##baseType##Targ##Table_ + +// use when baseType requires the Targ template argument as well +#define addNamedTemplatedToMemberFunctionSelectionTable\ +(baseType,thisType,Targ,memberFunction,argNames,lookup) \ + \ + /* Add the thisType memberFunction to the table, find by lookup name */ \ + baseType::add##memberFunction##argNames##MemberFunctionToTable > \ + add_##lookup##_##thisType##Targ##memberFunction##argNames##MemberFunctionTo##baseType##Targ##Table_(#lookup) + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/db/memberFunctionSelection/memberFunctionSelectionTables.H b/src/OpenFOAM/db/memberFunctionSelection/memberFunctionSelectionTables.H index 0b01515f65..b91e0fd682 100644 --- a/src/OpenFOAM/db/memberFunctionSelection/memberFunctionSelectionTables.H +++ b/src/OpenFOAM/db/memberFunctionSelection/memberFunctionSelectionTables.H @@ -79,7 +79,7 @@ Description } \ }; \ \ - /* Table MemberFunction called from the table add function */ \ + /* Table memberFunction called from the table add function */ \ static void construct##memberFunction##argNames##MemberFunctionTables(); \ \ /* Table destructor called from the table add function destructor */ \ @@ -89,7 +89,7 @@ Description #define defineMemberFunctionSelectionTableMemberFunction\ (baseType,memberFunction,argNames) \ \ - /* Table MemberFunction called from the table add function */ \ + /* Table memberFunction called from the table add function */ \ void baseType::construct##memberFunction##argNames##MemberFunctionTables()\ { \ static bool constructed = false; \ @@ -119,14 +119,14 @@ Description #define defineMemberFunctionSelectionTablePtr\ (baseType,memberFunction,argNames) \ \ - /* Define the constructor function table */ \ + /* Define the memberFunction table */ \ baseType::memberFunction##argNames##MemberFunctionTable* \ baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL #define defineTemplateMemberFunctionSelectionTablePtr\ (baseType,memberFunction,argNames) \ \ - /* Define the constructor function table */ \ + /* Define the memberFunction table */ \ typename baseType::memberFunction##argNames##MemberFunctionTable* \ baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL diff --git a/src/OpenFOAM/db/runTimeSelection/addToRunTimeSelectionTable.H b/src/OpenFOAM/db/runTimeSelection/addToRunTimeSelectionTable.H index a12190eb75..78837835e5 100644 --- a/src/OpenFOAM/db/runTimeSelection/addToRunTimeSelectionTable.H +++ b/src/OpenFOAM/db/runTimeSelection/addToRunTimeSelectionTable.H @@ -35,31 +35,52 @@ Description // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define addToRunTimeSelectionTable(baseType,thisType,argNames) \ +#define addToRunTimeSelectionTable\ +(baseType,thisType,argNames) \ \ /* Add the thisType constructor function to the table */ \ baseType::add##argNames##ConstructorToTable \ add##thisType##argNames##ConstructorTo##baseType##Table_ -#define addNamedToRunTimeSelectionTable(baseType,thisType,argNames,lookup) \ +#define addNamedToRunTimeSelectionTable\ +(baseType,thisType,argNames,lookup) \ \ - /* Add the thisType constructor function to the table */ \ + /* Add the thisType constructor function to the table, find by lookup */ \ baseType::add##argNames##ConstructorToTable \ add_##lookup##_##thisType##argNames##ConstructorTo##baseType##Table_(#lookup) -#define addTemplateToRunTimeSelectionTable(baseType,thisType,Targ,argNames) \ +// use when baseType doesn't need a template argument (eg, is a typedef) +#define addTemplateToRunTimeSelectionTable\ +(baseType,thisType,Targ,argNames) \ \ /* Add the thisType constructor function to the table */ \ baseType::add##argNames##ConstructorToTable > \ add##thisType##Targ##argNames##ConstructorTo##baseType##Table_ +// use when baseType doesn't need a template argument (eg, is a typedef) #define addNamedTemplateToRunTimeSelectionTable\ (baseType,thisType,Targ,argNames,lookup) \ \ - /* Add the thisType constructor function to the table */ \ + /* Add the thisType constructor function to the table, find by lookup */ \ baseType::add##argNames##ConstructorToTable > \ add_##lookup##_##thisType##Targ##argNames##ConstructorTo##baseType##Table_(#lookup) +// use when baseType requires the Targ template argument as well +#define addTemplatedToRunTimeSelectionTable\ +(baseType,thisType,Targ,argNames) \ + \ + /* Add the thisType constructor function to the table */ \ + baseType::add##argNames##ConstructorToTable > \ + add##thisType##Targ##argNames##ConstructorTo##baseType##Targ##Table_ + +// use when baseType requires the Targ template argument as well +#define addNamedTemplatedToRunTimeSelectionTable\ +(baseType,thisType,Targ,argNames,lookup) \ + \ + /* Add the thisType constructor function to the table, find by lookup */ \ + baseType::add##argNames##ConstructorToTable > \ + add_##lookup##_##thisType##Targ##argNames##ConstructorTo##baseType##Targ##Table_(#lookup) + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif diff --git a/src/OpenFOAM/db/runTimeSelection/runTimeSelectionTables.H b/src/OpenFOAM/db/runTimeSelection/runTimeSelectionTables.H index 52eb8a0aff..f2bad6ae83 100644 --- a/src/OpenFOAM/db/runTimeSelection/runTimeSelectionTables.H +++ b/src/OpenFOAM/db/runTimeSelection/runTimeSelectionTables.H @@ -41,104 +41,104 @@ Description // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #define declareRunTimeSelectionTable\ -(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 argList \ - { \ - return autoPtr(new baseType##Type parList); \ - } \ - \ - add##argNames##ConstructorToTable \ - ( \ - const word& lookup = baseType##Type::typeName \ - ) \ - { \ - construct##argNames##ConstructorTables(); \ - argNames##ConstructorTablePtr_->insert(lookup, New); \ - } \ - \ - ~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 */\ +(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 argList \ + { \ + return autoPtr(new baseType##Type parList); \ + } \ + \ + add##argNames##ConstructorToTable \ + ( \ + const word& lookup = baseType##Type::typeName \ + ) \ + { \ + construct##argNames##ConstructorTables(); \ + argNames##ConstructorTablePtr_->insert(lookup, New); \ + } \ + \ + ~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 */ \ - void baseType::construct##argNames##ConstructorTables() \ - { \ - static bool constructed = false; \ - \ - if (!constructed) \ - { \ - baseType::argNames##ConstructorTablePtr_ \ - = new baseType::argNames##ConstructorTable; \ - \ - constructed = true; \ - } \ +#define defineRunTimeSelectionTableConstructor(baseType,argNames) \ + \ + /* Table constructor called from the table add function */ \ + void baseType::construct##argNames##ConstructorTables() \ + { \ + static bool constructed = false; \ + \ + if (!constructed) \ + { \ + baseType::argNames##ConstructorTablePtr_ \ + = new baseType::argNames##ConstructorTable; \ + \ + constructed = true; \ + } \ } -#define defineRunTimeSelectionTableDestructor(baseType,argNames) \ - \ - /* Table destructor called from the table add function destructor */\ - void baseType::destroy##argNames##ConstructorTables() \ - { \ - if (baseType::argNames##ConstructorTablePtr_) \ - { \ - delete baseType::argNames##ConstructorTablePtr_; \ - baseType::argNames##ConstructorTablePtr_ = NULL; \ - } \ +#define defineRunTimeSelectionTableDestructor(baseType,argNames) \ + \ + /* Table destructor called from the table add function destructor */ \ + void baseType::destroy##argNames##ConstructorTables() \ + { \ + if (baseType::argNames##ConstructorTablePtr_) \ + { \ + delete baseType::argNames##ConstructorTablePtr_; \ + baseType::argNames##ConstructorTablePtr_ = NULL; \ + } \ } -#define defineRunTimeSelectionTablePtr(baseType,argNames) \ - \ - /* Define the constructor function table */ \ - baseType::argNames##ConstructorTable* \ +#define defineRunTimeSelectionTablePtr(baseType,argNames) \ + \ + /* Define the constructor function table */ \ + baseType::argNames##ConstructorTable* \ baseType::argNames##ConstructorTablePtr_ = NULL -#define defineTemplateRunTimeSelectionTablePtr(baseType,argNames) \ - \ - /* Define the constructor function table */ \ - typename baseType::argNames##ConstructorTable* \ +#define defineTemplateRunTimeSelectionTablePtr(baseType,argNames) \ + \ + /* Define the constructor function table */ \ + typename baseType::argNames##ConstructorTable* \ baseType::argNames##ConstructorTablePtr_ = NULL -#define defineRunTimeSelectionTable(baseType,argNames) \ - \ - defineRunTimeSelectionTablePtr(baseType,argNames); \ - defineRunTimeSelectionTableConstructor(baseType,argNames) \ +#define defineRunTimeSelectionTable(baseType,argNames) \ + \ + defineRunTimeSelectionTablePtr(baseType,argNames); \ + defineRunTimeSelectionTableConstructor(baseType,argNames) \ defineRunTimeSelectionTableDestructor(baseType,argNames) -#define defineTemplateRunTimeSelectionTable(baseType,argNames) \ - \ - template<> \ - defineRunTimeSelectionTablePtr(baseType,argNames); \ - template<> \ - defineRunTimeSelectionTableConstructor(baseType,argNames) \ - template<> \ +#define defineTemplateRunTimeSelectionTable(baseType,argNames) \ + \ + template<> \ + defineRunTimeSelectionTablePtr(baseType,argNames); \ + template<> \ + defineRunTimeSelectionTableConstructor(baseType,argNames) \ + template<> \ defineRunTimeSelectionTableDestructor(baseType,argNames)