From 895feecb6b8236810677f5e59004e837f19e193e Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Fri, 14 Nov 2008 01:42:30 +0100
Subject: [PATCH] more runTimeSelection/memberFunctionSelection templated forms

 - also allow table definition to have a templated baseType
 - added some comments/whitespace to make the files easier to read
---
 .../addToMemberFunctionSelectionTable.H       |  19 ++++
 .../memberFunctionSelectionTables.H           |  96 +++++++++++++++-
 .../addToRunTimeSelectionTable.H              |  18 +++
 .../runTimeSelection/runTimeSelectionTables.H | 105 +++++++++++++++++-
 4 files changed, 233 insertions(+), 5 deletions(-)

diff --git a/src/OpenFOAM/db/memberFunctionSelection/addToMemberFunctionSelectionTable.H b/src/OpenFOAM/db/memberFunctionSelection/addToMemberFunctionSelectionTable.H
index 03f2a1ea58e..36419156f09 100644
--- a/src/OpenFOAM/db/memberFunctionSelection/addToMemberFunctionSelectionTable.H
+++ b/src/OpenFOAM/db/memberFunctionSelection/addToMemberFunctionSelectionTable.H
@@ -35,6 +35,8 @@ Description
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
+
+// add to hash-table of functions with typename as the key
 #define addToMemberFunctionSelectionTable\
 (baseType,thisType,memberFunction,argNames)                                   \
                                                                               \
@@ -42,6 +44,9 @@ Description
     baseType::add##memberFunction##argNames##MemberFunctionToTable<thisType>  \
     add##thisType##memberFunction##argNames##MemberFunctionTo##baseType##Table_
 
+
+
+// add to hash-table of functions with 'lookup' as the key
 #define addNamedToMemberFunctionSelectionTable\
 (baseType,thisType,memberFunction,argNames,lookup)                            \
                                                                               \
@@ -49,6 +54,11 @@ Description
     baseType::add##memberFunction##argNames##MemberFunctionToTable<thisType>  \
     add_##lookup##_##thisType##memberFunction##argNames##MemberFunctionTo##baseType##Table_(#lookup)
 
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+
+// add to hash-table of functions with typename as the key
 // use when baseType doesn't need a template argument (eg, is a typedef)
 #define addTemplateToMemberFunctionSelectionTable\
 (baseType,thisType,Targ,memberFunction,argNames)                              \
@@ -57,6 +67,8 @@ Description
     baseType::add##memberFunction##argNames##MemberFunctionToTable<thisType<Targ> > \
     add##thisType##Targ##memberFunction##argNames##MemberFunctionTo##baseType##Table_
 
+
+// add to hash-table of functions with 'lookup' as the key
 // use when baseType doesn't need a template argument (eg, is a typedef)
 #define addNamedTemplateToMemberFunctionSelectionTable\
 (baseType,thisType,Targ,memberFunction,argNames,lookup)                       \
@@ -65,6 +77,11 @@ Description
     baseType::add##memberFunction##argNames##MemberFunctionToTable<thisType<Targ> > \
     add_##lookup##_##thisType##Targ##memberFunction##argNames##MemberFunctionTo##baseType##Table_(#lookup)
 
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+
+// add to hash-table of functions with typename as the key
 // use when baseType requires the Targ template argument as well
 #define addTemplatedToMemberFunctionSelectionTable\
 (baseType,thisType,Targ,memberFunction,argNames)                              \
@@ -73,6 +90,8 @@ Description
     baseType<Targ>::add##memberFunction##argNames##MemberFunctionToTable<thisType<Targ> > \
     add##thisType##Targ##memberFunction##argNames##MemberFunctionTo##baseType##Targ##Table_
 
+
+// add to hash-table of functions with 'lookup' as the key
 // use when baseType requires the Targ template argument as well
 #define addNamedTemplatedToMemberFunctionSelectionTable\
 (baseType,thisType,Targ,memberFunction,argNames,lookup)                       \
diff --git a/src/OpenFOAM/db/memberFunctionSelection/memberFunctionSelectionTables.H b/src/OpenFOAM/db/memberFunctionSelection/memberFunctionSelectionTables.H
index b91e0fd682c..851092375c5 100644
--- a/src/OpenFOAM/db/memberFunctionSelection/memberFunctionSelectionTables.H
+++ b/src/OpenFOAM/db/memberFunctionSelection/memberFunctionSelectionTables.H
@@ -39,6 +39,10 @@ Description
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
+
+// external use:
+// ~~~~~~~~~~~~~
+// declare a run-time selection:
 #define declareMemberFunctionSelectionTable\
 (returnType,baseType,memberFunction,argNames,argList,parList)                 \
                                                                               \
