Commit 9c8432a0 authored by Mark Olesen's avatar Mark Olesen
Browse files

regIOobject: make checkIn(), checkOut() return bool

parent 507ad1e6
......@@ -107,6 +107,7 @@ Foam::regIOobject::~regIOobject()
if (isPtr_)
{
delete isPtr_;
isPtr_ = NULL;
}
// Check out of objectRegistry if not owned by the registry
......@@ -120,47 +121,47 @@ Foam::regIOobject::~regIOobject()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::regIOobject::checkIn()
bool Foam::regIOobject::checkIn()
{
if (!registered_)
{
// Attempt to register object with objectRegistry
if (!db().checkIn(*this))
// multiple checkin of same object is disallowed - this would mess up
// any mapping
registered_ = db().checkIn(*this);
// checkin on defaultRegion is allowed to fail, since subsetted meshes
// are created with the same name as their originating mesh
if (!registered_ && debug && name() != polyMesh::defaultRegion)
{
// Disallow checkin of same object twice since would mess up
// any mapping.
// Check on defaultRegion is needed to prevent subsetted meshes
// (which are created with same name as their originating mesh)
// from upsetting this.
if (debug && name() != polyMesh::defaultRegion)
{
WarningIn("regIOobject::checkIn()")
<< "failed to register object " << objectPath()
WarningIn("regIOobject::checkIn()")
<< "failed to register object " << objectPath()
<< " the name already exists in the objectRegistry"
<< endl;
}
}
else
{
registered_ = true;
<< endl;
}
}
return registered_;
}
void Foam::regIOobject::checkOut()
bool Foam::regIOobject::checkOut()
{
if (registered_)
{
db().checkOut(*this);
registered_ = false;
return db().checkOut(*this);
}
return false;
}
// Rename object and re-register with objectRegistry under new name
void Foam::regIOobject::rename(const word& newName)
{
// TODO: verify that this works properly with unregistered objects
// I suspect that it incorrectly registers them
// Check out of objectRegistry
checkOut();
......
......@@ -49,7 +49,7 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class regIOobject Declaration
Class regIOobject Declaration
\*---------------------------------------------------------------------------*/
class regIOobject
......@@ -115,13 +115,13 @@ public:
// Registration
//- Register object with registry
void checkIn();
//- Add object to registry
bool checkIn();
//- Check-out object from registry
void checkOut();
//- Remove object from registry
bool checkOut();
//- Is this object owned by the registry
//- Is this object owned by the registry?
inline bool ownedByRegistry() const;
//- Transfer ownership of this object to its registry
......@@ -130,12 +130,12 @@ public:
//- Transfer ownership of the given object pointer to its registry
// and return reference to object.
template<class Type>
inline static Type& store(Type* tPtr);
inline static Type& store(Type*);
//- Transfer ownership of the given object pointer to its registry
// and return reference to object.
template<class Type>
inline static Type& store(autoPtr<Type>& atPtr);
inline static Type& store(autoPtr<Type>&);
//- Release ownership of this object from its registry
inline void release();
......@@ -179,9 +179,9 @@ public:
//- Write using given format, version and compression
virtual bool writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp
IOstream::streamFormat,
IOstream::versionNumber,
IOstream::compressionType
) const;
//- Write using setting from DB
......
......@@ -43,7 +43,7 @@ inline Type& Foam::regIOobject::store(Type* tPtr)
{
if (!tPtr)
{
FatalErrorIn("Type& store(Type*)")
FatalErrorIn("Type& regIOobject::store(Type*)")
<< "object deallocated"
<< abort(FatalError);
}
......@@ -63,13 +63,13 @@ inline Type& Foam::regIOobject::store(autoPtr<Type>& atPtr)
{
FatalErrorIn
(
"Type& store(autoPtr<Type>&)"
"Type& regIOobject::store(autoPtr<Type>&)"
) << "object deallocated"
<< abort(FatalError);
}
tPtr->regIOobject::ownedByRegistry_ = true;
return *tPtr;
}
......
......@@ -91,7 +91,7 @@ bool regIOobject::writeObject
// Try opening an OFstream for object
OFstream os(objectPath(), fmt, ver, cmp);
// If this has failed, return (leave error handling to Ostream class)
// If any of these fail, return (leave error handling to Ostream class)
if (!os.good())
{
return false;
......@@ -108,7 +108,8 @@ bool regIOobject::writeObject
return false;
}
os << "\n\n// ************************************************************************* //"
os << "\n\n"
"// ************************************************************************* //"
<< endl;
osGood = os.good();
......
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