summaryrefslogtreecommitdiffstats
path: root/src/dom
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2006-05-02 05:29:03 +0000
committergouldtj <gouldtj@users.sourceforge.net>2006-05-02 05:29:03 +0000
commitdc81b746cf1305802b07f367a44e518d9036a2d6 (patch)
tree079328ba4b24bee0c7dc90b022f5d7b3529c62d7 /src/dom
parentr11569@tres: ted | 2006-04-29 08:55:02 -0700 (diff)
downloadinkscape-dc81b746cf1305802b07f367a44e518d9036a2d6.tar.gz
inkscape-dc81b746cf1305802b07f367a44e518d9036a2d6.zip
(bzr r690)
Diffstat (limited to 'src/dom')
-rw-r--r--src/dom/domimpl.cpp2
-rw-r--r--src/dom/xpathtoken.cpp120
-rw-r--r--src/dom/xpathtoken.h162
3 files changed, 128 insertions, 156 deletions
diff --git a/src/dom/domimpl.cpp b/src/dom/domimpl.cpp
index ecbfd123d..026dc37c6 100644
--- a/src/dom/domimpl.cpp
+++ b/src/dom/domimpl.cpp
@@ -936,7 +936,7 @@ NodeImpl::NodeImpl() : Node()
/**
*
*/
-NodeImpl::NodeImpl(const NodeImpl &other) : Node()
+NodeImpl::NodeImpl(const NodeImpl &other)
{
init();
assign(other);
diff --git a/src/dom/xpathtoken.cpp b/src/dom/xpathtoken.cpp
index c9d4898d7..2d5dfc1d7 100644
--- a/src/dom/xpathtoken.cpp
+++ b/src/dom/xpathtoken.cpp
@@ -131,12 +131,12 @@ static TokenStringPair tokenStrings[] =
/**
- * Return the string TokenType of this token
+ * Return the enumerated TokenType of this token
* (in the .cpp file)
*/
DOMString Token::getTypeString()
{
- DOMString ret = "unknown";
+ DOMString ret;
for (TokenStringPair *pair = tokenStrings ; pair->sval ; pair++)
{
if (pair->ival == type)
@@ -148,8 +148,6 @@ DOMString Token::getTypeString()
return ret;
}
-
-
//########################################################################
//# X P A T H A X I S
//########################################################################
@@ -168,8 +166,7 @@ Axis::Axis()
*/
Axis::Axis(int tokPos)
{
- init();
- tokenPosition = tokPos;
+ assign(other);
}
@@ -186,15 +183,7 @@ Axis::Axis(const Axis &other)
/**
*
*/
-Axis::~Axis()
-{
-}
-
-
-/**
- *
- */
-Axis &Axis::operator=(const Axis &other)
+StackItem &StackItem::operator=(const StackItem &other)
{
assign(other);
return *this;
@@ -203,82 +192,72 @@ Axis &Axis::operator=(const Axis &other)
/**
*
*/
-void Axis::init()
+void StackItem::assign(const StackItem &other)
{
- tokenPosition = 0;
+ sval = other.sval;
+ ival = other.ival;
+ dval = other.dval;
}
-/**
- *
- */
-void Axis::assign(const Axis &other)
-{
- tokenPosition = other.tokenPosition;
-}
-/**
- *
- */
-void Axis::setPosition(unsigned int val)
-{
- tokenPosition = val;
-}
+//########################################################################
+//# X P A T H S T A C K I T E M
+//########################################################################
/**
*
*/
-unsigned int Axis::getPosition()
+StackItem::StackItem()
{
- return tokenPosition;
+ ival = 0L;
+ dval = 0.0;
}
-/**
- *
- */
-void Axis::setNode(const Node *val)
-{
- node = (Node *)val;
-}
/**
*
*/
-Node *Axis::getNode()
+StackItem::StackItem(const StackItem &other)
{
- return node;
+ assign(other);
}
-//########################################################################
-//# X P A T H S T A C K I T E M
-//########################################################################
/**
*
*/
-StackItem::StackItem()
+Stack::~Stack()
{
- ival = 0L;
- dval = 0.0;
}
/**
*
*/
-StackItem::StackItem(const StackItem &other)
+void Stack::assign(const Stack &other)
{
- assign(other);
+ root = other.root;
+ nodeList = other.nodeList;
+ size = other.size;
+ for (int i=0 ; i<size ; i++)
+ items[i] = other.items[i];
}
/**
*
*/
-StackItem::~StackItem()
+void Stack::reset()
{
+ root = NULL;
+ NodeList n; /*no "clear" in api*/
+ nodeList = n;
+ size = 0;
}
+
+
/**
*
*/
@@ -298,6 +277,22 @@ void StackItem::assign(const StackItem &other)
dval = other.dval;
}
+/**
+ * Set the root node
+ */
+void Stack::setRootNode(const Node *node)
+{
+ root = (Node *)node;
+}
+
+/**
+ * Get the current node list;
+ */
+NodeList &Stack::getNodeList()
+{
+ return nodeList;
+}
+
//########################################################################
//# T O K E N L I S T
@@ -375,31 +370,22 @@ unsigned int TokenList::size() const
}
-/**
- *
- */
-void TokenList::dump()
-{
+ Stack stack;
+ stack.setRootNode(root);
+
+ //### Execute the token list
std::vector<Token *>::iterator iter;
printf("############# TOKENS\n");
for (iter = tokens.begin() ; iter != tokens.end() ; iter++)
{
Token *tok = *iter;
- tok->dump();
+ tok->execute(stack);
}
}
+ list = stack.getNodeList();
-//########################################################################
-//# X P A T H E X E C U T O R
-//########################################################################
-
-/**
- *
- */
-TokenExecutor::TokenExecutor()
-{
- reset();
+ return list;
}
diff --git a/src/dom/xpathtoken.h b/src/dom/xpathtoken.h
index d595ad43c..03175efb1 100644
--- a/src/dom/xpathtoken.h
+++ b/src/dom/xpathtoken.h
@@ -199,7 +199,7 @@ public:
/**
* Assign our values to those of the other
*/
- virtual void assign(const TokenExecutor &other);
+ virtual void assign(const Stack &other);
/**
* Reset the stack to its original settings
@@ -217,38 +217,23 @@ public:
virtual StackItem pop();
/**
- * Execute a token list on the stack
+ * Set the root node
*/
- NodeList execute(const TokenList &list, const Node *node);
+ virtual void setRootNode(const Node *node);
/**
- *
+ * Get the current node list;
*/
- Axis axis;
+ virtual NodeList &getNodeList();
- /**
- *
- */
- std::vector<Axis> axisStack;
private:
- /**
- * Contains the StackItem stack;
- */
- StackItem stack[STACK_SIZE];
-
- /**
- * Marks the head of the stack, for push() and pop()
- */
- int stackSize;
-
- /**
- * Current list of nodes found by the expression
- */
+ Node *root;
NodeList nodeList;
-
+ StackItem items[STACK_SIZE];
+ int size;
};
@@ -387,7 +372,8 @@ public:
virtual int getType()
{ return type; }
/**
- * Return the string TokenType of this token
+ * Return the enumerated TokenType of this token
+ * (in the .cpp file)
*/
virtual DOMString getTypeString();
@@ -395,7 +381,7 @@ public:
* Let this token execute itself on the given stack,
* possibly adding Nodes to the node list.
*/
- virtual bool execute(TokenExecutor &stack)
+ virtual bool execute(Stack &stack)
{ return true; }
/**
@@ -456,7 +442,7 @@ public:
type = TOK_STR;
sval = val;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
StackItem item;
item.sval = sval;
@@ -473,7 +459,7 @@ public:
type = TOK_FLOAT;
dval = val;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
StackItem item;
item.dval = dval;
@@ -490,7 +476,7 @@ public:
type = TOK_INT;
ival = val;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
StackItem item;
item.ival = ival;
@@ -506,7 +492,7 @@ public:
{
type = TOK_AND;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
StackItem item1 = exec.pop();
StackItem item2 = exec.pop();
@@ -523,7 +509,7 @@ public:
{
type = TOK_OR;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
StackItem item1 = exec.pop();
StackItem item2 = exec.pop();
@@ -540,7 +526,7 @@ public:
{
type = TOK_MOD;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
StackItem item1 = exec.pop();
StackItem item2 = exec.pop();
@@ -557,7 +543,7 @@ public:
{
type = TOK_DIV;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
StackItem item1 = exec.pop();
StackItem item2 = exec.pop();
@@ -574,7 +560,7 @@ public:
{
type = TOK_MULTIPLY;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
StackItem item1 = exec.pop();
StackItem item2 = exec.pop();
@@ -591,7 +577,7 @@ public:
{
type = TOK_PLUS;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
StackItem item1 = exec.pop();
StackItem item2 = exec.pop();
@@ -608,7 +594,7 @@ public:
{
type = TOK_MINUS;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
StackItem item1 = exec.pop();
StackItem item2 = exec.pop();
@@ -625,7 +611,7 @@ public:
{
type = TOK_NEG;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
StackItem item = exec.pop();
item.dval = -item.dval;
@@ -642,7 +628,7 @@ public:
{
type = TOK_EQUALS;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
StackItem item1 = exec.pop();
StackItem item2 = exec.pop();
@@ -659,7 +645,7 @@ public:
{
type = TOK_NOT_EQUALS;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
StackItem item1 = exec.pop();
StackItem item2 = exec.pop();
@@ -676,7 +662,7 @@ public:
{
type = TOK_LESS_THAN_EQUALS;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
StackItem item1 = exec.pop();
StackItem item2 = exec.pop();
@@ -693,7 +679,7 @@ public:
{
type = TOK_LESS_THAN;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
StackItem item1 = exec.pop();
StackItem item2 = exec.pop();
@@ -710,7 +696,7 @@ public:
{
type = TOK_GREATER_THAN_EQUALS;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
StackItem item1 = exec.pop();
StackItem item2 = exec.pop();
@@ -727,7 +713,7 @@ public:
{
type = TOK_GREATER_THAN;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
StackItem item1 = exec.pop();
StackItem item2 = exec.pop();
@@ -749,7 +735,7 @@ public:
{
type = TOK_ABSOLUTE;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
Node *n = exec.axis.getNode();
while (n->getParentNode())
@@ -766,7 +752,7 @@ public:
{
type = TOK_RELATIVE;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
///exec.axis.currentNode = stack.rootNode;
return true;
@@ -780,7 +766,7 @@ public:
{
type = TOK_STEP;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -794,7 +780,7 @@ public:
type = TOK_NAME_TEST;
sval = name;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -807,7 +793,7 @@ public:
{
type = TOK_EXPR;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -820,7 +806,7 @@ public:
{
type = TOK_UNION;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -841,7 +827,7 @@ public:
{
type = TOK_AXIS_ANCESTOR_OR_SELF;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -854,7 +840,7 @@ public:
{
type = TOK_AXIS_ANCESTOR;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -867,7 +853,7 @@ public:
{
type = TOK_AXIS_ATTRIBUTE;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -880,7 +866,7 @@ public:
{
type = TOK_AXIS_CHILD;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -893,7 +879,7 @@ public:
{
type = TOK_AXIS_DESCENDANT_OR_SELF;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -906,7 +892,7 @@ public:
{
type = TOK_AXIS_DESCENDANT;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -919,7 +905,7 @@ public:
{
type = TOK_AXIS_FOLLOWING_SIBLING;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -932,7 +918,7 @@ public:
{
type = TOK_AXIS_FOLLOWING;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -945,7 +931,7 @@ public:
{
type = TOK_AXIS_NAMESPACE;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -958,7 +944,7 @@ public:
{
type = TOK_AXIS_PARENT;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -971,7 +957,7 @@ public:
{
type = TOK_AXIS_PRECEDING_SIBLING;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -984,7 +970,7 @@ public:
{
type = TOK_AXIS_PRECEDING;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -997,7 +983,7 @@ public:
{
type = TOK_AXIS_SELF;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1016,7 +1002,7 @@ public:
{
type = TOK_FUNC_LAST;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1029,7 +1015,7 @@ public:
{
type = TOK_FUNC_POSITION;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1042,7 +1028,7 @@ public:
{
type = TOK_FUNC_COUNT;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1055,7 +1041,7 @@ public:
{
type = TOK_FUNC_ID;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1068,7 +1054,7 @@ public:
{
type = TOK_FUNC_LOCAL_NAME;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1081,7 +1067,7 @@ public:
{
type = TOK_FUNC_NAMESPACE_URI;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1094,7 +1080,7 @@ public:
{
type = TOK_FUNC_NAME;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1107,7 +1093,7 @@ public:
{
type = TOK_FUNC_STRING;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1120,7 +1106,7 @@ public:
{
type = TOK_FUNC_CONCAT;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1133,7 +1119,7 @@ public:
{
type = TOK_FUNC_STARTS_WITH;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1146,7 +1132,7 @@ public:
{
type = TOK_FUNC_CONTAINS;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1159,7 +1145,7 @@ public:
{
type = TOK_FUNC_SUBSTRING_BEFORE;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1172,7 +1158,7 @@ public:
{
type = TOK_FUNC_SUBSTRING_AFTER;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1185,7 +1171,7 @@ public:
{
type = TOK_FUNC_SUBSTRING;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1198,7 +1184,7 @@ public:
{
type = TOK_FUNC_STRING_LENGTH;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1211,7 +1197,7 @@ public:
{
type = TOK_FUNC_NORMALIZE_SPACE;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1224,7 +1210,7 @@ public:
{
type = TOK_FUNC_TRANSLATE;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1237,7 +1223,7 @@ public:
{
type = TOK_FUNC_BOOLEAN;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1250,7 +1236,7 @@ public:
{
type = TOK_FUNC_NOT;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1263,7 +1249,7 @@ public:
{
type = TOK_FUNC_TRUE;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1276,7 +1262,7 @@ public:
{
type = TOK_FUNC_FALSE;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1289,7 +1275,7 @@ public:
{
type = TOK_FUNC_LANG;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1302,7 +1288,7 @@ public:
{
type = TOK_FUNC_NUMBER;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1315,7 +1301,7 @@ public:
{
type = TOK_FUNC_SUM;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1328,7 +1314,7 @@ public:
{
type = TOK_FUNC_FLOOR;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1341,7 +1327,7 @@ public:
{
type = TOK_FUNC_CEILING;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}
@@ -1354,7 +1340,7 @@ public:
{
type = TOK_FUNC_ROUND;
}
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
return true;
}