@@ -86,6 +90,8 @@ Description
     static void destroy##memberFunction##argNames##MemberFunctionTables()
 
 
+// internal use:
+// constructor aid
 #define defineMemberFunctionSelectionTableMemberFunction\
 (baseType,memberFunction,argNames)                                            \
                                                                               \
@@ -103,6 +109,9 @@ Description
         }                                                                     \
     }
 
+
+// internal use:
+// destructor aid
 #define defineMemberFunctionSelectionTableDestructor\
 (baseType,memberFunction,argNames)                                            \
                                                                               \
@@ -116,6 +125,9 @@ Description
         }                                                                     \
     }
 
+
+// internal use:
+// create pointer to hash-table of functions
 #define defineMemberFunctionSelectionTablePtr\
 (baseType,memberFunction,argNames)                                            \
                                                                               \
@@ -123,6 +135,8 @@ Description
     baseType::memberFunction##argNames##MemberFunctionTable*                  \
         baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL
 
+
+// not much in use:
 #define defineTemplateMemberFunctionSelectionTablePtr\
 (baseType,memberFunction,argNames)                                            \
                                                                               \
@@ -130,7 +144,14 @@ Description
     typename baseType::memberFunction##argNames##MemberFunctionTable*         \
         baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL
 
-#define defineMemberFunctionSelectionTable(baseType,memberFunction,argNames)  \
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+// external use:
+// ~~~~~~~~~~~~~
+// define run-time selection table
+#define defineMemberFunctionSelectionTable\
+(baseType,memberFunction,argNames)                                            \
                                                                               \
     defineMemberFunctionSelectionTablePtr                                     \
         (baseType,memberFunction,argNames);                                   \
@@ -139,6 +160,11 @@ Description
     defineMemberFunctionSelectionTableDestructor                              \
         (baseType,memberFunction,argNames)
 
+
+// external use:
+// ~~~~~~~~~~~~~
+// define run-time selection table for template classes
+// use when baseType doesn't need a template argument (eg, is a typedef)
 #define defineTemplateMemberFunctionSelectionTable\
 (baseType,memberFunction,argNames)                                            \
                                                                               \
@@ -155,6 +181,74 @@ Description
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
+// internal use:
+// constructor aid
+// use when baseType requires the Targ template argument
+#define defineTemplatedMemberFunctionSelectionTableMemberFunction\
+(baseType,memberFunction,argNames,Targ)                                       \
+                                                                              \
+    /* Table memberFunction called from the table add function */             \
+    void baseType<Targ>::construct##memberFunction##argNames##MemberFunctionTables()\
+    {                                                                         \
+        static bool constructed = false;                                      \
+                                                                              \
+        if (!constructed)                                                     \
+        {                                                                     \
+            baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_       \
+                = new baseType<Targ>::memberFunction##argNames##MemberFunctionTable;\
+                                                                              \
+            constructed = true;                                               \
+        }                                                                     \
+    }
+
+
+// internal use:
+// destructor aid
+// use when baseType requires the Targ template argument
+#define defineTemplatedMemberFunctionSelectionTableDestructor\
+(baseType,memberFunction,argNames,Targ)                                       \
+                                                                              \
+    /* Table destructor called from the table add function destructor */      \
+    void baseType<Targ>::destroy##memberFunction##argNames##MemberFunctionTables()  \
+    {                                                                         \
+        if (baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_)      \
+        {                                                                     \
+            delete baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_;\
+            baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_ = NULL;\
+        }                                                                     \
+    }
+
+
+// internal use:
+// create pointer to hash-table of functions
+// use when baseType requires the Targ template argument
+#define defineTemplatedMemberFunctionSelectionTablePtr\
+(baseType,memberFunction,argNames,Targ)                                       \
+                                                                              \
+    /* Define the memberFunction table */                                     \
+    baseType<Targ>::memberFunction##argNames##MemberFunctionTable*            \
+        baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_ = NULL
+
+
+// external use:
+// ~~~~~~~~~~~~~
+// define run-time selection table for template classes
+// use when baseType requires the Targ template argument
+#define defineTemplatedMemberFunctionSelectionTable\
+(baseType,memberFunction,argNames,Targ)                                       \
+                                                                              \
+    template<>                                                                \
+    defineTemplatedMemberFunctionSelectionTablePtr                            \
+        (baseType,memberFunction,argNames,Targ);                              \
+    template<>                                                                \
+    defineTemplatedMemberFunctionSelectionTableMemberFunction                 \
+        (baseType,memberFunction,argNames,Targ)                               \
+    template<>                                                                \
+    defineTemplatedMemberFunctionSelectionTableDestructor                     \
+        (baseType,memberFunction,argNames,Targ)
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
 #endif
 
 // ************************************************************************* //
