You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@locus.apache.org on 2000/03/07 17:13:46 UTC
cvs commit: xml-xalan/c/src/XPath XObjectFactory.hpp XObjectFactoryDefault.cpp XObjectFactoryDefault.hpp XPathFactory.hpp XPathFactoryDefault.cpp XPathFactoryDefault.hpp XPathFunctionTable.cpp
dbertoni 00/03/07 08:13:45
Modified: c/src/XPath XObjectFactory.hpp XObjectFactoryDefault.cpp
XObjectFactoryDefault.hpp XPathFactory.hpp
XPathFactoryDefault.cpp XPathFactoryDefault.hpp
XPathFunctionTable.cpp
Log:
Changes for new Factory interface.
Revision Changes Path
1.3 +23 -6 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XObjectFactory.hpp 2000/03/03 19:00:19 1.2
+++ XObjectFactory.hpp 2000/03/07 16:13:44 1.3
@@ -99,6 +99,18 @@
virtual
~XObjectFactory();
+
+ // These interfaces are inherited from Resetable...
+
+ /**
+ * Reset the instance. This invalidates all existing FactoryObject
+ * instances created with this Factory.
+ */
+ virtual void
+ reset() = 0;
+
+ // These interfaces are new to XObjectFactory...
+
/**
* Create a boolean XObject from a boolean value.
*
@@ -243,16 +255,21 @@
const DOM_Node& theValue,
bool fOptimize = true) = 0;
+protected:
// These interfaces are inherited from Factory...
- virtual bool
- returnObject(const FactoryObject* theFactoryObject) = 0;
-
- // These interfaces are inherited from Resetable...
+ /**
+ * Return an object to the factory.
+ *
+ * @param theFactoryObject object to be returned
+ * @param fInReset true when called during reset().
+ */
- virtual void
- reset() = 0;
+ virtual bool
+ doReturnObject(
+ const FactoryObject* theFactoryObject,
+ bool fInReset = false) = 0;
private:
1.5 +31 -74 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XObjectFactoryDefault.cpp 2000/02/03 20:13:18 1.4
+++ XObjectFactoryDefault.cpp 2000/03/07 16:13:44 1.5
@@ -87,50 +87,6 @@
-template<class ValueType, class CollectionType>
-void
-InsertObjectIntoCollection(
- CollectionType& theCollection,
- const ValueType& theObject)
-{
-#if defined(XALAN_HASH_CONTAINERS_AVAILABLE)
- theCollection.insert(theObject);
-#else
- theCollection.push_back(theObject);
-#endif
-}
-
-
-
-template<class ValueType, class CollectionType>
-bool
-RemoveObjectFromCollection(
- CollectionType& theCollection,
- const ValueType& theObject)
-{
-#if defined(XALAN_HASH_CONTAINERS_AVAILABLE)
- return theCollection.erase(theObject) > 0 ? true : false;
-#else
- typename CollectionType::iterator i =
- std::find(theCollection.begin(),
- theCollection.end(),
- theObject);
-
- if (i == theCollection.end())
- {
- return false;
- }
- else
- {
- theCollection.erase(i);
-
- return true;
- }
-#endif
-}
-
-
-
XObjectFactoryDefault::XObjectFactoryDefault(
XPathEnvSupport& theEnvSupport,
XPathSupport& theSupport) :
@@ -152,7 +108,9 @@
bool
-XObjectFactoryDefault::returnObject(const FactoryObject* theFactoryObject)
+XObjectFactoryDefault::doReturnObject(
+ const FactoryObject* theFactoryObject,
+ bool fInReset)
{
if (theFactoryObject == &theTrueBoolean ||
theFactoryObject == &theFalseBoolean ||
@@ -162,9 +120,16 @@
}
else
{
- if (RemoveObjectFromCollection(m_xobjects,
- theFactoryObject) == true)
+ const CollectionType::iterator i =
+ m_xobjects.find(theFactoryObject);
+
+ if (i != m_xobjects.end())
{
+ if (fInReset == false)
+ {
+ m_xobjects.erase(i);
+ }
+
return deleteObject(theFactoryObject);
}
else
@@ -189,8 +154,7 @@
{
XBoolean* const theBoolean = new XBoolean(m_envSupport, theValue);
- InsertObjectIntoCollection(m_xobjects,
- theBoolean);
+ m_xobjects.insert(theBoolean);
return theBoolean;
}
@@ -205,8 +169,7 @@
{
XNodeSet* const theXNodeSet = new XNodeSet(m_envSupport, m_support, value);
- InsertObjectIntoCollection(m_xobjects,
- theXNodeSet);
+ m_xobjects.insert(theXNodeSet);
return theXNodeSet;
}
@@ -220,8 +183,7 @@
{
XNodeSet* const theXNodeSet = new XNodeSet(m_envSupport, m_support, value);
- InsertObjectIntoCollection(m_xobjects,
- theXNodeSet);
+ m_xobjects.insert(theXNodeSet);
return theXNodeSet;
}
@@ -235,8 +197,7 @@
{
XNodeSet* const theXNodeSet = new XNodeSet(m_envSupport, m_support, value);
- InsertObjectIntoCollection(m_xobjects,
- theXNodeSet);
+ m_xobjects.insert(theXNodeSet);
return theXNodeSet;
}
@@ -254,8 +215,7 @@
{
XNull* const theXNull = new XNull(m_envSupport, m_support);
- InsertObjectIntoCollection(m_xobjects,
- theXNull);
+ m_xobjects.insert(theXNull);
return theXNull;
}
@@ -270,8 +230,7 @@
{
XNumber* theXNumber = new XNumber(m_envSupport, theValue);
- InsertObjectIntoCollection(m_xobjects,
- theXNumber);
+ m_xobjects.insert(theXNumber);
return theXNumber;
}
@@ -285,8 +244,7 @@
{
XString* const theXString = new XString(m_envSupport, m_support, theValue);
- InsertObjectIntoCollection(m_xobjects,
- theXString);
+ m_xobjects.insert(theXString);
return theXString;
}
@@ -300,8 +258,7 @@
{
XUnknown* const theXUnknown = new XUnknown(m_envSupport, theValue);
- InsertObjectIntoCollection(m_xobjects,
- theXUnknown);
+ m_xobjects.insert(theXUnknown);
return theXUnknown;
}
@@ -315,8 +272,7 @@
{
XResultTreeFrag* const theResultTreeFrag = new XResultTreeFrag(m_envSupport, m_support, theValue);
- InsertObjectIntoCollection(m_xobjects,
- theResultTreeFrag);
+ m_xobjects.insert(theResultTreeFrag);
return theResultTreeFrag;
}
@@ -330,8 +286,7 @@
{
XSpan* const theXSpan = new XSpan(m_envSupport, m_support, theValue);
- InsertObjectIntoCollection(m_xobjects,
- theXSpan);
+ m_xobjects.insert(theXSpan);
return theXSpan;
}
@@ -345,8 +300,7 @@
{
XSpan* const theXSpan = new XSpan(m_envSupport, m_support, theValue);
- InsertObjectIntoCollection(m_xobjects,
- theXSpan);
+ m_xobjects.insert(theXSpan);
return theXSpan;
}
@@ -360,8 +314,7 @@
{
XSpan* const theXSpan = new XSpan(m_envSupport, m_support, theValue);
- InsertObjectIntoCollection(m_xobjects,
- theXSpan);
+ m_xobjects.insert(theXSpan);
return theXSpan;
}
@@ -371,9 +324,13 @@
void
XObjectFactoryDefault::reset()
{
- std::for_each(m_xobjects.begin(),
- m_xobjects.end(),
- DeleteFactoryObjectFunctor(*this));
+#if !defined(XALAN_NO_NAMESPACES)
+ using std::for_each;
+#endif
+
+ for_each(m_xobjects.begin(),
+ m_xobjects.end(),
+ DeleteFactoryObjectFunctor(*this, true));
m_xobjects.clear();
}
1.3 +27 -38 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XObjectFactoryDefault.hpp 2000/03/03 19:00:20 1.2
+++ XObjectFactoryDefault.hpp 2000/03/07 16:13:44 1.3
@@ -64,10 +64,8 @@
-#if defined(XALAN_HASH_CONTAINERS_AVAILABLE)
-#include <hash_set>
-#elif !defined(XALAN_XTREE_BUG)
-#include <slist>
+#if !defined(XALAN_XTREE_BUG)
+#include <set>
#else
#include <vector>
#endif
@@ -105,33 +103,10 @@
~XObjectFactoryDefault();
-#if defined(XALAN_NO_NAMESPACES)
-# define XALAN_STD
-#else
-# define XALAN_STD std::
-#endif
-
-#if defined(XALAN_HASH_CONTAINERS_AVAILABLE)
- typedef XALAN_STD hash_set<const FactoryObject*> CollectionType;
-#elif !defined(XALAN_XTREE_BUG)
- typedef XALAN_STD slist<const FactoryObject*> CollectionType;
-#else
- typedef XALAN_STD vector<const FactoryObject*> CollectionType;
-#endif
+ // These methods are inherited from Factory...
-#undef XALAN_STD
-
- /**
- * Retrieve the number of instances in existence
- *
- * @return number of objects
- */
- CollectionType::size_type
- instanceCount() const
- {
- return m_xobjects.size();
- }
-
+ virtual void
+ reset();
// These methods are inherited from XObjectFactory ...
@@ -193,17 +168,31 @@
const DOM_Node& value,
bool fOptimize = true);
-
- // These methods are inherited from Factory ...
+#if defined(XALAN_NO_NAMESPACES)
+ typedef set<const FactoryObject*> CollectionType;
+#else
+ typedef std::set<const FactoryObject*> CollectionType;
+#endif
+
+ /**
+ * Retrieve the number of instances in existence
+ *
+ * @return number of objects
+ */
+ CollectionType::size_type
+ instanceCount() const
+ {
+ return m_xobjects.size();
+ }
- virtual bool
- returnObject(const FactoryObject* theFactoryObject);
+protected:
+ // These methods are inherited from Factory ...
- // These methods are inherited from Resettable ...
-
- virtual void
- reset();
+ virtual bool
+ doReturnObject(
+ const FactoryObject* theFactoryObject,
+ bool fInReset = false);
private:
1.3 +10 -4 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XPathFactory.hpp 2000/03/03 19:00:21 1.2
+++ XPathFactory.hpp 2000/03/07 16:13:44 1.3
@@ -85,6 +85,12 @@
virtual
~XPathFactory();
+ // Inherited from Factory...
+ 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.
@@ -94,14 +100,14 @@
virtual XPath*
create(bool fOptimize = true) = 0;
+protected:
// Inherited from Factory...
- virtual void
- reset() = 0;
-
virtual bool
- returnObject(const FactoryObject* theFactoryObject) = 0;
+ doReturnObject(
+ const FactoryObject* theFactoryObject,
+ bool fInReset = false) = 0;
};
1.3 +17 -18 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XPathFactoryDefault.cpp 2000/01/24 20:36:04 1.2
+++ XPathFactoryDefault.cpp 2000/03/07 16:13:44 1.3
@@ -85,9 +85,13 @@
void
XPathFactoryDefault::reset()
{
- std::for_each(m_xpaths.begin(),
- m_xpaths.end(),
- DeleteFactoryObjectFunctor(*this));
+#if !defined(XALAN_NO_NAMESPACES)
+ using std::for_each;
+#endif
+
+ for_each(m_xpaths.begin(),
+ m_xpaths.end(),
+ DeleteFactoryObjectFunctor(*this, true));
m_xpaths.clear();
}
@@ -95,21 +99,20 @@
bool
-XPathFactoryDefault::returnObject(const FactoryObject* theFactoryObject)
+XPathFactoryDefault::doReturnObject(
+ const FactoryObject* theFactoryObject,
+ bool fInReset)
{
-#if defined(XALAN_HASH_CONTAINERS_AVAILABLE)
- if(m_xpaths.erase(theObject) > 0)
- {
-#else
- CollectionType::iterator i =
- std::find(m_xpaths.begin(),
- m_xpaths.end(),
- theFactoryObject);
+ const CollectionType::iterator i =
+ m_xpaths.find(theFactoryObject);
if (i != m_xpaths.end())
{
- m_xpaths.erase(i);
-#endif
+ if (fInReset == false)
+ {
+ m_xpaths.erase(i);
+ }
+
return deleteObject(theFactoryObject);
}
else
@@ -125,11 +128,7 @@
{
XPath* const theXPath = new XPath;
-#if defined(XALAN_HASH_CONTAINERS_AVAILABLE)
m_xpaths.insert(theXPath);
-#else
- m_xpaths.push_back(theXPath);
-#endif
return theXPath;
}
1.4 +13 -13 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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XPathFactoryDefault.hpp 2000/03/03 19:00:21 1.3
+++ XPathFactoryDefault.hpp 2000/03/07 16:13:44 1.4
@@ -64,10 +64,8 @@
-#if defined(XALAN_HASH_CONTAINERS_AVAILABLE)
-#include <hash_set>
-#elif !defined(XALAN_XTREE_BUG)
-#include <slist>
+#if !defined(XALAN_XTREE_BUG)
+#include <set>
#else
#include <vector>
#endif
@@ -89,6 +87,9 @@
virtual
~XPathFactoryDefault();
+ // Inherited from Factory...
+ virtual void
+ reset();
// Inherited from XPathFactory...
@@ -96,22 +97,21 @@
create(bool fOptimize = true);
+protected:
+
// Inherited from Factory...
-
- virtual void
- reset();
virtual bool
- returnObject(const FactoryObject* theFactoryObject);
+ doReturnObject(
+ const FactoryObject* theFactoryObject,
+ bool fInReset = false);
private:
-#if defined(XALAN_HASH_CONTAINERS_AVAILABLE)
- typedef std::hash_set<const FactoryObject*> CollectionType;
-#elif !defined(XALAN_XTREE_BUG)
- typedef std::slist<const FactoryObject*> CollectionType;
+#if defined(XALAN_NO_NAMESPACES)
+ typedef set<const FactoryObject*> CollectionType;
#else
- typedef std::vector<const FactoryObject*> CollectionType;
+ typedef std::set<const FactoryObject*> CollectionType;
#endif
CollectionType m_xpaths;
1.3 +15 -5 xml-xalan/c/src/XPath/XPathFunctionTable.cpp
Index: XPathFunctionTable.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathFunctionTable.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XPathFunctionTable.cpp 2000/01/25 23:51:54 1.2
+++ XPathFunctionTable.cpp 2000/03/07 16:13:44 1.3
@@ -113,12 +113,22 @@
{
assert(length(theFunctionName) != 0);
- // Delete the currently installed function, if there is
- // one
- delete m_FunctionCollection[theFunctionName];
+ // See if a function of that name is already installed...
+ const CollectionType::iterator i =
+ m_FunctionCollection.find(theFunctionName);
- // Clone the function and add it to the collection.
- m_FunctionCollection[theFunctionName] = theFunction.clone();
+ if (i != m_FunctionCollection.end())
+ {
+ // It is, so delete the old one, and add the new one...
+ delete i->second;
+
+ i->second = theFunction.clone();
+ }
+ else
+ {
+ // It's not, so clone the function and add it to the collection.
+ m_FunctionCollection[theFunctionName] = theFunction.clone();
+ }
}