Commit 7e9846a5 authored by Mark Olesen's avatar Mark Olesen
Browse files

IOobjects - consistency fixes

  - consistent constructors and consistent behaviour with MUST_READ,
    READ_IF_PRESENT
parent 56296e89
......@@ -155,7 +155,7 @@ protected:
// Protected member functions
//- Construct and return an IFstream for the object.
// The results is NULL if the stream constuction failed
// The results is NULL if the stream construction failed
Istream* objectStream();
//- Set the object state to bad
......
......@@ -29,53 +29,93 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::IOField<Type>::IOField
(
const IOobject& io
)
Foam::IOField<Type>::IOField(const IOobject& io)
:
regIOobject(io),
Field<Type>(readStream(typeName))
regIOobject(io)
{
close();
if
(
io.readOpt() == IOobject::MUST_READ
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
)
{
readStream(typeName) >> *this;
close();
}
}
template<class Type>
Foam::IOField<Type>::IOField
(
const IOobject& io,
const label size
)
Foam::IOField<Type>::IOField(const IOobject& io, const label size)
:
regIOobject(io),
Field<Type>(size)
{}
regIOobject(io)
{
if
(
io.readOpt() == IOobject::MUST_READ
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
)
{
readStream(typeName) >> *this;
close();
}
else
{
Field<Type>::setSize(size);
}
}
template<class Type>
Foam::IOField<Type>::IOField
(
const IOobject& io,
const Field<Type>& f
)
Foam::IOField<Type>::IOField(const IOobject& io, const Field<Type>& f)
:
regIOobject(io),
Field<Type>(f)
regIOobject(io)
{
if (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
if
(
io.readOpt() == IOobject::MUST_READ
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
)
{
readStream(typeName) >> *this;
close();
}
else
{
Field<Type>::operator=(f);
}
}
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
template<class T>
Foam::IOField<T>::~IOField()
template<class Type>
Foam::IOField<Type>::~IOField()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
bool Foam::IOField<Type>::writeData(Ostream& os) const
{
return (os << static_cast<const Field<Type>&>(*this)).good();
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Type>
void Foam::IOField<Type>::operator=(const IOField<Type>& rhs)
{
Field<Type>::operator=(rhs);
}
template<class Type>
void Foam::IOField<Type>::operator=(const Field<Type>& rhs)
{
Field<Type>::operator=(rhs);
}
// ************************************************************************* //
......@@ -63,24 +63,13 @@ public:
// Constructors
//- Construct from IOobject
IOField
(
const IOobject&
);
IOField(const IOobject&);
//- Construct from components
IOField
(
const IOobject&,
const Field<Type>&
);
IOField(const IOobject&, const Field<Type>&);
//- Construct from IOobject and size (does not set values)
IOField
(
const IOobject&,
const label size
);
IOField(const IOobject&, const label size);
// Destructor
......@@ -90,23 +79,14 @@ public:
// Member functions
bool writeData(Ostream& os) const
{
return (os << static_cast<const Field<Type>&>(*this)).good();
}
bool writeData(Ostream&) const;
// Member operators
void operator=(const IOField<Type>& iof)
{
Field<Type>::operator=(iof);
}
void operator=(const IOField<Type>&);
void operator=(const Field<Type>& f)
{
Field<Type>::operator=(f);
}
void operator=(const Field<Type>&);
};
......
......@@ -84,7 +84,6 @@ Foam::IOList<T>::IOList(const IOobject& io, const List<T>& list)
{
List<T>::operator=(list);
}
}
......@@ -95,26 +94,29 @@ Foam::IOList<T>::~IOList()
{}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
void Foam::IOList<T>::operator=(const IOList<T>& rhs)
bool Foam::IOList<T>::writeData(Ostream& os) const
{
List<T>::operator=(rhs);
return (os << *this).good();
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
void Foam::IOList<T>::operator=(const List<T>& rhs)
void Foam::IOList<T>::operator=(const IOList<T>& rhs)
{
List<T>::operator=(rhs);
}
template<class T>
bool Foam::IOList<T>::writeData(Ostream& os) const
void Foam::IOList<T>::operator=(const List<T>& rhs)
{
return (os << *this).good();
List<T>::operator=(rhs);
}
......
......@@ -31,8 +31,7 @@ License
template<class T>
Foam::IOMap<T>::IOMap(const IOobject& io)
:
regIOobject(io),
Map<T>()
regIOobject(io)
{
if
(
......
......@@ -91,20 +91,21 @@ Foam::IOPtrList<T>::~IOPtrList()
{}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
void Foam::IOPtrList<T>::operator=(const IOPtrList<T>& rhs)
bool Foam::IOPtrList<T>::writeData(Ostream& os) const
{
PtrList<T>::operator=(rhs);
return (os << *this).good();
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
bool Foam::IOPtrList<T>::writeData(Ostream& os) const
void Foam::IOPtrList<T>::operator=(const IOPtrList<T>& rhs)
{
return (os << *this).good();
PtrList<T>::operator=(rhs);
}
// ************************************************************************* //
......@@ -42,15 +42,10 @@ namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::IOdictionary::IOdictionary
(
const IOobject& io
)
Foam::IOdictionary::IOdictionary(const IOobject& io)
:
regIOobject(io)
{
dictionary::name() = IOobject::objectPath();
if
(
io.readOpt() == IOobject::MUST_READ
......@@ -60,18 +55,29 @@ Foam::IOdictionary::IOdictionary
readStream(typeName) >> *this;
close();
}
dictionary::name() = IOobject::objectPath();
}
Foam::IOdictionary::IOdictionary
(
const IOobject& io,
const dictionary& dict
)
Foam::IOdictionary::IOdictionary(const IOobject& io, const dictionary& dict)
:
regIOobject(io),
dictionary(dict)
regIOobject(io)
{
if
(
io.readOpt() == IOobject::MUST_READ
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
)
{
readStream(typeName) >> *this;
close();
}
else
{
dictionary::operator=(dict);
}
dictionary::name() = IOobject::objectPath();
}
......@@ -92,9 +98,9 @@ const Foam::word& Foam::IOdictionary::name() const
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void Foam::IOdictionary::operator=(const IOdictionary& d)
void Foam::IOdictionary::operator=(const IOdictionary& rhs)
{
dictionary::operator=(d);
dictionary::operator=(rhs);
}
......
......@@ -34,27 +34,17 @@ Description
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
bool IOdictionary::readData(Istream& is)
bool Foam::IOdictionary::readData(Istream& is)
{
is >> *this;
return !is.bad();
}
bool IOdictionary::writeData(Ostream& os) const
bool Foam::IOdictionary::writeData(Ostream& os) const
{
dictionary::write(os, false);
return os.good();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
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