diff --git a/src/OpenFOAM/db/runTimeSelection/addToRunTimeSelectionTable.H b/src/OpenFOAM/db/runTimeSelection/addToRunTimeSelectionTable.H
index 78837835e5c..50818836631 100644
--- a/src/OpenFOAM/db/runTimeSelection/addToRunTimeSelectionTable.H
+++ b/src/OpenFOAM/db/runTimeSelection/addToRunTimeSelectionTable.H
@@ -35,6 +35,8 @@ Description
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
+
+// add to hash-table of functions with typename as the key
 #define addToRunTimeSelectionTable\
 (baseType,thisType,argNames)                                                  \
                                                                               \
@@ -42,6 +44,8 @@ Description
     baseType::add##argNames##ConstructorToTable<thisType>                     \
         add##thisType##argNames##ConstructorTo##baseType##Table_
 
+
+// add to hash-table of functions with 'lookup' as the key
 #define addNamedToRunTimeSelectionTable\
 (baseType,thisType,argNames,lookup)                                           \
                                                                               \
@@ -49,6 +53,10 @@ Description
     baseType::add##argNames##ConstructorToTable<thisType>                     \
         add_##lookup##_##thisType##argNames##ConstructorTo##baseType##Table_(#lookup)
 
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+
+// add to hash-table of functions with typename as the key
 // use when baseType doesn't need a template argument (eg, is a typedef)
 #define addTemplateToRunTimeSelectionTable\
 (baseType,thisType,Targ,argNames)                                             \
@@ -57,6 +65,8 @@ Description
     baseType::add##argNames##ConstructorToTable<thisType<Targ> >              \
         add##thisType##Targ##argNames##ConstructorTo##baseType##Table_
 
+
+// add to hash-table of functions with 'lookup' as the key
 // use when baseType doesn't need a template argument (eg, is a typedef)
 #define addNamedTemplateToRunTimeSelectionTable\
 (baseType,thisType,Targ,argNames,lookup)                                      \
@@ -65,6 +75,11 @@ Description
     baseType::add##argNames##ConstructorToTable<thisType<Targ> >              \
         add_##lookup##_##thisType##Targ##argNames##ConstructorTo##baseType##Table_(#lookup)
 
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+
+// add to hash-table of functions with typename as the key
 // use when baseType requires the Targ template argument as well
 #define addTemplatedToRunTimeSelectionTable\
 (baseType,thisType,Targ,argNames)                                             \
@@ -73,6 +88,8 @@ Description
     baseType<Targ>::add##argNames##ConstructorToTable<thisType<Targ> >        \
         add##thisType##Targ##argNames##ConstructorTo##baseType##Targ##Table_
 
+
+// add to hash-table of functions with 'lookup' as the key
 // use when baseType requires the Targ template argument as well
 #define addNamedTemplatedToRunTimeSelectionTable\
 (baseType,thisType,Targ,argNames,lookup)                                      \
@@ -81,6 +98,7 @@ Description
     baseType<Targ>::add##argNames##ConstructorToTable<thisType<Targ> >        \
         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 f2bad6ae836..45174dd82aa 100644
--- a/src/OpenFOAM/db/runTimeSelection/runTimeSelectionTables.H
+++ b/src/OpenFOAM/db/runTimeSelection/runTimeSelectionTables.H
@@ -40,6 +40,10 @@ Description
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
+
+// external use:
+// ~~~~~~~~~~~~~
+// declare a run-time selection:
 #define declareRunTimeSelectionTable\
 (autoPtr,baseType,argNames,argList,parList)                                   \
                                                                               \
@@ -86,7 +90,10 @@ Description
     static void destroy##argNames##ConstructorTables()
 
 
-#define defineRunTimeSelectionTableConstructor(baseType,argNames)             \
+// internal use:
+// constructor aid
+#define defineRunTimeSelectionTableConstructor\
+(baseType,argNames)                                                           \
                                                                               \
     /* Table constructor called from the table add function */                \
     void baseType::construct##argNames##ConstructorTables()                   \
@@ -102,7 +109,11 @@ Description
         }                                                                     \
     }
 
