ENH: add IOobject::isHeaderClassName() method

- in parameter form, check if it headerClassName() corresponds to the
  specified class name

- in templated form, check if headerClassName() corresponds to the
  Type:typeName value.
  Specialization for <void> always returns true (ie, no checks)
This commit is contained in:
Mark Olesen
2018-11-10 16:54:19 +01:00
parent 8562e5278f
commit f44e59fb55
3 changed files with 36 additions and 0 deletions

View File

@ -359,6 +359,16 @@ public:
inline bool& globalObject();
// Checks
//- Test if headerClassName() equals the given class name
inline bool isHeaderClassName(const word& clsName) const;
//- Test if headerClassName() equals Type::typeName
template<class Type>
inline bool isHeaderClassName() const;
// Read/write options
//- The read option
@ -488,6 +498,14 @@ public:
};
//- Specialization for \c void always returns true (no headerClassName check).
template<>
inline bool IOobject::isHeaderClassName<void>() const
{
return true;
}
template<>
Ostream& operator<<(Ostream& os, const InfoProxy<IOobject>& ip);

View File

@ -107,6 +107,21 @@ inline bool& Foam::IOobject::globalObject()
}
// Checks
inline bool Foam::IOobject::isHeaderClassName(const word& clsName) const
{
return (clsName == headerClassName_);
}
template<class Type>
inline bool Foam::IOobject::isHeaderClassName() const
{
return (Type::typeName == headerClassName_);
}
// Read/write options
inline Foam::IOobject::readOption Foam::IOobject::readOpt() const

View File

@ -74,10 +74,13 @@ bool Foam::IOobject::readHeader(Istream& is)
headerDict.get<float>("version")
)
);
is.format(headerDict.get<word>("format"));
headerClassName_ = headerDict.get<word>("class");
const word headerObject(headerDict.get<word>("object"));
if (IOobject::debug && headerObject != name())
{
IOWarningInFunction(is)