summaryrefslogtreecommitdiffstats
path: root/src/dom/xpathtoken.cpp
diff options
context:
space:
mode:
authorBob Jamison <ishmalius@gmail.com>2006-04-30 00:34:33 +0000
committerishmal <ishmal@users.sourceforge.net>2006-04-30 00:34:33 +0000
commit3f0a67f1da57a32a820ea6aca2db330985acdc59 (patch)
tree611f5ac3c2690f6a8aed988fe329df6853766f57 /src/dom/xpathtoken.cpp
parentupdated cc licenses to 2.5 (diff)
downloadinkscape-3f0a67f1da57a32a820ea6aca2db330985acdc59.tar.gz
inkscape-3f0a67f1da57a32a820ea6aca2db330985acdc59.zip
Rework Stack class to TokenExecutor, to support an Axis stack
(bzr r638)
Diffstat (limited to 'src/dom/xpathtoken.cpp')
-rw-r--r--src/dom/xpathtoken.cpp246
1 files changed, 169 insertions, 77 deletions
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<size ; i++)
- items[i] = other.items[i];
+ node = (Node *)val;
}
-
/**
*
*/
-void Stack::reset()
+Node *Axis::getNode()
{
- root = NULL;
- NodeList n; /*no "clear" in api*/
- nodeList = n;
- size = 0;
+ return node;
}
+//########################################################################
+//# X P A T H S T A C K I T E M
+//########################################################################
+/**
+ *
+ */
+StackItem::StackItem()
+{
+ ival = 0L;
+ dval = 0.0;
+}
/**
*
*/
-void Stack::push(StackItem &item)
+StackItem::StackItem(const StackItem &other)
{
- if (size>=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<Token *>::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<Token *>::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 ; i<stackSize ; i++)
+ stack[i] = other.stack[i];
+}
+
+
+/**
+ *
+ */
+void TokenExecutor::reset()
+{
+ axis.setPosition(0);
+ axis.setNode(NULL);
+ stackSize = 0;
+}
+
+
+
+
+/**
+ * Set the root node
+ */
+NodeList TokenExecutor::execute(const TokenList &tokens, const Node *node)
+{
+
+ axis.setPosition(0);
+ axis.setNode(node);
+
+ nodeList.clear();
+
+ while (axis.getPosition() < tokens.size())
{
- Token *tok = *iter;
- tok->dump();
}
+
+ 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];
+}
+
+
+
+
+
+