-#define defineRunTimeSelectionTableDestructor(baseType,argNames)              \
+
+// internal use:
+// destructor aid
+#define defineRunTimeSelectionTableDestructor\
+(baseType,argNames)                                                           \
                                                                               \
     /* Table destructor called from the table add function destructor */      \
     void baseType::destroy##argNames##ConstructorTables()                     \
@@ -114,24 +125,43 @@ Description
         }                                                                     \
     }
 
-#define defineRunTimeSelectionTablePtr(baseType,argNames)                     \
+
+// internal use:
+// create pointer to hash-table of functions
+#define defineRunTimeSelectionTablePtr\
+(baseType,argNames)                                                           \
                                                                               \
     /* Define the constructor function table */                               \
     baseType::argNames##ConstructorTable*                                     \
         baseType::argNames##ConstructorTablePtr_ = NULL
 
+
+// not much in use:
 #define defineTemplateRunTimeSelectionTablePtr(baseType,argNames)             \
                                                                               \
     /* Define the constructor function table */                               \
     typename baseType::argNames##ConstructorTable*                            \
         baseType::argNames##ConstructorTablePtr_ = NULL
 
-#define defineRunTimeSelectionTable(baseType,argNames)                        \
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+
+// external use:
+// ~~~~~~~~~~~~~
+// define run-time selection table
+#define defineRunTimeSelectionTable\
+(baseType,argNames)                        \
                                                                               \
     defineRunTimeSelectionTablePtr(baseType,argNames);                        \
     defineRunTimeSelectionTableConstructor(baseType,argNames)                 \
     defineRunTimeSelectionTableDestructor(baseType,argNames)
 
+
+// external use:
+// ~~~~~~~~~~~~~
+// define run-time selection table for template classes
+// use when baseType doesn't need a template argument (eg, is a typedef)
 #define defineTemplateRunTimeSelectionTable(baseType,argNames)                \
                                                                               \
     template<>                                                                \
@@ -142,6 +172,73 @@ Description
     defineRunTimeSelectionTableDestructor(baseType,argNames)
 
 
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+
+// internal use:
+// constructor aid
+// use when baseType requires the Targ template argument
+#define defineTemplatedRunTimeSelectionTableConstructor\
+(baseType,argNames,Targ)                                                      \
+                                                                              \
+    /* Table constructor called from the table add function */                \
+    void baseType<Targ>::construct##argNames##ConstructorTables()             \
+    {                                                                         \
+        static bool constructed = false;                                      \
+                                                                              \
+        if (!constructed)                                                     \
+        {                                                                     \
+            baseType<Targ>::argNames##ConstructorTablePtr_                    \
+                = new baseType<Targ>::argNames##ConstructorTable;             \
+                                                                              \
+            constructed = true;                                               \
+        }                                                                     \
+    }
+
+
+// internal use:
+// destructor aid
+// use when baseType requires the Targ template argument
+#define defineTemplatedRunTimeSelectionTableDestructor\
+(baseType,argNames,Targ)                                                      \
+                                                                              \
+    /* Table destructor called from the table add function destructor */      \
+    void baseType<Targ>::destroy##argNames##ConstructorTables()               \
+    {                                                                         \
+        if (baseType<Targ>::argNames##ConstructorTablePtr_)                   \
+        {                                                                     \
+            delete baseType<Targ>::argNames##ConstructorTablePtr_;            \
+            baseType<Targ>::argNames##ConstructorTablePtr_ = NULL;            \
+        }                                                                     \
+    }
+
+
+// internal use:
+// create pointer to hash-table of functions
+// use when baseType requires the Targ template argument
+#define defineTemplatedRunTimeSelectionTablePtr\
+(baseType,argNames,Targ)                                                      \
+                                                                              \
+    /* Define the constructor function table */                               \
+    baseType<Targ>::argNames##ConstructorTable*                               \
+        baseType<Targ>::argNames##ConstructorTablePtr_ = NULL
+
+
+// external use:
+// ~~~~~~~~~~~~~
+// define run-time selection table for template classes
+// use when baseType requires the Targ template argument
+#define defineTemplatedRunTimeSelectionTable\
+(baseType,argNames,Targ)                                                      \
+                                                                              \
+    template<>                                                                \
+    defineTemplatedRunTimeSelectionTablePtr(baseType,argNames,Targ);          \
+    template<>                                                                \
+    defineTemplatedRunTimeSelectionTableConstructor(baseType,argNames,Targ)   \
+    template<>                                                                \
+    defineTemplatedRunTimeSelectionTableDestructor(baseType,argNames,Targ)
+
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 #endif
-- 
GitLab