ENH: Added copy/clone functionality tp DataEntry class

This commit is contained in:
andy
2010-10-20 11:03:00 +01:00
parent 16de7dc20b
commit e44efb5130
6 changed files with 62 additions and 43 deletions

View File

@ -31,8 +31,10 @@ template<class Type>
Foam::Constant<Type>::Constant(const word& entryName, Istream& is) Foam::Constant<Type>::Constant(const word& entryName, Istream& is)
: :
DataEntry<Type>(entryName), DataEntry<Type>(entryName),
value_(is) value_(pTraits<Type>::zero)
{} {
is >> value_;
}
template<class Type> template<class Type>
@ -43,22 +45,6 @@ Foam::Constant<Type>::Constant(const Constant<Type>& cnst)
{} {}
template<>
Foam::Constant<Foam::label>::Constant(const word& entryName, Istream& is)
:
DataEntry<label>(entryName),
value_(readLabel(is))
{}
template<>
Foam::Constant<Foam::scalar>::Constant(const word& entryName, Istream& is)
:
DataEntry<scalar>(entryName),
value_(readScalar(is))
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type> template<class Type>

View File

@ -51,11 +51,7 @@ template<class Type>
class Constant; class Constant;
template<class Type> template<class Type>
Ostream& operator<< Ostream& operator<<(Ostream&, const Constant<Type>&);
(
Ostream&,
const Constant<Type>&
);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class Constant Declaration Class Constant Declaration
@ -92,6 +88,12 @@ public:
//- Copy constructor //- Copy constructor
Constant(const Constant<Type>& cnst); Constant(const Constant<Type>& cnst);
//- Construct and return a clone
virtual tmp<DataEntry<Type> > clone() const
{
return tmp<DataEntry<Type> >(new Constant<Type>(*this));
}
//- Destructor //- Destructor
virtual ~Constant(); virtual ~Constant();
@ -107,23 +109,12 @@ public:
//- Ostream Operator //- Ostream Operator
friend Ostream& operator<< <Type> friend Ostream& operator<< <Type>(Ostream&, const Constant<Type>&);
(
Ostream&,
const Constant<Type>&
);
}; };
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<>
Constant<label>::Constant(const word& entryName, Istream& is);
template<>
Constant<scalar>::Constant(const word& entryName, Istream& is);
} // End namespace Foam } // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -30,6 +30,7 @@ License
template<class Type> template<class Type>
Foam::DataEntry<Type>::DataEntry(const word& entryName) Foam::DataEntry<Type>::DataEntry(const word& entryName)
: :
refCount(),
name_(entryName) name_(entryName)
{} {}
@ -37,6 +38,7 @@ Foam::DataEntry<Type>::DataEntry(const word& entryName)
template<class Type> template<class Type>
Foam::DataEntry<Type>::DataEntry(const DataEntry<Type>& de) Foam::DataEntry<Type>::DataEntry(const DataEntry<Type>& de)
: :
refCount(),
name_(de.name_) name_(de.name_)
{} {}
@ -57,6 +59,31 @@ const Foam::word& Foam::DataEntry<Type>::name() const
} }
template<class Type>
Type Foam::DataEntry<Type>::value(const scalar x) const
{
notImplemented("Type Foam::DataEntry<Type>::value(const scalar) const");
return pTraits<Type>::zero;
}
template<class Type>
Type Foam::DataEntry<Type>::integrate(const scalar x1, const scalar x2) const
{
notImplemented
(
"Type Foam::DataEntry<Type>::integrate"
"("
"const scalar, "
"const scalar"
") const"
);
return pTraits<Type>::zero;
}
// * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
#include "DataEntryIO.C" #include "DataEntryIO.C"

View File

@ -62,6 +62,8 @@ Ostream& operator<<
template<class Type> template<class Type>
class DataEntry class DataEntry
:
public refCount
{ {
// Private Member Functions // Private Member Functions
@ -104,6 +106,12 @@ public:
//- Copy constructor //- Copy constructor
DataEntry(const DataEntry<Type>& de); DataEntry(const DataEntry<Type>& de);
//- Construct and return a clone
virtual tmp<DataEntry<Type> > clone() const
{
return tmp<DataEntry<Type> >(new DataEntry<Type>(*this));
}
//- Selector //- Selector
static autoPtr<DataEntry<Type> > New static autoPtr<DataEntry<Type> > New
@ -128,10 +136,10 @@ public:
// Evaluation // Evaluation
//- Return value as a function of (scalar) independent variable //- Return value as a function of (scalar) independent variable
virtual Type value(const scalar x) const = 0; virtual Type value(const scalar x) const;
//- Integrate between two (scalar) values //- Integrate between two (scalar) values
virtual Type integrate(const scalar x1, const scalar x2) const = 0; virtual Type integrate(const scalar x1, const scalar x2) const;
//- Ostream Operator //- Ostream Operator

View File

@ -98,6 +98,12 @@ public:
//- Copy constructor //- Copy constructor
Table(const Table<Type>& tbl); Table(const Table<Type>& tbl);
//- Construct and return a clone
virtual tmp<DataEntry<Type> > clone() const
{
return tmp<DataEntry<Type> >(new Table<Type>(*this));
}
//- Destructor //- Destructor
virtual ~Table(); virtual ~Table();

View File

@ -91,12 +91,17 @@ public:
// Constructors // Constructors
//- Construct from entry name and Istream
polynomial(const word& entryName, Istream& is); polynomial(const word& entryName, Istream& is);
//- Copy constructor //- Copy constructor
polynomial(const polynomial& poly); polynomial(const polynomial& poly);
//- Construct and return a clone
virtual tmp<DataEntry<scalar> > clone() const
{
return tmp<DataEntry<scalar> >(new polynomial(*this));
}
//- Destructor //- Destructor
virtual ~polynomial(); virtual ~polynomial();
@ -112,11 +117,7 @@ public:
//- Ostream Operator //- Ostream Operator
friend Ostream& operator<< friend Ostream& operator<<(Ostream&, const polynomial&);
(
Ostream&,
const polynomial&
);
}; };