Commit d1387a85 authored by Henry Weller's avatar Henry Weller
Browse files

DataEntry: Created the DataEntryTypes namespace for all the concrete DataEntry types

to avoid name conflicts with these primitive names in the OpenFOAM namespace
parent e9a28482
......@@ -135,7 +135,7 @@ int main(int argc, char *argv[])
#include "createFields.H"
Info<< "Reading data file" << endl;
CSV<scalar> pData("pressure", dict, "Data");
DataEntryTypes::CSV<scalar> pData("pressure", dict, "Data");
// time history data
const scalarField t(pData.x());
......
......@@ -29,63 +29,67 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
namespace Foam
template<>
Foam::label Foam::DataEntryTypes::CSV<Foam::label>::readValue
(
const List<string>& splitted
)
{
template<>
label CSV<label>::readValue(const List<string>& splitted)
if (componentColumns_[0] >= splitted.size())
{
if (componentColumns_[0] >= splitted.size())
{
FatalErrorInFunction
<< "No column " << componentColumns_[0] << " in "
<< splitted << endl
<< exit(FatalError);
}
FatalErrorInFunction
<< "No column " << componentColumns_[0] << " in "
<< splitted << endl
<< exit(FatalError);
}
return readLabel(IStringStream(splitted[componentColumns_[0]])());
}
return readLabel(IStringStream(splitted[componentColumns_[0]])());
template<>
Foam::scalar Foam::DataEntryTypes::CSV<Foam::scalar>::readValue
(
const List<string>& splitted
)
{
if (componentColumns_[0] >= splitted.size())
{
FatalErrorInFunction
<< "No column " << componentColumns_[0] << " in "
<< splitted << endl
<< exit(FatalError);
}
template<>
scalar CSV<scalar>::readValue(const List<string>& splitted)
return readScalar(IStringStream(splitted[componentColumns_[0]])());
}
template<class Type>
Type Foam::DataEntryTypes::CSV<Type>::readValue(const List<string>& splitted)
{
Type result;
for (label i = 0; i < pTraits<Type>::nComponents; i++)
{
if (componentColumns_[0] >= splitted.size())
if (componentColumns_[i] >= splitted.size())
{
FatalErrorInFunction
<< "No column " << componentColumns_[0] << " in "
<< "No column " << componentColumns_[i] << " in "
<< splitted << endl
<< exit(FatalError);
}
return readScalar(IStringStream(splitted[componentColumns_[0]])());
result[i] =
readScalar(IStringStream(splitted[componentColumns_[i]])());
}
template<class Type>
Type CSV<Type>::readValue(const List<string>& splitted)
{
Type result;
for (label i = 0; i < pTraits<Type>::nComponents; i++)
{
if (componentColumns_[i] >= splitted.size())
{
FatalErrorInFunction
<< "No column " << componentColumns_[i] << " in "
<< splitted << endl
<< exit(FatalError);
}
result[i] =
readScalar(IStringStream(splitted[componentColumns_[i]])());
}
return result;
}
return result;
}
template<class Type>
void Foam::CSV<Type>::read()
void Foam::DataEntryTypes::CSV<Type>::read()
{
fileName expandedFile(fName_);
IFstream is(expandedFile.expand());
......@@ -196,7 +200,7 @@ void Foam::CSV<Type>::read()
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::CSV<Type>::CSV
Foam::DataEntryTypes::CSV<Type>::CSV
(
const word& entryName,
const dictionary& dict,
......@@ -227,7 +231,7 @@ Foam::CSV<Type>::CSV
template<class Type>
Foam::CSV<Type>::CSV(const CSV<Type>& tbl)
Foam::DataEntryTypes::CSV<Type>::CSV(const CSV<Type>& tbl)
:
TableBase<Type>(tbl),
nHeaderLine_(tbl.nHeaderLine_),
......@@ -242,14 +246,14 @@ Foam::CSV<Type>::CSV(const CSV<Type>& tbl)
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::CSV<Type>::~CSV()
Foam::DataEntryTypes::CSV<Type>::~CSV()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
const Foam::fileName& Foam::CSV<Type>::fName() const
const Foam::fileName& Foam::DataEntryTypes::CSV<Type>::fName() const
{
return fName_;
}
......
......@@ -62,15 +62,17 @@ SourceFiles
namespace Foam
{
template<class Type>
class CSV;
// Forward declaration of friend functions and operators
namespace DataEntryTypes
{
template<class Type> class CSV;
};
template<class Type>
Ostream& operator<<
(
Ostream&,
const CSV<Type>&
);
Ostream& operator<<(Ostream&, const DataEntryTypes::CSV<Type>&);
namespace DataEntryTypes
{
/*---------------------------------------------------------------------------*\
Class CSV Declaration
......@@ -169,8 +171,16 @@ public:
};
template<>
label CSV<label>::readValue(const List<string>& splitted);
template<>
Foam::scalar CSV<scalar>::readValue(const List<string>& splitted);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace DataEntryTypes
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -31,7 +31,7 @@ template<class Type>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const CSV<Type>& tbl
const DataEntryTypes::CSV<Type>& tbl
)
{
os << static_cast<const DataEntry<Type>& >(tbl)
......@@ -50,7 +50,7 @@ Foam::Ostream& Foam::operator<<
template<class Type>
void Foam::CSV<Type>::writeData(Ostream& os) const
void Foam::DataEntryTypes::CSV<Type>::writeData(Ostream& os) const
{
DataEntry<Type>::writeData(os);
os << token::END_STATEMENT << nl;
......
......@@ -28,7 +28,11 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::Constant<Type>::Constant(const word& entryName, const dictionary& dict)
Foam::DataEntryTypes::Constant<Type>::Constant
(
const word& entryName,
const dictionary& dict
)
:
DataEntry<Type>(entryName),
value_(pTraits<Type>::zero)
......@@ -40,7 +44,11 @@ Foam::Constant<Type>::Constant(const word& entryName, const dictionary& dict)
template<class Type>
Foam::Constant<Type>::Constant(const word& entryName, Istream& is)
Foam::DataEntryTypes::Constant<Type>::Constant
(
const word& entryName,
Istream& is
)
:
DataEntry<Type>(entryName),
value_(pTraits<Type>(is))
......@@ -48,7 +56,7 @@ Foam::Constant<Type>::Constant(const word& entryName, Istream& is)
template<class Type>
Foam::Constant<Type>::Constant(const Constant<Type>& cnst)
Foam::DataEntryTypes::Constant<Type>::Constant(const Constant<Type>& cnst)
:
DataEntry<Type>(cnst),
value_(cnst.value_)
......@@ -58,21 +66,25 @@ Foam::Constant<Type>::Constant(const Constant<Type>& cnst)
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::Constant<Type>::~Constant()
Foam::DataEntryTypes::Constant<Type>::~Constant()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Type Foam::Constant<Type>::value(const scalar x) const
Type Foam::DataEntryTypes::Constant<Type>::value(const scalar x) const
{
return value_;
}
template<class Type>
Type Foam::Constant<Type>::integrate(const scalar x1, const scalar x2) const
Type Foam::DataEntryTypes::Constant<Type>::integrate
(
const scalar x1,
const scalar x2
) const
{
return (x2 - x1)*value_;
}
......
......@@ -48,8 +48,16 @@ namespace Foam
{
// Forward declaration of friend functions and operators
template<class Type> class Constant;
template<class Type> Ostream& operator<<(Ostream&, const Constant<Type>&);
namespace DataEntryTypes
{
template<class Type> class Constant;
};
template<class Type>
Ostream& operator<<(Ostream&, const DataEntryTypes::Constant<Type>&);
namespace DataEntryTypes
{
/*---------------------------------------------------------------------------*\
Class Constant Declaration
......@@ -127,6 +135,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace DataEntryTypes
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -31,7 +31,7 @@ template<class Type>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const Constant<Type>& cnst
const DataEntryTypes::Constant<Type>& cnst
)
{
os << static_cast<const DataEntry<Type>& >(cnst)
......@@ -48,7 +48,7 @@ Foam::Ostream& Foam::operator<<
template<class Type>
void Foam::Constant<Type>::writeData(Ostream& os) const
void Foam::DataEntryTypes::Constant<Type>::writeData(Ostream& os) const
{
DataEntry<Type>::writeData(os);
......
......@@ -189,9 +189,9 @@ public:
#define makeDataEntryType(SS, Type) \
\
defineNamedTemplateTypeNameAndDebug(SS<Type>, 0); \
defineNamedTemplateTypeNameAndDebug(DataEntryTypes::SS<Type>, 0); \
\
DataEntry<Type>::adddictionaryConstructorToTable<SS<Type>> \
DataEntry<Type>::adddictionaryConstructorToTable<DataEntryTypes::SS<Type>> \
add##SS##Type##ConstructorToTable_;
......
......@@ -42,7 +42,10 @@ Foam::autoPtr<Foam::DataEntry<Type>> Foam::DataEntry<Type>::New
if (!firstToken.isWord())
{
is.putBack(firstToken);
return autoPtr<DataEntry<Type>>(new Constant<Type>(entryName, is));
return autoPtr<DataEntry<Type>>
(
new DataEntryTypes::Constant<Type>(entryName, is)
);
}
else
{
......
......@@ -28,7 +28,7 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::PolynomialEntry<Type>::PolynomialEntry
Foam::DataEntryTypes::Polynomial<Type>::Polynomial
(
const word& entryName,
const dictionary& dict
......@@ -46,7 +46,7 @@ Foam::PolynomialEntry<Type>::PolynomialEntry
if (!coeffs_.size())
{
FatalErrorInFunction
<< "PolynomialEntry coefficients for entry " << this->name_
<< "Polynomial coefficients for entry " << this->name_
<< " are invalid (empty)" << nl << exit(FatalError);
}
......@@ -64,7 +64,7 @@ Foam::PolynomialEntry<Type>::PolynomialEntry
if (!canIntegrate_)
{
WarningInFunction
<< "PolynomialEntry " << this->name_ << " cannot be integrated"
<< "Polynomial " << this->name_ << " cannot be integrated"
<< endl;
}
}
......@@ -72,7 +72,7 @@ Foam::PolynomialEntry<Type>::PolynomialEntry
template<class Type>
Foam::PolynomialEntry<Type>::PolynomialEntry
Foam::DataEntryTypes::Polynomial<Type>::Polynomial
(
const word& entryName,
const List<Tuple2<Type, Type>>& coeffs
......@@ -85,7 +85,7 @@ Foam::PolynomialEntry<Type>::PolynomialEntry
if (!coeffs_.size())
{
FatalErrorInFunction
<< "PolynomialEntry coefficients for entry " << this->name_
<< "Polynomial coefficients for entry " << this->name_
<< " are invalid (empty)" << nl << exit(FatalError);
}
......@@ -103,7 +103,7 @@ Foam::PolynomialEntry<Type>::PolynomialEntry
if (!canIntegrate_)
{
WarningInFunction
<< "PolynomialEntry " << this->name_ << " cannot be integrated"
<< "Polynomial " << this->name_ << " cannot be integrated"
<< endl;
}
}
......@@ -111,7 +111,7 @@ Foam::PolynomialEntry<Type>::PolynomialEntry
template<class Type>
Foam::PolynomialEntry<Type>::PolynomialEntry(const PolynomialEntry& poly)
Foam::DataEntryTypes::Polynomial<Type>::Polynomial(const Polynomial& poly)
:
DataEntry<Type>(poly),
coeffs_(poly.coeffs_),
......@@ -122,14 +122,14 @@ Foam::PolynomialEntry<Type>::PolynomialEntry(const PolynomialEntry& poly)
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::PolynomialEntry<Type>::~PolynomialEntry()
Foam::DataEntryTypes::Polynomial<Type>::~Polynomial()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::PolynomialEntry<Type>::convertTimeBase(const Time& t)
void Foam::DataEntryTypes::Polynomial<Type>::convertTimeBase(const Time& t)
{
forAll(coeffs_, i)
{
......@@ -144,7 +144,7 @@ void Foam::PolynomialEntry<Type>::convertTimeBase(const Time& t)
template<class Type>
Type Foam::PolynomialEntry<Type>::value(const scalar x) const
Type Foam::DataEntryTypes::Polynomial<Type>::value(const scalar x) const
{
Type y(pTraits<Type>::zero);
forAll(coeffs_, i)
......@@ -161,7 +161,7 @@ Type Foam::PolynomialEntry<Type>::value(const scalar x) const
template<class Type>
Type Foam::PolynomialEntry<Type>::integrate
Type Foam::DataEntryTypes::Polynomial<Type>::integrate
(
const scalar x1,
const scalar x2
......
......@@ -55,22 +55,29 @@ namespace Foam
{
// Forward declaration of friend functions and operators
template<class Type> class PolynomialEntry;
namespace DataEntryTypes
{
template<class Type> class Polynomial;
};
template<class Type>
Ostream& operator<<(Ostream&, const PolynomialEntry<Type>&);
Ostream& operator<<(Ostream&, const DataEntryTypes::Polynomial<Type>&);
namespace DataEntryTypes
{
/*---------------------------------------------------------------------------*\
Class PolynomialEntry Declaration
Class Polynomial Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class PolynomialEntry
class Polynomial
:
public DataEntry<Type>
{
// Private data
//- PolynomialEntry coefficients - list of prefactor, exponent
//- Polynomial coefficients - list of prefactor, exponent
List<Tuple2<Type, Type>> coeffs_;
//- Flag to indicate whether poly can be integrated
......@@ -80,7 +87,7 @@ class PolynomialEntry
// Private Member Functions
//- Disallow default bitwise assignment
void operator=(const PolynomialEntry<Type>&);
void operator=(const Polynomial<Type>&);
public:
......@@ -91,27 +98,27 @@ public:
// Constructors
PolynomialEntry(const word& entryName, const dictionary& dict);
Polynomial(const word& entryName, const dictionary& dict);
//- Construct from components
PolynomialEntry
Polynomial
(
const word& entryName,
const List<Tuple2<Type, Type>>&
);
//- Copy constructor
PolynomialEntry(const PolynomialEntry& poly);
Polynomial(const Polynomial& poly);
//- Construct and return a clone
virtual tmp<DataEntry<Type>> clone() const
{
return tmp<DataEntry<Type>>(new PolynomialEntry(*this));
return tmp<DataEntry<Type>>(new Polynomial(*this));
}
//- Destructor
virtual ~PolynomialEntry();
virtual ~Polynomial();
// Member Functions
......@@ -124,7 +131,7 @@ public:
// Evaluation
//- Return PolynomialEntry value
//- Return Polynomial value
Type value(const scalar x) const;
//- Integrate between two (scalar) values
......@@ -137,7 +144,7 @@ public:
friend Ostream& operator<< <Type>
(
Ostream& os,
const PolynomialEntry<Type>& cnst
const Polynomial<Type>& cnst
);
//- Write in dictionary format
......@@ -147,6 +154,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace DataEntryTypes
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -31,7 +31,7 @@ template<class Type>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const PolynomialEntry<Type>& poly
const DataEntryTypes::Polynomial<Type>& poly
)
{
os << static_cast<const DataEntry<Type>& >(poly)
......@@ -40,7 +40,7 @@ Foam::Ostream& Foam::operator<<
// Check state of Ostream
os.check
(
"Ostream& operator<<(Ostream&, const PolynomialEntry&)"
"Ostream& operator<<(Ostream&, const Polynomial&)"
);
return os;
......@@ -48,7 +48,7 @@ Foam::Ostream& Foam::operator<<
template<class Type>
void Foam::PolynomialEntry<Type>::writeData(Ostream& os) const
void Foam::DataEntryTypes::Polynomial<Type>::writeData(Ostream& os) const
{
DataEntry<Type>::writeData(os);
......
......@@ -28,7 +28,11 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::Table<Type>::Table(const word& entryName, const dictionary& dict)
Foam::DataEntryTypes::Table<Type>::Table
(
const word& entryName,
const dictionary& dict
)
:
TableBase<Type>(entryName, dict)
{
......@@ -40,7 +44,7 @@ Foam::Table<Type>::Table(const word& entryName, const dictionary& dict)
template<class Type>
Foam::Table<Type>::Table(const Table<Type>& tbl)
Foam::DataEntryTypes::Table<Type>::Table(const Table<Type>& tbl)
:
TableBase<Type>(tbl)
{}
......@@ -49,7 +53,7 @@ Foam::Table<Type>::Table(const Table<Type>& tbl)
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::Table<Type>::~Table()
Foam::DataEntryTypes::Table<Type>::~Table()
{}