#include "../config/pathan_config.h" /* * Copyright (c) 2001, DecisionSoft Limited All rights reserved. * Please see LICENSE.TXT for more information. */ #include #include #include #include #include /*static*/ const XMLCh Union::name[]={ XERCES_CPP_NAMESPACE_QUALIFIER chLatin_u, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_n, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_i, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_o, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_n, XERCES_CPP_NAMESPACE_QUALIFIER chNull }; Union::Union(const VectorOfDataItems &args, XPath2MemoryManager* memMgr) : DataItemOperator(name, args, memMgr) { } Sequence Union::collapseTreeInternal(DynamicContext* context, int flags) const { Sequence param1 = _args[0]->collapseTree(context); if(!checkSequenceIsNodes(param1)) { DSLthrow(XPath2ErrorException,X("Union::collapseTreeInternal"), X("The operator 'union' has been called with a parameter that is not just nodes")); } Sequence param2 = _args[1]->collapseTree(context); if(!checkSequenceIsNodes(param2)) { DSLthrow(XPath2ErrorException,X("Union::collapseTreeInternal"), X("The operator 'union' has been called with a parameter that is not just nodes")); } //Now let's go through each element in the second list, and if it isn't already //in the first list, then add it to the first list for(Sequence::iterator secondIter = param2.begin(); secondIter != param2.end(); secondIter++) { bool toAdd = true; for(Sequence::iterator firstIter = param1.begin(); firstIter != param1.end(); firstIter++) { //If we see this element then set toAdd to false, and exit if(((const Node*)*firstIter)->equals((const Node*)*secondIter)) { toAdd = false; break; } } //Add the element if it isn't already in the list if(toAdd == true) { param1.addItem(*secondIter); } } //Sort the nodes into document order if(!(flags & DataItem::UNORDERED)) param1.sortIntoDocumentOrder(); return param1; }