From 3f0a67f1da57a32a820ea6aca2db330985acdc59 Mon Sep 17 00:00:00 2001 From: Bob Jamison Date: Sun, 30 Apr 2006 00:34:33 +0000 Subject: Rework Stack class to TokenExecutor, to support an Axis stack (bzr r638) --- src/dom/xpathtoken.cpp | 246 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 169 insertions(+), 77 deletions(-) (limited to 'src/dom/xpathtoken.cpp') diff --git a/src/dom/xpathtoken.cpp b/src/dom/xpathtoken.cpp index 5de011959..c9d4898d7 100644 --- a/src/dom/xpathtoken.cpp +++ b/src/dom/xpathtoken.cpp @@ -131,12 +131,12 @@ static TokenStringPair tokenStrings[] = /** - * Return the enumerated TokenType of this token + * Return the string TokenType of this token * (in the .cpp file) */ DOMString Token::getTypeString() { - DOMString ret; + DOMString ret = "unknown"; for (TokenStringPair *pair = tokenStrings ; pair->sval ; pair++) { if (pair->ival == type) @@ -148,25 +148,37 @@ DOMString Token::getTypeString() return ret; } + + //######################################################################## -//# X P A T H S T A C K I T E M +//# X P A T H A X I S //######################################################################## /** * */ -StackItem::StackItem() +Axis::Axis() { - ival = 0L; - dval = 0.0; + init(); } /** * */ -StackItem::StackItem(const StackItem &other) +Axis::Axis(int tokPos) +{ + init(); + tokenPosition = tokPos; +} + + +/** + * + */ +Axis::Axis(const Axis &other) { + init(); assign(other); } @@ -174,7 +186,7 @@ StackItem::StackItem(const StackItem &other) /** * */ -StackItem::~StackItem() +Axis::~Axis() { } @@ -182,7 +194,7 @@ StackItem::~StackItem() /** * */ -StackItem &StackItem::operator=(const StackItem &other) +Axis &Axis::operator=(const Axis &other) { assign(other); return *this; @@ -191,111 +203,99 @@ StackItem &StackItem::operator=(const StackItem &other) /** * */ -void StackItem::assign(const StackItem &other) +void Axis::init() { - sval = other.sval; - ival = other.ival; - dval = other.dval; + tokenPosition = 0; } - -//######################################################################## -//# X P A T H S T A C K -//######################################################################## - /** * */ -Stack::Stack() +void Axis::assign(const Axis &other) { - size = 0; + tokenPosition = other.tokenPosition; } - /** * */ -Stack::Stack(const Stack &other) +void Axis::setPosition(unsigned int val) { - assign(other); + tokenPosition = val; } - /** * */ -Stack::~Stack() +unsigned int Axis::getPosition() { + return tokenPosition; } - /** * */ -void Stack::assign(const Stack &other) +void Axis::setNode(const Node *val) { - root = other.root; - nodeList = other.nodeList; - size = other.size; - for (int i=0 ; i=STACK_SIZE) - { - return; - } - items[size++] = item; + assign(other); } + /** * */ -StackItem Stack::pop() +StackItem::~StackItem() { - if (size<1) - { - StackItem item; - return item; - } - return items[--size]; } + /** - * Set the root node + * */ -void Stack::setRootNode(const Node *node) +StackItem &StackItem::operator=(const StackItem &other) { - root = (Node *)node; + assign(other); + return *this; } - /** - * Get the current node list; + * */ -NodeList &Stack::getNodeList() +void StackItem::assign(const StackItem &other) { - return nodeList; + sval = other.sval; + ival = other.ival; + dval = other.dval; } @@ -365,48 +365,140 @@ void TokenList::add(Token *tok) tokens.push_back(tok); } + /** - * This method "executes" a list of Tokens in the context of a DOM root - * Node, returning a list of Nodes that match the xpath expression. + * */ -NodeList TokenList::execute(const Node *root) +unsigned int TokenList::size() const { - NodeList list; - - if (!root) - return list; + return (unsigned int)tokens.size(); +} - Stack stack; - stack.setRootNode(root); - //### Execute the token list +/** + * + */ +void TokenList::dump() +{ std::vector::iterator iter; + printf("############# TOKENS\n"); for (iter = tokens.begin() ; iter != tokens.end() ; iter++) { Token *tok = *iter; - tok->execute(stack); + tok->dump(); } +} - list = stack.getNodeList(); - return list; +//######################################################################## +//# X P A T H E X E C U T O R +//######################################################################## + +/** + * + */ +TokenExecutor::TokenExecutor() +{ + reset(); } /** * */ -void TokenList::dump() +TokenExecutor::TokenExecutor(const TokenExecutor &other) { - std::vector::iterator iter; - printf("############# TOKENS\n"); - for (iter = tokens.begin() ; iter != tokens.end() ; iter++) + reset(); + assign(other); +} + + +/** + * + */ +TokenExecutor::~TokenExecutor() +{ +} + + +/** + * + */ +void TokenExecutor::assign(const TokenExecutor &other) +{ + axis = other.axis; + axisStack = other.axisStack; + stackSize = other.stackSize; + for (int i=0 ; idump(); } + + return nodeList; +} + + + + + +/** + * + */ +void TokenExecutor::push(StackItem &item) +{ + if (stackSize>=STACK_SIZE) + { + return; + } + stack[stackSize++] = item; } +/** + * + */ +StackItem TokenExecutor::pop() +{ + if (stackSize<1) + { + StackItem item; + return item; + } + return stack[--stackSize]; +} + + + + + + -- cgit v1.2.3