use runtime selection mechanism

This commit is contained in:
mattijs 2009-03-20 18:13:16 +00:00
parent ee3d5243c4
commit 8ef30f0fb8
6 changed files with 24 additions and 76 deletions

View File

@ -30,8 +30,7 @@ Description
#include "arcEdge.H"
#include "mathematicalConstants.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -40,8 +39,7 @@ namespace Foam
defineTypeNameAndDebug(arcEdge, 0);
// Add the curvedEdge constructor functions to the hash tables
curvedEdge::addIstreamConstructorToTable<arcEdge>
addArcEdgeIstreamConstructorToTable_;
addToRunTimeSelectionTable(curvedEdge, arcEdge, Istream);
}

View File

@ -41,26 +41,7 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(curvedEdge, 0);
// Define the constructor function hash tables
HashTable<curvedEdge::IstreamConstructorPtr_>*
curvedEdge::IstreamConstructorTablePtr_;
// Hash table Constructor called from the table add functions.
void curvedEdge::constructTables()
{
static bool constructed = false;
if (!constructed)
{
curvedEdge::IstreamConstructorTablePtr_
= new HashTable<curvedEdge::IstreamConstructorPtr_>;
constructed = true;
}
}
defineRunTimeSelectionTable(curvedEdge, Istream);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -117,10 +98,11 @@ autoPtr<curvedEdge> curvedEdge::New(const pointField& points, Istream& is)
word curvedEdgeType(is);
HashTable<IstreamConstructorPtr_>::iterator curvedEdgeConstructorIter =
IstreamConstructorTablePtr_->find(curvedEdgeType);
IstreamConstructorTable::iterator cstrIter =
IstreamConstructorTablePtr_
->find(curvedEdgeType);
if (curvedEdgeConstructorIter == IstreamConstructorTablePtr_->end())
if (cstrIter == IstreamConstructorTablePtr_->end())
{
FatalErrorIn("curvedEdge::New(const pointField&, Istream&)")
<< "Unknown curvedEdge type " << curvedEdgeType << endl << endl
@ -129,7 +111,7 @@ autoPtr<curvedEdge> curvedEdge::New(const pointField& points, Istream& is)
<< abort(FatalError);
}
return autoPtr<curvedEdge>(curvedEdgeConstructorIter()(points, is));
return autoPtr<curvedEdge>(cstrIter()(points, is));
}
@ -177,7 +159,6 @@ Ostream& operator<<(Ostream& os, const curvedEdge& p)
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam

View File

@ -63,51 +63,23 @@ protected:
public:
// Constructor Hash tables
//- Construct from Istream function pointer type
typedef autoPtr<curvedEdge> (*IstreamConstructorPtr_)
(const pointField&, Istream&);
//- Construct from Istream function pointer table pointer
static HashTable<IstreamConstructorPtr_>*
IstreamConstructorTablePtr_;
//- Runtime type information
TypeName("curvedEdge");
// Hash table constructor classes and functions
// Declare run-time constructor selection tables
//- Hash table Constructor.
// Must be called from the table add functions below.
static void constructTables();
//- Class to add constructor from Istream to Hash table
template<class curvedEdgeType>
class addIstreamConstructorToTable
{
public:
static autoPtr<curvedEdge> New
declareRunTimeSelectionTable
(
autoPtr,
curvedEdge,
Istream,
(
const pointField& points,
Istream& is
)
{
return autoPtr<curvedEdge>(new curvedEdgeType(points, is));
}
addIstreamConstructorToTable()
{
curvedEdge::constructTables();
curvedEdge::IstreamConstructorTablePtr_
->insert(curvedEdgeType::typeName, New);
}
};
//- Runtime type information
TypeName("curvedEdge");
),
(points, is)
);
// Constructors

View File

@ -26,6 +26,7 @@ License
#include "polySplineEdge.H"
#include "BSpline.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -34,8 +35,7 @@ namespace Foam
defineTypeNameAndDebug(polySplineEdge, 0);
// Add the curvedEdge constructor functions to the hash tables
curvedEdge::addIstreamConstructorToTable<polySplineEdge>
addPolySplineEdgeIstreamConstructorToTable_;
addToRunTimeSelectionTable(curvedEdge, polySplineEdge, Istream);
}

View File

@ -92,7 +92,7 @@ public:
);
//- Construct from Istream setting pointsList
polySplineEdge(const pointField& points,Istream& is);
polySplineEdge(const pointField& points, Istream& is);
// Destructor

View File

@ -27,9 +27,8 @@ Description
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "simpleSplineEdge.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -39,10 +38,8 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(simpleSplineEdge, 0);
addToRunTimeSelectionTable(curvedEdge, simpleSplineEdge, Istream);
// Add the curvedEdge constructor functions to the hash tables
curvedEdge::addIstreamConstructorToTable<simpleSplineEdge>
addSimpleSplineEdgeIstreamConstructorToTable_;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //