runTimeSelection/memberFunctionSelection templated forms

- useful when the baseType isn't a typedef and thus requires the same
   template argument as the derived class
This commit is contained in:
Mark Olesen
2008-11-13 09:44:03 +01:00
parent f9ec26bada
commit 051eee5caa
4 changed files with 137 additions and 98 deletions

View File

@ -38,31 +38,49 @@ Description
#define addToMemberFunctionSelectionTable\ #define addToMemberFunctionSelectionTable\
(baseType,thisType,memberFunction,argNames) \ (baseType,thisType,memberFunction,argNames) \
\ \
/* Add the thisType constructor function to the table */ \ /* Add the thisType memberFunction to the table */ \
baseType::add##memberFunction##argNames##MemberFunctionToTable<thisType> \ baseType::add##memberFunction##argNames##MemberFunctionToTable<thisType> \
add##thisType##memberFunction##argNames##MemberFunctionTo##baseType##Table_ add##thisType##memberFunction##argNames##MemberFunctionTo##baseType##Table_
#define addNamedToMemberFunctionSelectionTable\ #define addNamedToMemberFunctionSelectionTable\
(baseType,thisType,memberFunction,argNames,lookup) \ (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<thisType> \ baseType::add##memberFunction##argNames##MemberFunctionToTable<thisType> \
add_##lookup##_##thisType##memberFunction##argNames##MemberFunctionTo##baseType##Table_(#lookup) add_##lookup##_##thisType##memberFunction##argNames##MemberFunctionTo##baseType##Table_(#lookup)
// use when baseType doesn't need a template argument (eg, is a typedef)
#define addTemplateToMemberFunctionSelectionTable\ #define addTemplateToMemberFunctionSelectionTable\
(baseType,thisType,Targ,memberFunction,argNames) \ (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<thisType<Targ> > \ baseType::add##memberFunction##argNames##MemberFunctionToTable<thisType<Targ> > \
add##thisType##Targ##memberFunction##argNames##MemberFunctionTo##baseType##Table_ add##thisType##Targ##memberFunction##argNames##MemberFunctionTo##baseType##Table_
// use when baseType doesn't need a template argument (eg, is a typedef)
#define addNamedTemplateToMemberFunctionSelectionTable\ #define addNamedTemplateToMemberFunctionSelectionTable\
(baseType,thisType,Targ,memberFunction,argNames,lookup) \ (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<thisType<Targ> > \ baseType::add##memberFunction##argNames##MemberFunctionToTable<thisType<Targ> > \
add_##lookup##_##thisType##Targ##memberFunction##argNames##MemberFunctionTo##baseType##Table_(#lookup) 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<Targ>::add##memberFunction##argNames##MemberFunctionToTable<thisType<Targ> > \
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<Targ>::add##memberFunction##argNames##MemberFunctionToTable<thisType<Targ> > \
add_##lookup##_##thisType##Targ##memberFunction##argNames##MemberFunctionTo##baseType##Targ##Table_(#lookup)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -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(); \ static void construct##memberFunction##argNames##MemberFunctionTables(); \
\ \
/* Table destructor called from the table add function destructor */ \ /* Table destructor called from the table add function destructor */ \
@ -89,7 +89,7 @@ Description
#define defineMemberFunctionSelectionTableMemberFunction\ #define defineMemberFunctionSelectionTableMemberFunction\
(baseType,memberFunction,argNames) \ (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()\ void baseType::construct##memberFunction##argNames##MemberFunctionTables()\
{ \ { \
static bool constructed = false; \ static bool constructed = false; \
@ -119,14 +119,14 @@ Description
#define defineMemberFunctionSelectionTablePtr\ #define defineMemberFunctionSelectionTablePtr\
(baseType,memberFunction,argNames) \ (baseType,memberFunction,argNames) \
\ \
/* Define the constructor function table */ \ /* Define the memberFunction table */ \
baseType::memberFunction##argNames##MemberFunctionTable* \ baseType::memberFunction##argNames##MemberFunctionTable* \
baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL
#define defineTemplateMemberFunctionSelectionTablePtr\ #define defineTemplateMemberFunctionSelectionTablePtr\
(baseType,memberFunction,argNames) \ (baseType,memberFunction,argNames) \
\ \
/* Define the constructor function table */ \ /* Define the memberFunction table */ \
typename baseType::memberFunction##argNames##MemberFunctionTable* \ typename baseType::memberFunction##argNames##MemberFunctionTable* \
baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL

View File

@ -35,31 +35,52 @@ Description
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define addToRunTimeSelectionTable(baseType,thisType,argNames) \ #define addToRunTimeSelectionTable\
(baseType,thisType,argNames) \
\ \
/* Add the thisType constructor function to the table */ \ /* Add the thisType constructor function to the table */ \
baseType::add##argNames##ConstructorToTable<thisType> \ baseType::add##argNames##ConstructorToTable<thisType> \
add##thisType##argNames##ConstructorTo##baseType##Table_ 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<thisType> \ baseType::add##argNames##ConstructorToTable<thisType> \
add_##lookup##_##thisType##argNames##ConstructorTo##baseType##Table_(#lookup) 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 */ \ /* Add the thisType constructor function to the table */ \
baseType::add##argNames##ConstructorToTable<thisType<Targ> > \ baseType::add##argNames##ConstructorToTable<thisType<Targ> > \
add##thisType##Targ##argNames##ConstructorTo##baseType##Table_ add##thisType##Targ##argNames##ConstructorTo##baseType##Table_
// use when baseType doesn't need a template argument (eg, is a typedef)
#define addNamedTemplateToRunTimeSelectionTable\ #define addNamedTemplateToRunTimeSelectionTable\
(baseType,thisType,Targ,argNames,lookup) \ (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<thisType<Targ> > \ baseType::add##argNames##ConstructorToTable<thisType<Targ> > \
add_##lookup##_##thisType##Targ##argNames##ConstructorTo##baseType##Table_(#lookup) 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<Targ>::add##argNames##ConstructorToTable<thisType<Targ> > \
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<Targ>::add##argNames##ConstructorToTable<thisType<Targ> > \
add_##lookup##_##thisType##Targ##argNames##ConstructorTo##baseType##Targ##Table_(#lookup)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif

View File

@ -41,104 +41,104 @@ Description
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define declareRunTimeSelectionTable\ #define declareRunTimeSelectionTable\
(autoPtr,baseType,argNames,argList,parList) \ (autoPtr,baseType,argNames,argList,parList) \
\ \
/* Construct from argList function pointer type */ \ /* Construct from argList function pointer type */ \
typedef autoPtr<baseType> (*argNames##ConstructorPtr)argList; \ typedef autoPtr<baseType> (*argNames##ConstructorPtr)argList; \
\ \
/* Construct from argList function table type */ \ /* Construct from argList function table type */ \
typedef HashTable<argNames##ConstructorPtr, word, string::hash> \ typedef HashTable<argNames##ConstructorPtr, word, string::hash> \
argNames##ConstructorTable; \ argNames##ConstructorTable; \
\ \
/* Construct from argList function pointer table pointer */ \ /* Construct from argList function pointer table pointer */ \
static argNames##ConstructorTable* argNames##ConstructorTablePtr_; \ static argNames##ConstructorTable* argNames##ConstructorTablePtr_; \
\ \
/* Class to add constructor from argList to table */ \ /* Class to add constructor from argList to table */ \
template<class baseType##Type> \ template<class baseType##Type> \
class add##argNames##ConstructorToTable \ class add##argNames##ConstructorToTable \
{ \ { \
public: \ public: \
\ \
static autoPtr<baseType> New argList \ static autoPtr<baseType> New argList \
{ \ { \
return autoPtr<baseType>(new baseType##Type parList); \ return autoPtr<baseType>(new baseType##Type parList); \
} \ } \
\ \
add##argNames##ConstructorToTable \ add##argNames##ConstructorToTable \
( \ ( \
const word& lookup = baseType##Type::typeName \ const word& lookup = baseType##Type::typeName \
) \ ) \
{ \ { \
construct##argNames##ConstructorTables(); \ construct##argNames##ConstructorTables(); \
argNames##ConstructorTablePtr_->insert(lookup, New); \ argNames##ConstructorTablePtr_->insert(lookup, New); \
} \ } \
\ \
~add##argNames##ConstructorToTable() \ ~add##argNames##ConstructorToTable() \
{ \ { \
destroy##argNames##ConstructorTables(); \ destroy##argNames##ConstructorTables(); \
} \ } \
}; \ }; \
\ \
/* Table Constructor called from the table add function */ \ /* Table constructor called from the table add function */ \
static void construct##argNames##ConstructorTables(); \ static void construct##argNames##ConstructorTables(); \
\ \
/* Table destructor called from the table add function destructor */\ /* Table destructor called from the table add function destructor */ \
static void destroy##argNames##ConstructorTables() static void destroy##argNames##ConstructorTables()
#define defineRunTimeSelectionTableConstructor(baseType,argNames) \ #define defineRunTimeSelectionTableConstructor(baseType,argNames) \
\ \
/* Table Constructor called from the table add function */ \ /* Table constructor called from the table add function */ \
void baseType::construct##argNames##ConstructorTables() \ void baseType::construct##argNames##ConstructorTables() \
{ \ { \
static bool constructed = false; \ static bool constructed = false; \
\ \
if (!constructed) \ if (!constructed) \
{ \ { \
baseType::argNames##ConstructorTablePtr_ \ baseType::argNames##ConstructorTablePtr_ \
= new baseType::argNames##ConstructorTable; \ = new baseType::argNames##ConstructorTable; \
\ \
constructed = true; \ constructed = true; \
} \ } \
} }
#define defineRunTimeSelectionTableDestructor(baseType,argNames) \ #define defineRunTimeSelectionTableDestructor(baseType,argNames) \
\ \
/* Table destructor called from the table add function destructor */\ /* Table destructor called from the table add function destructor */ \
void baseType::destroy##argNames##ConstructorTables() \ void baseType::destroy##argNames##ConstructorTables() \
{ \ { \
if (baseType::argNames##ConstructorTablePtr_) \ if (baseType::argNames##ConstructorTablePtr_) \
{ \ { \
delete baseType::argNames##ConstructorTablePtr_; \ delete baseType::argNames##ConstructorTablePtr_; \
baseType::argNames##ConstructorTablePtr_ = NULL; \ baseType::argNames##ConstructorTablePtr_ = NULL; \
} \ } \
} }
#define defineRunTimeSelectionTablePtr(baseType,argNames) \ #define defineRunTimeSelectionTablePtr(baseType,argNames) \
\ \
/* Define the constructor function table */ \ /* Define the constructor function table */ \
baseType::argNames##ConstructorTable* \ baseType::argNames##ConstructorTable* \
baseType::argNames##ConstructorTablePtr_ = NULL baseType::argNames##ConstructorTablePtr_ = NULL
#define defineTemplateRunTimeSelectionTablePtr(baseType,argNames) \ #define defineTemplateRunTimeSelectionTablePtr(baseType,argNames) \
\ \
/* Define the constructor function table */ \ /* Define the constructor function table */ \
typename baseType::argNames##ConstructorTable* \ typename baseType::argNames##ConstructorTable* \
baseType::argNames##ConstructorTablePtr_ = NULL baseType::argNames##ConstructorTablePtr_ = NULL
#define defineRunTimeSelectionTable(baseType,argNames) \ #define defineRunTimeSelectionTable(baseType,argNames) \
\ \
defineRunTimeSelectionTablePtr(baseType,argNames); \ defineRunTimeSelectionTablePtr(baseType,argNames); \
defineRunTimeSelectionTableConstructor(baseType,argNames) \ defineRunTimeSelectionTableConstructor(baseType,argNames) \
defineRunTimeSelectionTableDestructor(baseType,argNames) defineRunTimeSelectionTableDestructor(baseType,argNames)
#define defineTemplateRunTimeSelectionTable(baseType,argNames) \ #define defineTemplateRunTimeSelectionTable(baseType,argNames) \
\ \
template<> \ template<> \
defineRunTimeSelectionTablePtr(baseType,argNames); \ defineRunTimeSelectionTablePtr(baseType,argNames); \
template<> \ template<> \
defineRunTimeSelectionTableConstructor(baseType,argNames) \ defineRunTimeSelectionTableConstructor(baseType,argNames) \
template<> \ template<> \
defineRunTimeSelectionTableDestructor(baseType,argNames) defineRunTimeSelectionTableDestructor(baseType,argNames)