dbertoni 00/07/12 14:46:54
Modified: c/src/XPath FunctionDefaultStringArgument.hpp
FunctionNamespaceURI.hpp FunctionNumber.hpp
XObject.cpp XObject.hpp XObjectFactory.hpp
XObjectFactoryDefault.cpp XObjectFactoryDefault.hpp
XPath.cpp XPath.hpp XPathExpression.cpp
XPathFactory.hpp XPathFactoryDefault.cpp
XPathFactoryDefault.hpp
Log:
Changed inheritance of XObjectFactory, XPathFactory, XPath, and XObject to
get rid of the Factory, and FactoryObject base classes.
Revision Changes Path
1.6 +2 -2 xml-xalan/c/src/XPath/FunctionDefaultStringArgument.hpp
Index: FunctionDefaultStringArgument.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/FunctionDefaultStringArgument.hpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FunctionDefaultStringArgument.hpp 2000/04/18 15:26:41 1.5
+++ FunctionDefaultStringArgument.hpp 2000/07/12 21:46:50 1.6
@@ -124,8 +124,8 @@
// do the real work in turning themselves into strings.
// A node set that contains the context node.
- FactoryObjectAutoPointer<XObject>
theArg(&executionContext.getXObjectFactory(),
-
executionContext.getXObjectFactory().createNodeSet(context));
+ XObjectGuard theArg(executionContext.getXObjectFactory(),
+
executionContext.getXObjectFactory().createNodeSet(context));
// Now, get the string from the XObject.
return theArg->str();
1.5 +2 -2 xml-xalan/c/src/XPath/FunctionNamespaceURI.hpp
Index: FunctionNamespaceURI.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/FunctionNamespaceURI.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FunctionNamespaceURI.hpp 2000/04/11 14:46:06 1.4
+++ FunctionNamespaceURI.hpp 2000/07/12 21:46:50 1.5
@@ -129,8 +129,8 @@
// we're done.
// An XObject that contains the context node.
- FactoryObjectAutoPointer<XObject>
theXObject(&executionContext.getXObjectFactory(),
-
executionContext.getXObjectFactory().createNodeSet(*context));
+ XObjectGuard
theXObject(executionContext.getXObjectFactory(),
+
executionContext.getXObjectFactory().createNodeSet(*context));
theNamespace =
getNamespaceFromNodeSet(*theXObject.get(),
1.5 +2 -2 xml-xalan/c/src/XPath/FunctionNumber.hpp
Index: FunctionNumber.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/FunctionNumber.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FunctionNumber.hpp 2000/04/11 14:46:07 1.4
+++ FunctionNumber.hpp 2000/07/12 21:46:51 1.5
@@ -126,8 +126,8 @@
// deleted once we've converted the context node to a
number.
// An XObject that contains the context node.
- FactoryObjectAutoPointer<XObject>
theXObject(&executionContext.getXObjectFactory(),
-
executionContext.getXObjectFactory().createNodeSet(*context));
+ XObjectGuard
theXObject(executionContext.getXObjectFactory(),
+
executionContext.getXObjectFactory().createNodeSet(*context));
// Get the numeric value of the theXObject...
theValue = theXObject->num();
1.7 +0 -2 xml-xalan/c/src/XPath/XObject.cpp
Index: XObject.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XObject.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XObject.cpp 2000/05/15 15:54:11 1.6
+++ XObject.cpp 2000/07/12 21:46:51 1.7
@@ -81,7 +81,6 @@
XObject::XObject(
XPathEnvSupport* envSupport,
XPathSupport* support) :
- FactoryObject(),
m_envSupport(envSupport),
m_support(support)
{
@@ -90,7 +89,6 @@
XObject::XObject(const XObject& source) :
- FactoryObject(),
m_envSupport(source.m_envSupport),
m_support(source.m_support)
{
1.7 +4 -5 xml-xalan/c/src/XPath/XObject.hpp
Index: XObject.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XObject.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XObject.hpp 2000/07/06 20:16:28 1.6
+++ XObject.hpp 2000/07/12 21:46:51 1.7
@@ -68,10 +68,6 @@
-#include <PlatformSupport/FactoryObject.hpp>
-
-
-
class MutableNodeRefList;
class NodeRefListBase;
class ResultTreeFragBase;
@@ -84,7 +80,7 @@
/**
* Class to hold XPath return types.
*/
-class XALAN_XPATH_EXPORT XObject : public FactoryObject
+class XALAN_XPATH_EXPORT XObject
{
public:
@@ -284,6 +280,9 @@
{
return m_support;
}
+
+ // All XObject instances are controlled by an instance of an
XObjectFactory.
+ friend class XObjectFactory;
protected:
1.6 +99 -19 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XObjectFactory.hpp 2000/07/06 20:16:28 1.5
+++ XObjectFactory.hpp 2000/07/12 21:46:51 1.6
@@ -64,16 +64,12 @@
+#include <algorithm>
#include <cassert>
#include <set>
-// Base class header file...
-#include <PlatformSupport/Factory.hpp>
-
-
-
#include <XPath/XObject.hpp>
@@ -89,7 +85,7 @@
/**
* This class handles the creation of XObjects and manages their lifetime.
*/
-class XALAN_XPATH_EXPORT XObjectFactory : public Factory
+class XALAN_XPATH_EXPORT XObjectFactory
{
public:
@@ -99,17 +95,25 @@
~XObjectFactory();
- // These interfaces are inherited from Resetable...
+ /**
+ * Return an XObject to the factory.
+ *
+ * @param theXObject The XObject to be returned
+ * @return true if the object belongs to the factory, false if not.
+ */
+ bool
+ returnObject(const XObject* theXObject)
+ {
+ return doReturnObject(theXObject);
+ }
/**
- * Reset the instance. This invalidates all existing FactoryObject
- * instances created with this Factory.
+ * Reset the instance. This invalidates all existing instances created
+ * with this XObjectFactory.
*/
virtual void
reset() = 0;
- // These interfaces are new to XObjectFactory...
-
/**
* Clone an XObject instance, and hold in the factory.
*
@@ -263,21 +267,96 @@
XalanNode& theValue,
bool fOptimize = true) = 0;
+ /**
+ *
+ * A public functor for use with stl algorithms.
+ *
+ */
+#if defined(XALAN_NO_NAMESPACES)
+ struct DeleteXObjectFunctor : public unary_function<const XObject*,
void>
+#else
+ struct DeleteXObjectFunctor : public std::unary_function<const
XObject*, void>
+#endif
+ {
+ public:
+
+ DeleteXObjectFunctor(XObjectFactory& theFactoryInstance) :
+ m_factoryInstance(theFactoryInstance)
+ {
+ }
+
+ result_type
+ operator()(argument_type theXObject) const
+ {
+ m_factoryInstance.returnObject(theXObject);
+ }
+
+ private:
+
+ XObjectFactory& m_factoryInstance;
+ };
+
protected:
- // These interfaces are inherited from Factory...
+ /**
+ * Delete a FactoryObject instance.
+ *
+ * @param theXObject the XObject instance to delete.
+ */
+ void
+ deleteObject(const XObject* theXObject) const
+ {
+ delete theXObject;
+ }
/**
- * Return an object to the factory.
+ * Return an XObject to the factory.
*
- * @param theFactoryObject object to be returned
+ * @param theXObject XObject to be returned
* @param fInReset true when called during reset().
*/
virtual bool
doReturnObject(
- const FactoryObject* theFactoryObject,
- bool fInReset =
false) = 0;
+ const XObject* theXObject,
+ bool fInReset = false) = 0;
+
+ /**
+ *
+ * A functor for use with stl algorithms.
+ *
+ */
+#if defined(XALAN_NO_NAMESPACES)
+ struct ProtectedDeleteXObjectFunctor : public unary_function<const
XObject*, void>
+#else
+ struct ProtectedDeleteXObjectFunctor : public std::unary_function<const
XObject*, void>
+#endif
+ {
+ public:
+
+ ProtectedDeleteXObjectFunctor(
+ XObjectFactory& theFactoryInstance,
+ bool fInReset) :
+ m_factoryInstance(theFactoryInstance),
+ m_fInReset(fInReset)
+ {
+ }
+
+ result_type
+ operator()(argument_type theXObject) const
+ {
+ m_factoryInstance.doReturnObject(theXObject,
+
m_fInReset);
+ }
+
+ private:
+
+ XObjectFactory& m_factoryInstance;
+
+ const bool m_fInReset;
+ };
+
+ friend struct ProtectedDeleteXObjectFunctor;
private:
@@ -294,7 +373,7 @@
/**
- * Manages the ownership of an objected pointed to by an XObject pointer
+ * Manages the lifetime of an XObject instance.
*/
class XObjectGuard
{
@@ -306,8 +385,9 @@
* @param theFactory object that manages lifetime of XObjects
* @param theXObject pointer to XObject managed
*/
- XObjectGuard(XObjectFactory& theFactory,
- XObject* theXObject) :
+ XObjectGuard(
+ XObjectFactory& theFactory,
+ XObject* theXObject) :
m_factory(&theFactory),
m_object(theXObject)
{
1.9 +14 -13 xml-xalan/c/src/XPath/XObjectFactoryDefault.cpp
Index: XObjectFactoryDefault.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XObjectFactoryDefault.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- XObjectFactoryDefault.cpp 2000/07/06 20:16:28 1.8
+++ XObjectFactoryDefault.cpp 2000/07/12 21:46:51 1.9
@@ -86,6 +86,7 @@
XObjectFactoryDefault::XObjectFactoryDefault(
XPathEnvSupport& theEnvSupport,
XPathSupport& theSupport) :
+ XObjectFactory(),
m_envSupport(theEnvSupport),
m_support(theSupport),
m_xobjects(),
@@ -108,27 +109,25 @@
XObjectFactoryDefault::~XObjectFactoryDefault()
{
reset();
-
- deleteObject(m_XNull);
}
bool
XObjectFactoryDefault::doReturnObject(
- const FactoryObject* theFactoryObject,
- bool fInReset)
+ const XObject* theXObject,
+ bool fInReset)
{
- if (theFactoryObject == &theTrueBoolean ||
- theFactoryObject == &theFalseBoolean ||
- theFactoryObject == m_XNull)
+ if (theXObject == &theTrueBoolean ||
+ theXObject == &theFalseBoolean ||
+ theXObject == m_XNull.get())
{
return true;
}
else
{
const CollectionType::iterator i =
- m_xobjects.find(theFactoryObject);
+ m_xobjects.find(theXObject);
if (i != m_xobjects.end())
{
@@ -136,8 +135,10 @@
{
m_xobjects.erase(i);
}
+
+ deleteObject(theXObject);
- return deleteObject(theFactoryObject);
+ return true;
}
else
{
@@ -159,9 +160,9 @@
{
return &theFalseBoolean;
}
- else if (&theXObject == m_XNull)
+ else if (&theXObject == m_XNull.get())
{
- return m_XNull;
+ return m_XNull.get();
}
else
{
@@ -258,7 +259,7 @@
{
if (fOptimize == true)
{
- return m_XNull;
+ return m_XNull.get();
}
else
{
@@ -411,7 +412,7 @@
for_each(m_xobjects.begin(),
m_xobjects.end(),
- ProtectedDeleteFactoryObjectFunctor(*this, true));
+ ProtectedDeleteXObjectFunctor(*this, true));
m_xobjects.clear();
}
1.7 +12 -8 xml-xalan/c/src/XPath/XObjectFactoryDefault.hpp
Index: XObjectFactoryDefault.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XObjectFactoryDefault.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XObjectFactoryDefault.hpp 2000/07/06 20:16:28 1.6
+++ XObjectFactoryDefault.hpp 2000/07/12 21:46:51 1.7
@@ -64,6 +64,7 @@
+#include <memory>
#include <set>
@@ -73,6 +74,7 @@
+class XNull;
class XPathEnvSupport;
class XPathSupport;
@@ -100,13 +102,11 @@
~XObjectFactoryDefault();
- // These methods are inherited from Factory...
+ // These methods are inherited from XObjectFactory ...
virtual void
reset();
- // These methods are inherited from XObjectFactory ...
-
virtual XObject*
clone(const XObject& theXObject);
@@ -169,9 +169,9 @@
bool fOptimize = true);
#if defined(XALAN_NO_NAMESPACES)
- typedef set<const FactoryObject*> CollectionType;
+ typedef set<const XObject*> CollectionType;
#else
- typedef std::set<const FactoryObject*> CollectionType;
+ typedef std::set<const XObject*> CollectionType;
#endif
/**
@@ -243,8 +243,8 @@
virtual bool
doReturnObject(
- const FactoryObject* theFactoryObject,
- bool fInReset =
false);
+ const XObject* theXObject,
+ bool fInReset = false);
private:
@@ -264,7 +264,11 @@
CollectionType m_xobjects;
- XObject* const m_XNull;
+#if defined(XALAN_NO_NAMESPACES)
+ const auto_ptr<XNull> m_XNull;
+#else
+ const std::auto_ptr<XNull> m_XNull;
+#endif
#if !defined(NDEBUG)
1.20 +0 -1 xml-xalan/c/src/XPath/XPath.cpp
Index: XPath.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPath.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- XPath.cpp 2000/07/06 20:16:28 1.19
+++ XPath.cpp 2000/07/12 21:46:51 1.20
@@ -107,7 +107,6 @@
XPath::XPath(bool createDefaultLocator) :
- FactoryObject(),
m_defaultXLocator(createDefaultLocator == false ? 0 :
createXLocatorHandler()),
m_expression()
{
1.10 +4 -4 xml-xalan/c/src/XPath/XPath.hpp
Index: XPath.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPath.hpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- XPath.hpp 2000/07/06 20:16:28 1.9
+++ XPath.hpp 2000/07/12 21:46:51 1.10
@@ -110,7 +110,7 @@
* where strings are represented within the array as indices into the token
* tree.
*/
-class XALAN_XPATH_EXPORT XPath : public FactoryObject
+class XALAN_XPATH_EXPORT XPath
{
public:
@@ -146,6 +146,9 @@
explicit
XPath(bool createDefaultLocator = true);
+ virtual
+ ~XPath();
+
/**
* Shrink internal tables.
*/
@@ -419,9 +422,6 @@
#endif
protected:
-
- virtual
- ~XPath();
/**
* createXLocatorHandler.
1.9 +1 -1 xml-xalan/c/src/XPath/XPathExpression.cpp
Index: XPathExpression.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathExpression.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- XPathExpression.cpp 2000/07/06 20:16:28 1.8
+++ XPathExpression.cpp 2000/07/12 21:46:51 1.9
@@ -283,7 +283,7 @@
for_each(
m_tokenQueue.begin(),
m_tokenQueue.end(),
- DeleteFactoryObjectFunctor(*m_xobjectFactory));
+
XObjectFactory::DeleteXObjectFunctor(*m_xobjectFactory));
}
m_opMap.clear();
1.5 +172 -10 xml-xalan/c/src/XPath/XPathFactory.hpp
Index: XPathFactory.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathFactory.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XPathFactory.hpp 2000/04/11 14:46:19 1.4
+++ XPathFactory.hpp 2000/07/12 21:46:51 1.5
@@ -64,8 +64,8 @@
-// Base class header file...
-#include <PlatformSupport/Factory.hpp>
+#include <cassert>
+#include <functional>
@@ -73,7 +73,7 @@
-class XALAN_XPATH_EXPORT XPathFactory : public Factory
+class XALAN_XPATH_EXPORT XPathFactory
{
public:
@@ -83,12 +83,25 @@
virtual
~XPathFactory();
- // Inherited from Factory...
+ /**
+ * Return an XPath to the factory.
+ *
+ * @param theXPath The XPath to be returned
+ * @return true if the object belongs to the factory, false if not.
+ */
+ bool
+ returnObject(const XPath* theXPath)
+ {
+ return doReturnObject(theXPath);
+ }
+
+ /**
+ * Reset the instance. This invalidates all existing instances created
+ * with this XPathFactory.
+ */
virtual void
reset() = 0;
- // New to XPathFactory...
-
/**
* Create an XPath. The XPath instance is owned by the factory, and
should
* not be deleted. The factory will manage the lifetime.
@@ -100,15 +113,164 @@
protected:
- // Inherited from Factory...
-
virtual bool
doReturnObject(
- const FactoryObject* theFactoryObject,
- bool fInReset =
false) = 0;
+ const XPath* theXPath,
+ bool fInReset = false) = 0;
+
+ /**
+ *
+ * A functor for use with stl algorithms.
+ *
+ */
+#if defined(XALAN_NO_NAMESPACES)
+ struct ProtectedDeleteXPathFunctor : public unary_function<const
XPath*, void>
+#else
+ struct ProtectedDeleteXPathFunctor : public std::unary_function<const
XPath*, void>
+#endif
+ {
+ public:
+
+ ProtectedDeleteXPathFunctor(
+ XPathFactory& theFactoryInstance,
+ bool fInReset) :
+ m_factoryInstance(theFactoryInstance),
+ m_fInReset(fInReset)
+ {
+ }
+
+ result_type
+ operator()(argument_type theXPath) const
+ {
+ m_factoryInstance.doReturnObject(theXPath,
+
m_fInReset);
+ }
+ private:
+
+ XPathFactory& m_factoryInstance;
+
+ const bool m_fInReset;
+ };
+
+ friend struct ProtectedDeleteXPathFunctor;
+
};
+
+/**
+ * Manages the lifetime of an XPath instance.
+ */
+class XPathGuard
+{
+public:
+
+ /**
+ * Construct an XPathGuard instance from a factory object and an XPath.
+ *
+ * @param theFactory object that manages lifetime of XPaths
+ * @param theXPath pointer to XPath managed
+ */
+ XPathGuard(
+ XPathFactory& theFactory,
+ XPath* theXPath) :
+ m_factory(&theFactory),
+ m_object(theXPath)
+ {
+ }
+
+ // Note that copy construction transfers ownership, just
+ // as std::auto_ptr.
+ XPathGuard(XPathGuard& theRHS)
+ {
+ // 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;
+ }
+
+ ~XPathGuard()
+ {
+ reset();
+ }
+
+ /**
+ * Retrieve the object pointer (must not be null)
+ *
+ * @return pointer to XPath
+ */
+ XPath*
+ operator->() const
+ {
+ assert(m_object != 0);
+
+ return m_object;
+ }
+
+ /**
+ * Retrieve the object pointer (may be null)
+ *
+ * @return pointer to XPath
+ */
+ XPath*
+ get() const
+ {
+ return m_object;
+ }
+
+ /**
+ * Return the referenced object to the factory and set pointers to null.
+ */
+ void
+ reset()
+ {
+ if (m_object != 0)
+ {
+ assert(m_factory != 0);
+
+ m_factory->returnObject(m_object);
+
+ m_object = 0;
+ }
+
+ m_factory = 0;
+ }
+
+ /**
+ * Transfers ownership of XPath to caller
+ *
+ * @return pointer to XPath
+ */
+ XPath*
+ release()
+ {
+ XPath* const theTemp = m_object;
+
+ m_object = 0;
+
+ return theTemp;
+ }
+
+private:
+
+ XPathGuard&
+ operator=(const XPathGuard&);
+
+ bool
+ operator==(const XPathGuard&) const;
+
+
+ // Data members...
+ XPathFactory* m_factory;
+ XPath* m_object;
+};
#endif // XPATHFACTORY_HEADER_GUARD_1357924680
1.6 +7 -5 xml-xalan/c/src/XPath/XPathFactoryDefault.cpp
Index: XPathFactoryDefault.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathFactoryDefault.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XPathFactoryDefault.cpp 2000/07/06 20:16:28 1.5
+++ XPathFactoryDefault.cpp 2000/07/12 21:46:51 1.6
@@ -94,7 +94,7 @@
for_each(m_xpaths.begin(),
m_xpaths.end(),
- ProtectedDeleteFactoryObjectFunctor(*this, true));
+ ProtectedDeleteXPathFunctor(*this, true));
m_xpaths.clear();
}
@@ -103,11 +103,11 @@
bool
XPathFactoryDefault::doReturnObject(
- const FactoryObject* theFactoryObject,
- bool fInReset)
+ const XPath* theXPath,
+ bool fInReset)
{
const CollectionType::iterator i =
- m_xpaths.find(theFactoryObject);
+ m_xpaths.find(theXPath);
if (i != m_xpaths.end())
{
@@ -116,7 +116,9 @@
m_xpaths.erase(i);
}
- return deleteObject(theFactoryObject);
+ delete theXPath;
+
+ return true;
}
else
{
1.7 +7 -6 xml-xalan/c/src/XPath/XPathFactoryDefault.hpp
Index: XPathFactoryDefault.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathFactoryDefault.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XPathFactoryDefault.hpp 2000/04/11 14:46:19 1.6
+++ XPathFactoryDefault.hpp 2000/07/12 21:46:51 1.7
@@ -84,7 +84,8 @@
virtual
~XPathFactoryDefault();
- // Inherited from Factory...
+
+ // Inherited from XPathFactory...
virtual void
reset();
@@ -95,9 +96,9 @@
#if defined(XALAN_NO_NAMESPACES)
- typedef set<const FactoryObject*> CollectionType;
+ typedef set<const XPath*> CollectionType;
#else
- typedef std::set<const FactoryObject*> CollectionType;
+ typedef std::set<const XPath*> CollectionType;
#endif
CollectionType::size_type
@@ -116,12 +117,12 @@
protected:
- // Inherited from Factory...
+ // Inherited from XPathFactory...
virtual bool
doReturnObject(
- const FactoryObject* theFactoryObject,
- bool fInReset =
false);
+ const XPath* theXPath,
+ bool fInReset = false);
private: