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() ...@@ -107,6 +107,7 @@ Foam::regIOobject::~regIOobject()
if (isPtr_) if (isPtr_)
{ {
delete isPtr_; delete isPtr_;
isPtr_ = NULL;
} }
// Check out of objectRegistry if not owned by the registry // Check out of objectRegistry if not owned by the registry
...@@ -120,47 +121,47 @@ Foam::regIOobject::~regIOobject() ...@@ -120,47 +121,47 @@ Foam::regIOobject::~regIOobject()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::regIOobject::checkIn() bool Foam::regIOobject::checkIn()
{ {
if (!registered_) if (!registered_)
{ {
// Attempt to register object with objectRegistry // multiple checkin of same object is disallowed - this would mess up
if (!db().checkIn(*this)) // 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 WarningIn("regIOobject::checkIn()")
// any mapping. << "failed to register object " << objectPath()
// 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()
<< " the name already exists in the objectRegistry" << " the name already exists in the objectRegistry"
<< endl; << endl;
}
}
else
{
registered_ = true;
} }
} }
return registered_;
} }
void Foam::regIOobject::checkOut() bool Foam::regIOobject::checkOut()
{ {
if (registered_) if (registered_)
{ {
db().checkOut(*this);
registered_ = false; registered_ = false;
return db().checkOut(*this);
} }
return false;
} }
// Rename object and re-register with objectRegistry under new name // Rename object and re-register with objectRegistry under new name
void Foam::regIOobject::rename(const word& newName) 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 // Check out of objectRegistry
checkOut(); checkOut();
......
...@@ -49,7 +49,7 @@ namespace Foam ...@@ -49,7 +49,7 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class regIOobject Declaration Class regIOobject Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class regIOobject class regIOobject
...@@ -115,13 +115,13 @@ public: ...@@ -115,13 +115,13 @@ public:
// Registration // Registration
//- Register object with registry //- Add object to registry
void checkIn(); bool checkIn();
//- Check-out object from registry //- Remove object from registry
void checkOut(); bool checkOut();
//- Is this object owned by the registry //- Is this object owned by the registry?
inline bool ownedByRegistry() const; inline bool ownedByRegistry() const;
//- Transfer ownership of this object to its registry //- Transfer ownership of this object to its registry
...@@ -130,12 +130,12 @@ public: ...@@ -130,12 +130,12 @@ public:
//- Transfer ownership of the given object pointer to its registry //- Transfer ownership of the given object pointer to its registry
// and return reference to object. // and return reference to object.
template<class Type> template<class Type>
inline static Type& store(Type* tPtr); inline static Type& store(Type*);
//- Transfer ownership of the given object pointer to its registry //- Transfer ownership of the given object pointer to its registry
// and return reference to object. // and return reference to object.
template<class Type> template<class Type>
inline static Type& store(autoPtr<Type>& atPtr); inline static Type& store(autoPtr<Type>&);
//- Release ownership of this object from its registry //- Release ownership of this object from its registry
inline void release(); inline void release();
...@@ -179,9 +179,9 @@ public: ...@@ -179,9 +179,9 @@ public:
//- Write using given format, version and compression //- Write using given format, version and compression
virtual bool writeObject virtual bool writeObject
( (
IOstream::streamFormat fmt, IOstream::streamFormat,
IOstream::versionNumber ver, IOstream::versionNumber,
IOstream::compressionType cmp IOstream::compressionType
) const; ) const;
//- Write using setting from DB //- Write using setting from DB
......
...@@ -43,7 +43,7 @@ inline Type& Foam::regIOobject::store(Type* tPtr) ...@@ -43,7 +43,7 @@ inline Type& Foam::regIOobject::store(Type* tPtr)
{ {
if (!tPtr) if (!tPtr)
{ {
FatalErrorIn("Type& store(Type*)") FatalErrorIn("Type& regIOobject::store(Type*)")
<< "object deallocated" << "object deallocated"
<< abort(FatalError); << abort(FatalError);
} }
...@@ -63,13 +63,13 @@ inline Type& Foam::regIOobject::store(autoPtr<Type>& atPtr) ...@@ -63,13 +63,13 @@ inline Type& Foam::regIOobject::store(autoPtr<Type>& atPtr)
{ {
FatalErrorIn FatalErrorIn
( (
"Type& store(autoPtr<Type>&)" "Type& regIOobject::store(autoPtr<Type>&)"
) << "object deallocated" ) << "object deallocated"
<< abort(FatalError); << abort(FatalError);
} }
tPtr->regIOobject::ownedByRegistry_ = true; tPtr->regIOobject::ownedByRegistry_ = true;
return *tPtr; return *tPtr;
} }
......
...@@ -91,7 +91,7 @@ bool regIOobject::writeObject ...@@ -91,7 +91,7 @@ bool regIOobject::writeObject
// Try opening an OFstream for object // Try opening an OFstream for object
OFstream os(objectPath(), fmt, ver, cmp); 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()) if (!os.good())
{ {
return false; return false;
...@@ -108,7 +108,8 @@ bool regIOobject::writeObject ...@@ -108,7 +108,8 @@ bool regIOobject::writeObject
return false; return false;
} }
os << "\n\n// ************************************************************************* //" os << "\n\n"
"// ************************************************************************* //"
<< endl; << endl;
osGood = os.good(); 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