Commit 1b9ae829 authored by Andrew Heather's avatar Andrew Heather
Browse files

streamlined input for DataEntry

parent 3b07525b
......@@ -29,38 +29,26 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::Constant<Type>::Constant
(
const word& entryName,
const dictionary& dict
)
Foam::Constant<Type>::Constant(const word& entryName, Istream& is)
:
DataEntry<Type>(typeName, entryName, dict),
value_(this->dict_.lookup("value"))
DataEntry<Type>(entryName),
value_(is)
{}
template<>
Foam::Constant<Foam::label>::Constant
(
const word& entryName,
const dictionary& dict
)
Foam::Constant<Foam::label>::Constant(const word& entryName, Istream& is)
:
DataEntry<label>(typeName, entryName, dict),
value_(readLabel(this->dict_.lookup("value")))
DataEntry<label>(entryName),
value_(readLabel(is))
{}
template<>
Foam::Constant<Foam::scalar>::Constant
(
const word& entryName,
const dictionary& dict
)
Foam::Constant<Foam::scalar>::Constant(const word& entryName, Istream& is)
:
DataEntry<scalar>(typeName, entryName, dict),
value_(readScalar(this->dict_.lookup("value")))
DataEntry<scalar>(entryName),
value_(readScalar(is))
{}
......
......@@ -28,12 +28,9 @@ Class
Description
Templated basic entry that holds a constant value.
Usage - for entry <entryName> having the value <value>:
@verbatim
entry Constant
entryCoeffs
{
value 100.0; // Constant value
}
<entryName> constant <value>
@endverbatim
SourceFiles
......@@ -78,17 +75,13 @@ class Constant
public:
// Runtime type information
TypeName("Constant");
TypeName("constant");
// Constructors
//- Construct from dictionary
Constant
(
const word& entryName,
const dictionary& dict
);
//- Construct from entry name and Istream
Constant(const word& entryName, Istream& is);
//- Destructor
......@@ -108,10 +101,10 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<>
Constant<label>::Constant(const word& entryName, const dictionary& dict);
Constant<label>::Constant(const word& entryName, Istream& is);
template<>
Constant<scalar>::Constant(const word& entryName, const dictionary& dict);
Constant<scalar>::Constant(const word& entryName, Istream& is);
} // End namespace Foam
......
......@@ -29,15 +29,9 @@ License
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::DataEntry<Type>::DataEntry
(
const word& typeName,
const word& entryName,
const dictionary& dict
)
Foam::DataEntry<Type>::DataEntry(const word& entryName)
:
dict_(dict.subDict(entryName + "Coeffs")),
entry_(entryName)
name_(entryName)
{}
......@@ -51,9 +45,9 @@ Foam::DataEntry<Type>::~DataEntry()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
const Foam::dictionary& Foam::DataEntry<Type>::dict() const
const Foam::word& Foam::DataEntry<Type>::name() const
{
return dict_;
return name_;
}
......
......@@ -48,7 +48,7 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class DataEntry Declaration
Class DataEntry Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
......@@ -67,11 +67,8 @@ protected:
// Protected data
//- Coefficients dictionary
const dictionary dict_;
//- Name of entry
const word entry_;
const word name_;
public:
......@@ -87,21 +84,16 @@ public:
dictionary,
(
const word& entryName,
const dictionary& dict
Istream& is
),
(entryName, dict)
(entryName, is)
);
// Constructor
//- Construct from type name and dictionary
DataEntry
(
const word& TypeName,
const word& entryName,
const dictionary& dict
);
//- Construct from entry name
DataEntry(const word& entryName);
//- Selector
......@@ -120,8 +112,8 @@ public:
// Access
//- Return the dictionary
const dictionary& dict() const;
//- Return the name of the entry
const word& name() const;
// Evaluation
......
......@@ -35,27 +35,24 @@ Foam::autoPtr<Foam::DataEntry<Type> > Foam::DataEntry<Type>::New
const dictionary& dict
)
{
word DataEntryType(dict.lookup(entryName));
Istream& is(dict.lookup(entryName));
// Info<< "Selecting DataEntry " << DataEntryType << endl;
word DataEntryType(is);
typename dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(DataEntryType);
if (cstrIter == dictionaryConstructorTablePtr_->end())
{
FatalErrorIn
(
"DataEntry<Type>::New(const dictionary&"
) << "Unknown DataEntry type "
<< DataEntryType << " for " << entryName
<< ", constructor not in hash table" << nl << nl
FatalErrorIn("DataEntry<Type>::New(Istream&)")
<< "Unknown DataEntry type " << DataEntryType << " for DataEntry "
<< entryName << ". Constructor not in hash table" << nl << nl
<< " Valid DataEntry types are :" << nl
<< dictionaryConstructorTablePtr_->toc() << nl
<< exit(FatalError);
}
return autoPtr<DataEntry<Type> >(cstrIter()(entryName, dict));
return autoPtr<DataEntry<Type> >(cstrIter()(entryName, is));
}
......
......@@ -29,26 +29,16 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::Table<Type>::Table
(
const word& entryName,
const dictionary& dict
)
Foam::Table<Type>::Table(const word& entryName, Istream& is)
:
DataEntry<Type>(typeName, entryName, dict),
table_(this->dict_.lookup("table"))
DataEntry<Type>(entryName),
table_(is)
{
if (!table_.size())
{
FatalErrorIn
(
"Foam::Table<Type>::Table\n"
"(\n"
" const word& entryName,\n"
" const dictionary& dict\n"
")\n"
) << "Table is invalid (empty)" << nl
<< exit(FatalError);
FatalErrorIn("Foam::Table<Type>::Table(const Istream&)")
<< "Table for entry " << this->name_ << " is invalid (empty)"
<< nl << exit(FatalError);
}
}
......
......@@ -28,18 +28,14 @@ Class
Description
Templated table container data entry. Items are stored in a list of
Tuple2's. First column is always stored as scalar entries. Data is read
in the form, e.g. for (scalar, vector):
in the form, e.g. for an entry <entryName> that is (scalar, vector):
@verbatim
entry Table
entryCoeffs
{
table
(
0.0 (1 2 3)
1.0 (4 5 6)
)
}
<entryName> table
(
0.0 (1 2 3)
1.0 (4 5 6)
);
@endverbatim
SourceFiles
......@@ -85,13 +81,13 @@ class Table
public:
//- Runtime type information
TypeName("Table");
TypeName("table");
// Constructors
//- Construct from dictionary
Table(const word& entryName, const dictionary& dict);
//- Construct from entry name and Istream
Table(const word& entryName, Istream& is);
//- Destructor
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment