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/07/27 22:35:33 UTC
cvs commit: xml-xalan/c/src/XPath ResultTreeFrag.cpp SimpleNodeLocator.cpp XPath.cpp XPathFunctionTable.cpp XPathFunctionTable.hpp XPathProcessorImpl.cpp
dbertoni 00/07/27 13:35:33
Modified: c/src/XPath ResultTreeFrag.cpp SimpleNodeLocator.cpp
XPath.cpp XPathFunctionTable.cpp
XPathFunctionTable.hpp XPathProcessorImpl.cpp
Log:
Changes so that functions are called by number, not by name.
Revision Changes Path
1.8 +2 -0 xml-xalan/c/src/XPath/ResultTreeFrag.cpp
Index: ResultTreeFrag.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/ResultTreeFrag.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ResultTreeFrag.cpp 2000/04/20 16:29:20 1.7
+++ ResultTreeFrag.cpp 2000/07/27 20:35:23 1.8
@@ -231,6 +231,8 @@
XalanNode* newChild,
XalanNode* oldChild)
{
+ assert(newChild != 0);
+
const unsigned int refIndex =
0 == oldChild ? m_children.npos : m_children.indexOf(oldChild);
1.18 +5 -27 xml-xalan/c/src/XPath/SimpleNodeLocator.cpp
Index: SimpleNodeLocator.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/SimpleNodeLocator.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- SimpleNodeLocator.cpp 2000/07/07 22:52:35 1.17
+++ SimpleNodeLocator.cpp 2000/07/27 20:35:23 1.18
@@ -1690,20 +1690,6 @@
const unsigned int theLength = subQueryResults.getLength();
-#if defined(XALAN_NO_NAMESPACES)
- typedef vector<unsigned int> FailedEntriesVectorType;
-#else
- typedef std::vector<unsigned int> FailedEntriesVectorType;
-#endif
- // We'll accumulate the entries that we want to remove
- // here, then remove them all at once.
- FailedEntriesVectorType theFailedEntries;
-
- // Might as well reserve some space now, although it's
- // probably bad to reserve the entire size of the
- // list results.
- theFailedEntries.reserve(theLength / 2);
-
while(i < theLength)
{
XalanNode* const theNode = subQueryResults.item(i);
@@ -1719,24 +1705,16 @@
i + 1 != pred->num() ||
pred->boolean() == false)
{
- theFailedEntries.push_back(i);
+ // Set the node to null. Later on,
+ // we'll clear it out.
+ subQueryResults.setNode(i, 0);
}
++i;
}
-
- // Erase from the back to the front, to preserve the validity
- // of the indexing, and so that we don't end up moving entries
- // that we would already be erasing...
- FailedEntriesVectorType::reverse_iterator theIterator =
- theFailedEntries.rbegin();
- while(theIterator != theFailedEntries.rend())
- {
- subQueryResults.removeNode(*theIterator);
-
- theIterator++;
- }
+ // Clear out any null entries...
+ subQueryResults.clearNulls();
opPos = currentExpression.getNextOpCodePosition(opPos);
1.22 +1 -6 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.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- XPath.cpp 2000/07/21 19:50:03 1.21
+++ XPath.cpp 2000/07/27 20:35:23 1.22
@@ -1456,10 +1456,5 @@
XPathExecutionContext& executionContext) const
{
- assert(m_expression.getToken(funcID) != 0);
-
- const XalanDOMString theFunctionName(m_expression.getToken(funcID)->str());
- assert(isEmpty(theFunctionName) == false);
-
- return s_functions[theFunctionName].execute(executionContext, context, opPos, argVec);
+ return s_functions[funcID].execute(executionContext, context, opPos, argVec);
}
1.7 +28 -9 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XPathFunctionTable.cpp 2000/05/26 19:20:41 1.6
+++ XPathFunctionTable.cpp 2000/07/27 20:35:23 1.7
@@ -94,7 +94,8 @@
XPathFunctionTable::XPathFunctionTable() :
- m_FunctionCollection()
+ m_FunctionCollection(),
+ m_FunctionNameIndex()
{
CreateTable();
}
@@ -110,25 +111,30 @@
void
XPathFunctionTable::InstallFunction(
const XalanDOMString& theFunctionName,
- const Function& theFunction)
+ const Function& theFunction)
{
assert(length(theFunctionName) != 0);
// See if a function of that name is already installed...
- const CollectionType::iterator i =
- m_FunctionCollection.find(theFunctionName);
+ const FunctionNameIndexMapType::iterator i =
+ m_FunctionNameIndex.find(theFunctionName);
- if (i != m_FunctionCollection.end())
+ if (i != m_FunctionNameIndex.end())
{
+ assert(CollectionType::size_type(i->second) < m_FunctionCollection.size());
+
// It is, so delete the old one, and add the new one...
- delete i->second;
+ delete m_FunctionCollection[i->second];
- i->second = theFunction.clone();
+ m_FunctionCollection[i->second] = theFunction.clone();
}
else
{
- // It's not, so clone the function and add it to the collection.
- m_FunctionCollection[theFunctionName] = theFunction.clone();
+ const int theIndex = m_FunctionCollection.size();
+
+ m_FunctionCollection.push_back(theFunction.clone());
+
+ m_FunctionNameIndex[theFunctionName] = theIndex;
}
}
@@ -243,10 +249,23 @@
for_each(m_FunctionCollection.begin(),
m_FunctionCollection.end(),
DeleteFunctorType());
+
+ m_FunctionCollection.clear();
+ m_FunctionNameIndex.clear();
}
catch(...)
{
}
+}
+
+
+
+XPathExceptionFunctionNotAvailable::XPathExceptionFunctionNotAvailable(
+ int theFunctionNumber,
+ const XalanNode* styleNode) :
+ XPathException(XALAN_STATIC_UCODE_STRING("The specified function ID is not available: ") + LongToDOMString(theFunctionNumber),
+ styleNode)
+{
}
1.6 +98 -15 xml-xalan/c/src/XPath/XPathFunctionTable.hpp
Index: XPathFunctionTable.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathFunctionTable.hpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XPathFunctionTable.hpp 2000/05/26 19:20:41 1.5
+++ XPathFunctionTable.hpp 2000/07/27 20:35:23 1.6
@@ -90,6 +90,10 @@
public:
XPathExceptionFunctionNotAvailable(
+ int theFunctionName,
+ const XalanNode* styleNode = 0);
+
+ XPathExceptionFunctionNotAvailable(
const XalanDOMString& theFunctionName,
const XalanNode* styleNode = 0);
@@ -106,12 +110,14 @@
public:
#if defined(XALAN_NO_NAMESPACES)
- typedef map<XalanDOMString, Function*> CollectionType;
+ typedef vector<Function*> CollectionType;
+ typedef map<XalanDOMString, int> FunctionNameIndexMapType;
#else
- typedef std::map<XalanDOMString, Function*> CollectionType;
+ typedef std::vector<Function*> CollectionType;
+ typedef std::map<XalanDOMString, int> FunctionNameIndexMapType;
#endif
- typedef MapValueDeleteFunctor<CollectionType> DeleteFunctorType;
+ typedef DeleteFunctor<Function> DeleteFunctorType;
XPathFunctionTable();
@@ -126,12 +132,12 @@
Function&
operator[](const XalanDOMString& theFunctionName) const
{
- CollectionType::const_iterator i =
- m_FunctionCollection.find(theFunctionName);
+ FunctionNameIndexMapType::const_iterator i =
+ m_FunctionNameIndex.find(theFunctionName);
- if (i != m_FunctionCollection.end())
+ if (i != m_FunctionNameIndex.end())
{
- return *(*i).second;
+ return *m_FunctionCollection[i->second];
}
else
{
@@ -140,6 +146,81 @@
}
/**
+ * Retrieve the function object for a specified function ID number.
+ *
+ * @param theFunctionID ID number of the function
+ * @return function named
+ */
+ Function&
+ operator[](int theFunctionID) const
+ {
+ if (theFunctionID >= 0 &&
+ CollectionType::size_type(theFunctionID) < m_FunctionCollection.size())
+ {
+ return *m_FunctionCollection[theFunctionID];
+ }
+ else
+ {
+ throw XPathExceptionFunctionNotAvailable(theFunctionID);
+ }
+ }
+
+ enum { InvalidFunctionNumberID = -1 };
+
+ /**
+ * Map a function ID to the corresponding name.
+ *
+ * @param theFunctionID The ID number of the function
+ * @return The name of the function, or an empty string if the function doesn't exist.
+ */
+ const XalanDOMString
+ idToName(int theFunctionID) const
+ {
+ XalanDOMString theName;
+
+ if (theFunctionID >= 0 &&
+ CollectionType::size_type(theFunctionID) < m_FunctionCollection.size())
+ {
+ FunctionNameIndexMapType::const_iterator i =
+ m_FunctionNameIndex.begin();
+
+ while (i != m_FunctionNameIndex.end())
+ {
+ if (i->second == theFunctionID)
+ {
+ theName = i->first;
+
+ break;
+ }
+ }
+ }
+
+ return theName;
+ }
+
+ /**
+ * Map a function name to the corresponding ID number.
+ *
+ * @param theName name of function
+ * @return The ID number of function, or InvalidFunctionNumberID if the function doesn't exist.
+ */
+ int
+ nameToID(const XalanDOMString& theName) const
+ {
+ const FunctionNameIndexMapType::const_iterator i =
+ m_FunctionNameIndex.find(theName);
+
+ if (i != m_FunctionNameIndex.end())
+ {
+ return i->second;
+ }
+ else
+ {
+ return InvalidFunctionNumberID;
+ }
+ }
+
+ /**
* Insert a named function into the function table.
*
* @param theFunctionName name of function
@@ -160,7 +241,7 @@
bool
isInstalledFunction(const XalanDOMString& theFunctionName) const
{
- if (m_FunctionCollection.find(theFunctionName) != m_FunctionCollection.end())
+ if (m_FunctionNameIndex.find(theFunctionName) != m_FunctionNameIndex.end())
{
return true;
}
@@ -181,10 +262,10 @@
void
getInstalledFunctionNames(InstalledFunctionNameVectorType& theVector) const
{
- CollectionType::const_iterator i =
- m_FunctionCollection.begin();
+ FunctionNameIndexMapType::const_iterator i =
+ m_FunctionNameIndex.begin();
- while(i != m_FunctionCollection.end())
+ while(i != m_FunctionNameIndex.end())
{
theVector.push_back((*i).first);
@@ -201,10 +282,10 @@
void
getInstalledFunctionNames(OutputIteratorType theIterator) const
{
- CollectionType::const_iterator i =
- m_FunctionCollection.begin();
+ FunctionNameIndexMapType::const_iterator i =
+ m_FunctionNameIndex.begin();
- while(i != m_FunctionCollection.end())
+ while(i != m_FunctionNameIndex.end())
{
*theIterator = (*i).first;
@@ -223,8 +304,10 @@
DestroyTable();
private:
+
+ CollectionType m_FunctionCollection;
- CollectionType m_FunctionCollection;
+ FunctionNameIndexMapType m_FunctionNameIndex;
};
1.16 +3 -6 xml-xalan/c/src/XPath/XPathProcessorImpl.cpp
Index: XPathProcessorImpl.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathProcessorImpl.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- XPathProcessorImpl.cpp 2000/07/13 22:22:32 1.15
+++ XPathProcessorImpl.cpp 2000/07/27 20:35:23 1.16
@@ -1661,13 +1661,10 @@
// we've looked at a token.
assert(m_expression->getTokenPosition() > 0);
- XPathExpression::OpCodeMapValueType thePosition =
- static_cast<XPathExpression::OpCodeMapValueType>(m_expression->getTokenPosition()) - 1;
+ int theFunctionID =
+ XPath::getFunctionTable().nameToID(m_token);
- assert(m_expression->getToken(thePosition) != 0 &&
- equals(m_expression->getToken(thePosition)->str(), m_token));
-
- XPathExpression::OpCodeMapValueVectorType theArgs(1, thePosition);
+ XPathExpression::OpCodeMapValueVectorType theArgs(1, theFunctionID);
m_expression->appendOpCode(XPathExpression::eOP_FUNCTION,
theArgs);