dbertoni 00/07/25 07:48:14
Modified: c/src/XPath XObjectFactory.hpp
Log:
Enhancements to XObjectGuard.
Revision Changes Path
1.7 +51 -4 xml-xalan/c/src/XPath/XObjectFactory.hpp
Index: XObjectFactory.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XObjectFactory.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XObjectFactory.hpp 2000/07/12 21:46:51 1.6
+++ XObjectFactory.hpp 2000/07/25 14:48:12 1.7
@@ -393,6 +393,13 @@
{
}
+ explicit
+ XObjectGuard() :
+ m_factory(0),
+ m_object(0)
+ {
+ }
+
// Note that copy construction transfers ownership, just
// as std::auto_ptr.
XObjectGuard(XObjectGuard& theRHS)
@@ -415,6 +422,29 @@
reset();
}
+ // Note that assignment transfers ownership, just
+ // as std::auto_ptr.
+ XObjectGuard&
+ operator=(XObjectGuard& theRHS)
+ {
+ if (&theRHS != this)
+ {
+ // Release the current object...
+ release();
+
+ // Copy the factory and object pointers...
+ m_factory = theRHS.m_factory;
+ m_object = theRHS.m_object;
+
+ // The source object no longer points to
+ // the object...
+ theRHS.m_factory = 0;
+ theRHS.m_object = 0;
+ }
+
+ return *this;
+ }
+
/**
* Retrieve the object pointer (must not be null)
*
@@ -440,7 +470,7 @@
}
/**
- * Return the referenced object to the factory and set pointers to null.
+ * Return the referenced object to the factory and set the pointers to
null.
*/
void
reset()
@@ -458,6 +488,26 @@
}
/**
+ * Return the referenced object to the factory, if there is one,
+ * and set the pointers to the new object and factory.
+ */
+ void
+ reset(
+ XObjectFactory& theFactory,
+ XObject* theXObject)
+ {
+ if (m_object != 0)
+ {
+ assert(m_factory != 0);
+
+ m_factory->returnObject(m_object);
+ }
+
+ m_object = theXObject;
+ m_factory = &theFactory;
+ }
+
+ /**
* Transfers ownership of XObject to caller
*
* @return pointer to XObject
@@ -473,9 +523,6 @@
}
private:
-
- XObjectGuard&
- operator=(const XObjectGuard&);
bool
operator==(const XObjectGuard&) const;