diff --git a/src/dom/xpathtoken.h b/src/dom/xpathtoken.h
index 9b9259e06c5a2f5eae075d49d43c363010c2235e..9039006278981536bb9302f0627bb10a091cef8d 100644 (file)
--- a/src/dom/xpathtoken.h
+++ b/src/dom/xpathtoken.h
-#ifndef __XPATHTOKEN_H__\r
-#define __XPATHTOKEN_H__\r
-\r
-/**\r
- * Phoebe DOM Implementation.\r
- *\r
- * This is a C++ approximation of the W3C DOM model, which follows\r
- * fairly closely the specifications in the various .idl files, copies of\r
- * which are provided for reference. Most important is this one:\r
- *\r
- * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html\r
- *\r
- * Authors:\r
- * Bob Jamison\r
- *\r
- * Copyright (C) 2006 Bob Jamison\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Lesser General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2.1 of the License, or (at your option) any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Lesser General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Lesser General Public\r
- * License along with this library; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\r
- */\r
-\r
-\r
-#include "dom.h"\r
-\r
-#include <math.h>\r
-\r
-#include <vector>\r
-\r
-namespace org\r
-{\r
-namespace w3c\r
-{\r
-namespace dom\r
-{\r
-namespace xpath\r
-{\r
-\r
-typedef org::w3c::dom::DOMString DOMString;\r
-\r
-/**\r
- * This represents a single value on the evaluation stack\r
- */\r
-class StackItem\r
-{\r
-public:\r
-\r
- /**\r
- * Constructor\r
- */\r
- StackItem();\r
-\r
- /**\r
- * Copy constructor\r
- */\r
- StackItem(const StackItem &other);\r
-\r
- /**\r
- * Destructor\r
- */\r
- virtual ~StackItem();\r
-\r
- //treat the stack item like an union of string, integer, and double\r
-\r
- /**\r
- * String value\r
- */\r
- DOMString sval;\r
-\r
- /**\r
- * Integer value\r
- */\r
- long ival;\r
-\r
- /**\r
- * Double value;\r
- */\r
- double dval;\r
-\r
-};\r
-\r
-#define STACK_SIZE 1024\r
-\r
-/**\r
- * An evaluation stack\r
- */\r
-class Stack\r
-{\r
-public:\r
-\r
- /**\r
- * Constructor\r
- */\r
- Stack();\r
-\r
- /**\r
- * Copy constructor\r
- */\r
- Stack(const Stack &other);\r
-\r
- /**\r
- * Destructor\r
- */\r
- virtual ~Stack();\r
-\r
- /**\r
- * Assign our values to those of the other\r
- */\r
- virtual void assign(const Stack &other);\r
-\r
- /**\r
- * Reset the stack to its original settings\r
- */\r
- virtual void reset();\r
-\r
- /**\r
- * Push a stack item onto the stack\r
- */\r
- virtual void push(StackItem &item);\r
-\r
- /**\r
- * Pop a stack item from the stack\r
- */\r
- virtual StackItem pop();\r
-\r
- /**\r
- * Set the root node\r
- */\r
- virtual void setRootNode(const Node *node);\r
-\r
- /**\r
- * Get the current node list;\r
- */\r
- virtual NodeList &getNodeList();\r
-\r
-\r
-private:\r
-\r
- Node *root;\r
- NodeList nodeList;\r
-\r
- StackItem items[STACK_SIZE];\r
- int size;\r
-};\r
-\r
-\r
-\r
-\r
-/**\r
- * This is a pseudocode-type class that executes itself on a stack,\r
- * much like stack-oriented languages such as FORTH or Postscript.\r
- * Each token can pop zero or more tokens off the stack, and push\r
- * zero or one token back onto it. When a list of tokens is completed,\r
- * a single stack value should be left on the stack.\r
- */\r
-class Token\r
-{\r
-public:\r
-\r
- /**\r
- * Token types. Look in xpathtoken.cpp's function table\r
- * to see how these types map to their respective\r
- * functionalities\r
- */\r
- typedef enum\r
- {\r
- TOK_NOP = 0,\r
- TOK_STR,\r
- TOK_INT,\r
- TOK_FLOAT,\r
- //operators\r
- TOK_AND,\r
- TOK_OR,\r
- TOK_MOD,\r
- TOK_DIV,\r
- TOK_MULTIPLY,\r
- TOK_DOUBLE_SLASH,\r
- TOK_SLASH,\r
- TOK_PIPE,\r
- TOK_PLUS,\r
- TOK_MINUS,\r
- TOK_NEG,\r
- TOK_EQUALS,\r
- TOK_NOT_EQUALS,\r
- TOK_LESS_THAN_EQUALS,\r
- TOK_LESS_THAN,\r
- TOK_GREATER_THAN_EQUALS,\r
- TOK_GREATER_THAN,\r
- //path types\r
- TOK_ABSOLUTE,\r
- TOK_RELATIVE,\r
- TOK_STEP,\r
- TOK_EXPR,\r
- TOK_UNION,\r
- //function types\r
- TOK_POSITION\r
- } TokenType;\r
- /**\r
- * Constructor with a NOP default type\r
- */\r
- Token()\r
- {\r
- type = TOK_NOP;\r
- stype = "nop";\r
- ival = 0L;\r
- dval = 0.0;\r
- }\r
-\r
- /**\r
- * Copy constructor\r
- */\r
- Token(const Token &other)\r
- {\r
- type = other.type;\r
- stype = other.stype;\r
- sval = other.sval;\r
- ival = other.ival;\r
- dval = other.dval;\r
- }\r
-\r
- /**\r
- * Destructor\r
- */\r
- virtual ~Token()\r
- {}\r
-\r
- /**\r
- * Return the enumerated TokenType of this token\r
- */\r
- virtual int getType()\r
- { return type; }\r
-\r
- /**\r
- * Let this token execute itself on the given stack,\r
- * possibly adding Nodes to the node list.\r
- */\r
- virtual bool execute(Stack &stack)\r
- { return true; }\r
-\r
- /**\r
- * Print the contents of this token\r
- */\r
- virtual void dump()\r
- {\r
- printf("%s %s %f %ld\n", stype, sval.c_str(), dval, ival);\r
- }\r
-\r
- //treat the token like an union of string, integer, and double\r
-\r
- /**\r
- * String value\r
- */\r
- DOMString sval;\r
-\r
- /**\r
- * Integer value\r
- */\r
- long ival;\r
-\r
- /**\r
- * Double value;\r
- */\r
- double dval;\r
-\r
-protected:\r
-\r
- /**\r
- * The enmerated token type\r
- */\r
- int type;\r
-\r
- /**\r
- * String type\r
- */\r
- char *stype;\r
-\r
-private:\r
-\r
-\r
-};\r
-\r
-\r
-//########################################################################\r
-//# X P A T H T O K E N\r
-//########################################################################\r
-\r
-\r
-\r
-//###########################\r
-//# V A L U E S\r
-//###########################\r
-\r
-class TokStr : public Token\r
-{\r
-public:\r
- TokStr(const DOMString &val)\r
- {\r
- type = TOK_STR;\r
- stype = "str";\r
- sval = val;\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- StackItem item;\r
- item.sval = sval;\r
- stack.push(item);\r
- return true;\r
- }\r
-};\r
-\r
-class TokFloat : public Token\r
-{\r
-public:\r
- TokFloat(double val)\r
- {\r
- type = TOK_FLOAT;\r
- stype = "float";\r
- dval = val;\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- StackItem item;\r
- item.dval = dval;\r
- stack.push(item);\r
- return true;\r
- }\r
-};\r
-\r
-class TokInt : public Token\r
-{\r
-public:\r
- TokInt(long val)\r
- {\r
- type = TOK_INT;\r
- stype = "int";\r
- ival = val;\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- StackItem item;\r
- item.ival = ival;\r
- stack.push(item);\r
- return true;\r
- }\r
-};\r
-\r
-class TokAnd : public Token\r
-{\r
-public:\r
- TokAnd()\r
- {\r
- type = TOK_AND;\r
- stype = "and";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- StackItem item1 = stack.pop();\r
- StackItem item2 = stack.pop();\r
- item1.ival = item1.ival && item2.ival;\r
- stack.push(item1);\r
- return true;\r
- }\r
-};\r
-\r
-class TokOr : public Token\r
-{\r
-public:\r
- TokOr()\r
- {\r
- type = TOK_OR;\r
- stype = "or";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- StackItem item1 = stack.pop();\r
- StackItem item2 = stack.pop();\r
- item1.ival = item1.ival || item2.ival;\r
- stack.push(item1);\r
- return true;\r
- }\r
-};\r
-\r
-class TokMod : public Token\r
-{\r
-public:\r
- TokMod()\r
- {\r
- type = TOK_MOD;\r
- stype = "mod";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- StackItem item1 = stack.pop();\r
- StackItem item2 = stack.pop();\r
- item1.dval = fmod(item1.dval, item2.dval);\r
- stack.push(item1);\r
- return true;\r
- }\r
-};\r
-\r
-class TokDiv : public Token\r
-{\r
-public:\r
- TokDiv()\r
- {\r
- type = TOK_DIV;\r
- stype = "div";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- StackItem item1 = stack.pop();\r
- StackItem item2 = stack.pop();\r
- item1.dval /= item2.dval;\r
- stack.push(item1);\r
- return true;\r
- }\r
-};\r
-\r
-class TokMul : public Token\r
-{\r
-public:\r
- TokMul()\r
- {\r
- type = TOK_MULTIPLY;\r
- stype = "mul";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- StackItem item1 = stack.pop();\r
- StackItem item2 = stack.pop();\r
- item1.dval *= item2.dval;\r
- stack.push(item1);\r
- return true;\r
- }\r
-};\r
-\r
-class TokPlus : public Token\r
-{\r
-public:\r
- TokPlus()\r
- {\r
- type = TOK_PLUS;\r
- stype = "plus";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- StackItem item1 = stack.pop();\r
- StackItem item2 = stack.pop();\r
- item1.dval += item2.dval;\r
- stack.push(item1);\r
- return true;\r
- }\r
-};\r
-\r
-class TokMinus : public Token\r
-{\r
-public:\r
- TokMinus()\r
- {\r
- type = TOK_MINUS;\r
- stype = "minus";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- StackItem item1 = stack.pop();\r
- StackItem item2 = stack.pop();\r
- item1.dval -= item2.dval;\r
- stack.push(item1);\r
- return true;\r
- }\r
-};\r
-\r
-class TokNeg : public Token\r
-{\r
-public:\r
- TokNeg()\r
- {\r
- type = TOK_NEG;\r
- stype = "neg";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- StackItem item;\r
- item.dval = -dval;\r
- item.ival = -ival;\r
- stack.push(item);\r
- return true;\r
- }\r
-};\r
-\r
-class TokEquals : public Token\r
-{\r
-public:\r
- TokEquals()\r
- {\r
- type = TOK_EQUALS;\r
- stype = "equals";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- StackItem item1 = stack.pop();\r
- StackItem item2 = stack.pop();\r
- item1.ival = (item1.dval == item2.dval);\r
- stack.push(item1);\r
- return true;\r
- }\r
-};\r
-\r
-class TokNotEquals : public Token\r
-{\r
-public:\r
- TokNotEquals()\r
- {\r
- type = TOK_NOT_EQUALS;\r
- stype = "neq";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- StackItem item1 = stack.pop();\r
- StackItem item2 = stack.pop();\r
- item1.ival = (item1.dval != item2.dval);\r
- stack.push(item1);\r
- return true;\r
- }\r
-};\r
-\r
-class TokLessThanEquals : public Token\r
-{\r
-public:\r
- TokLessThanEquals()\r
- {\r
- type = TOK_LESS_THAN_EQUALS;\r
- stype = "lt_eq";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- StackItem item1 = stack.pop();\r
- StackItem item2 = stack.pop();\r
- item1.ival = (item1.dval <= item2.dval);\r
- stack.push(item1);\r
- return true;\r
- }\r
-};\r
-\r
-class TokLessThan : public Token\r
-{\r
-public:\r
- TokLessThan()\r
- {\r
- type = TOK_LESS_THAN;\r
- stype = "lt";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- StackItem item1 = stack.pop();\r
- StackItem item2 = stack.pop();\r
- item1.ival = (item1.dval < item2.dval);\r
- stack.push(item1);\r
- return true;\r
- }\r
-};\r
-\r
-class TokGreaterThanEquals : public Token\r
-{\r
-public:\r
- TokGreaterThanEquals()\r
- {\r
- type = TOK_GREATER_THAN_EQUALS;\r
- stype = "gt";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- StackItem item1 = stack.pop();\r
- StackItem item2 = stack.pop();\r
- item1.ival = (item1.dval >= item2.dval);\r
- stack.push(item1);\r
- return true;\r
- }\r
-};\r
-\r
-class TokGreaterThan : public Token\r
-{\r
-public:\r
- TokGreaterThan()\r
- {\r
- type = TOK_GREATER_THAN;\r
- stype = "gt_eq";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- StackItem item1 = stack.pop();\r
- StackItem item2 = stack.pop();\r
- item1.ival = (item1.dval > item2.dval);\r
- stack.push(item1);\r
- return true;\r
- }\r
-};\r
-\r
-\r
-//###########################\r
-//# X P A T H I T E M S\r
-//###########################\r
-\r
-class TokAbsolute : public Token\r
-{\r
-public:\r
- TokAbsolute()\r
- {\r
- type = TOK_ABSOLUTE;\r
- stype = "absolute";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- return true;\r
- }\r
-};\r
-\r
-class TokRelative : public Token\r
-{\r
-public:\r
- TokRelative()\r
- {\r
- type = TOK_RELATIVE;\r
- stype = "relative";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- return true;\r
- }\r
-};\r
-\r
-class TokStep : public Token\r
-{\r
-public:\r
- TokStep()\r
- {\r
- type = TOK_STEP;\r
- stype = "step";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- return true;\r
- }\r
-};\r
-\r
-class TokExpr : public Token\r
-{\r
-public:\r
- TokExpr()\r
- {\r
- type = TOK_EXPR;\r
- stype = "token";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- return true;\r
- }\r
-};\r
-\r
-class TokUnion : public Token\r
-{\r
-public:\r
- TokUnion()\r
- {\r
- type = TOK_UNION;\r
- stype = "union";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- return true;\r
- }\r
-};\r
-\r
-\r
-\r
-//###########################\r
-//# F U N C T I O N S\r
-//###########################\r
-\r
-class TokPosition : public Token\r
-{\r
-public:\r
- TokPosition()\r
- {\r
- type = TOK_POSITION;\r
- stype = "position";\r
- }\r
- virtual bool execute(Stack &stack)\r
- {\r
- return true;\r
- }\r
-};\r
-\r
-\r
-\r
-//########################################################################\r
-//# T O K E N L I S T\r
-//########################################################################\r
-\r
-/**\r
- *\r
- */\r
-class TokenList\r
-{\r
-public:\r
-\r
- /**\r
- *\r
- */\r
- TokenList();\r
-\r
- /**\r
- *\r
- */\r
- virtual ~TokenList();\r
-\r
- /**\r
- *\r
- */\r
- virtual void clear();\r
-\r
- /**\r
- *\r
- */\r
- virtual void add(Token *tok);\r
-\r
- /**\r
- * This method "executes" a list of Tokens in the context of a DOM root\r
- * Node, returning a list of Nodes that match the xpath expression.\r
- */\r
- NodeList execute(const Node *root);\r
-\r
- /**\r
- *\r
- */\r
- virtual void dump();\r
-\r
-private:\r
-\r
-\r
- std::vector<Token *> tokens;\r
-\r
-};\r
-\r
-\r
-\r
-} // namespace xpath\r
-} // namespace dom\r
-} // namespace w3c\r
-} // namespace org\r
-\r
-\r
-\r
-\r
-\r
-\r
-#endif /* __XPATHTOKEN_H__ */\r
-//########################################################################\r
-//# E N D O F F I L E\r
-//########################################################################\r
-\r
+#ifndef __XPATHTOKEN_H__
+#define __XPATHTOKEN_H__
+
+/**
+ * Phoebe DOM Implementation.
+ *
+ * This is a C++ approximation of the W3C DOM model, which follows
+ * fairly closely the specifications in the various .idl files, copies of
+ * which are provided for reference. Most important is this one:
+ *
+ * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
+ *
+ * Authors:
+ * Bob Jamison
+ *
+ * Copyright (C) 2006 Bob Jamison
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+#include "dom.h"
+
+#include <math.h>
+
+#include <vector>
+
+namespace org
+{
+namespace w3c
+{
+namespace dom
+{
+namespace xpath
+{
+
+typedef org::w3c::dom::DOMString DOMString;
+
+
+class TokenExecutor;
+
+
+//########################################################################
+//# S T A C K I T E M
+//########################################################################
+
+
+/**
+ * This represents a single value on the evaluation stack
+ */
+class StackItem
+{
+public:
+
+ /**
+ * Constructor
+ */
+ StackItem()
+ { init(); }
+
+ /**
+ * Copy constructor
+ */
+ StackItem(const StackItem &other)
+ { assign(other); }
+
+ /**
+ * Destructor
+ */
+ virtual ~StackItem()
+ {}
+
+ /**
+ *
+ */
+ StackItem &operator=(const StackItem &other)
+ { assign(other); return *this; }
+
+ //treat the stack item like an union of string, integer, and double
+
+ /**
+ * String value
+ */
+ DOMString sval;
+
+ /**
+ * Integer value
+ */
+ long ival;
+
+ /**
+ * Double value;
+ */
+ double dval;
+
+
+private:
+
+ void init()
+ {
+ sval = "";
+ ival = 0;
+ dval = 0.0;
+ }
+
+ void assign(const StackItem &other)
+ {
+ sval = other.sval;
+ ival = other.ival;
+ dval = other.dval;
+ }
+
+};
+
+
+
+//########################################################################
+//# X P A T H T O K E N
+//########################################################################
+
+class Token;
+class Stack;
+
+typedef bool (*TokenFunc)(Token &tok, Stack &stack);
+
+
+/**
+ * This is a pseudocode-type class that executes itself on a stack,
+ * much like stack-oriented languages such as FORTH or Postscript.
+ * Each token can pop zero or more tokens off the stack, and push
+ * zero or one token back onto it. When a list of tokens is completed,
+ * a single stack value should be left on the stack.
+ */
+class Token
+{
+public:
+
+ /**
+ * Token types. Look in xpathtoken.cpp's function table
+ * to see how these types map to their respective
+ * functionalities
+ */
+ typedef enum
+ {
+ //primitives
+ TOK_NOP = 0,
+ TOK_STR,
+ TOK_INT,
+ TOK_FLOAT,
+ //operators
+ TOK_AND,
+ TOK_OR,
+ TOK_MOD,
+ TOK_DIV,
+ TOK_MUL,
+ TOK_DOUBLE_SLASH,
+ TOK_SLASH,
+ TOK_PIPE,
+ TOK_PLUS,
+ TOK_MINUS,
+ TOK_NEG,
+ TOK_EQUALS,
+ TOK_NOT_EQUALS,
+ TOK_LESS_THAN_EQUALS,
+ TOK_LESS_THAN,
+ TOK_GREATER_THAN_EQUALS,
+ TOK_GREATER_THAN,
+ //path types
+ TOK_ABSOLUTE,
+ TOK_RELATIVE,
+ TOK_STEP,
+ TOK_NAME_TEST,
+ TOK_EXPR,
+ TOK_UNION,
+ //axis types
+ TOK_AXIS_ANCESTOR_OR_SELF,
+ TOK_AXIS_ANCESTOR,
+ TOK_AXIS_ATTRIBUTE,
+ TOK_AXIS_CHILD,
+ TOK_AXIS_DESCENDANT_OR_SELF,
+ TOK_AXIS_DESCENDANT,
+ TOK_AXIS_FOLLOWING_SIBLING,
+ TOK_AXIS_FOLLOWING,
+ TOK_AXIS_NAMESPACE,
+ TOK_AXIS_PARENT,
+ TOK_AXIS_PRECEDING_SIBLING,
+ TOK_AXIS_PRECEDING,
+ TOK_AXIS_SELF,
+ //function types
+ TOK_FUNC_LAST,
+ TOK_FUNC_POSITION,
+ TOK_FUNC_COUNT,
+ TOK_FUNC_ID,
+ TOK_FUNC_LOCAL_NAME,
+ TOK_FUNC_NAMESPACE_URI,
+ TOK_FUNC_NAME,
+ TOK_FUNC_STRING,
+ TOK_FUNC_CONCAT,
+ TOK_FUNC_STARTS_WITH,
+ TOK_FUNC_CONTAINS,
+ TOK_FUNC_SUBSTRING_BEFORE,
+ TOK_FUNC_SUBSTRING_AFTER,
+ TOK_FUNC_SUBSTRING,
+ TOK_FUNC_STRING_LENGTH,
+ TOK_FUNC_NORMALIZE_SPACE,
+ TOK_FUNC_TRANSLATE,
+ TOK_FUNC_BOOLEAN,
+ TOK_FUNC_NOT,
+ TOK_FUNC_TRUE,
+ TOK_FUNC_FALSE,
+ TOK_FUNC_LANG,
+ TOK_FUNC_NUMBER,
+ TOK_FUNC_SUM,
+ TOK_FUNC_FLOOR,
+ TOK_FUNC_CEILING,
+ TOK_FUNC_ROUND,
+ } TokenType;
+
+
+
+
+ /**
+ * Constructor with a NOP default type
+ */
+ Token()
+ { init(); }
+
+ /**
+ * Constructor with a NOP default type
+ */
+ Token(int typeArg)
+ { init(); type = typeArg; }
+
+ /**
+ * Constructor with a NOP default type
+ */
+ Token(int typeArg,
+ long ivalArg, double dvalArg, const DOMString &svalArg)
+ {
+ init();
+ type = typeArg,
+ ival = ivalArg;
+ dval = dvalArg;
+ sval = svalArg;
+ }
+
+ /**
+ * Copy constructor
+ */
+ Token(const Token &other)
+ { assign(other); }
+
+ /**
+ * Assignment
+ */
+ Token &operator=(const Token &other)
+ { assign(other); return *this; }
+
+ /**
+ * Destructor
+ */
+ virtual ~Token()
+ {}
+
+ /**
+ * Return the enumerated TokenType of this token
+ */
+ virtual int getType()
+ { return type; }
+
+ /**
+ * Return true if the type is one of the Axis types
+ * above;
+ */
+ virtual bool isAxis()
+ {
+ return type>=TOK_AXIS_ANCESTOR_OR_SELF &&
+ type <= TOK_AXIS_SELF;
+ }
+ /**
+ * Return the string TokenType of this token
+ */
+ virtual DOMString getTypeString();
+
+ /**
+ * Let this token execute itself on the given stack,
+ * possibly adding Nodes to the node list.
+ */
+ virtual bool execute(Stack &stack)
+ {
+ if (tokenFunc)
+ return tokenFunc(*this, stack);
+ return false;
+ }
+
+ /**
+ * Print the contents of this token
+ */
+ virtual void dump()
+ {
+ printf("%s %s %f %ld\n",
+ getTypeString().c_str(), sval.c_str(), dval, ival);
+ }
+
+ //treat the token like an union of string, integer, and double
+
+ /**
+ * String value
+ */
+ DOMString sval;
+
+ /**
+ * Integer value
+ */
+ long ival;
+
+ /**
+ * Double value;
+ */
+ double dval;
+
+ /**
+ *
+ */
+ static Token create(int type, long ival,
+ double dval, const DOMString &sval);
+
+ /**
+ *
+ */
+ static Token create(int type)
+ { return create(type, 0, 0.0, ""); }
+
+ /**
+ *
+ */
+ static Token create(int type, long val)
+ { return create(type, val, 0.0, ""); }
+
+ /**
+ *
+ */
+ static Token create(int type, double val)
+ { return create(type, 0, val, ""); }
+
+ /**
+ *
+ */
+ static Token create(int type, const DOMString &val)
+ { return create(type, 0, 0.0, val); }
+
+
+
+protected:
+
+ /**
+ * The enmerated token type
+ */
+ int type;
+
+ /**
+ * The function that defines the behaviour of this token
+ */
+ TokenFunc tokenFunc;
+
+
+private:
+
+ void init()
+ {
+ tokenFunc = NULL;
+ type = TOK_NOP;
+ ival = 0L;
+ dval = 0.0;
+ //sval = ""; //not necessary
+ }
+
+ void assign(const Token &other)
+ {
+ tokenFunc = other.tokenFunc;
+ type = other.type;
+ sval = other.sval;
+ ival = other.ival;
+ dval = other.dval;
+ }
+
+
+};
+
+
+//########################################################################
+//# S T A C K
+//########################################################################
+
+/**
+ *
+ */
+class Stack
+{
+public:
+
+ //# From 2.3, principal type of child axes
+ typedef enum
+ {
+ AXIS_ATTRIBUTE,
+ AXIS_NAMESPACE,
+ AXIS_ELEMENT
+ } PrincipalNodeType;
+
+ /**
+ * Constructor
+ */
+ Stack(TokenExecutor &par) : parent(par)
+ { clear(); }
+
+ /**
+ * Copy constructor
+ */
+ Stack(const Stack &other) : parent(other.parent)
+ { assign(other); }
+
+ /**
+ * Destructor
+ */
+ virtual ~Stack()
+ {}
+
+ /**
+ *
+ */
+ Stack &operator=(const Stack &other)
+ { assign(other); return *this; }
+
+ /**
+ *
+ */
+ void push(StackItem &item)
+ { return stackItems.push_back(item); }
+
+ /**
+ *
+ */
+ StackItem pop()
+ {
+ if (stackItems.size() < 1)
+ {
+ //TODO: error here
+ StackItem item;
+ return item;
+ }
+ std::vector<StackItem>::iterator iter =
+ stackItems.end() - 1;
+ StackItem item = *iter;
+ stackItems.erase(iter);
+ return item;
+ }
+
+ /**
+ *
+ */
+ virtual void clear()
+ {
+ stackItems.clear();
+ principalNodeType = AXIS_ELEMENT;
+ }
+
+private:
+
+ void assign(const Stack &other)
+ {
+ principalNodeType = other.principalNodeType;
+ stackItems = other.stackItems;
+ }
+
+ int principalNodeType;
+
+ std::vector<StackItem> stackItems;
+
+ TokenExecutor &parent;
+
+};
+
+
+
+
+//########################################################################
+//# T O K E N L I S T
+//########################################################################
+
+/**
+ *
+ */
+class TokenList
+{
+public:
+
+ /**
+ *
+ */
+ TokenList()
+ { init(); }
+
+ /**
+ *
+ */
+ TokenList(const TokenList &other)
+ { assign(other); }
+
+ /**
+ *
+ */
+ TokenList &operator=(const TokenList &other)
+ { assign(other); return *this; }
+
+ /**
+ *
+ */
+ virtual ~TokenList()
+ { }
+
+
+ /**
+ *
+ */
+ virtual void add(const Token &token)
+ { tokens.push_back(token); }
+
+ /**
+ *
+ */
+ virtual std::vector<Token> &getTokens()
+ { return tokens; }
+
+ /**
+ *
+ */
+ virtual void dump()
+ {
+ for (unsigned int i=0 ; i<tokens.size() ; i++)
+ {
+ Token token = tokens[i];
+ token.dump();
+ }
+ }
+
+ /**
+ *
+ */
+ virtual void clear()
+ {
+ tokens.clear();
+ }
+
+private:
+
+
+ void init()
+ {
+ clear();
+ }
+
+ void assign(const TokenList &other)
+ {
+ tokens = other.tokens;
+ }
+
+ std::vector<Token> tokens;
+
+
+};
+
+
+
+
+//########################################################################
+//# T O K E N E X E C U T O R
+//########################################################################
+
+
+/**
+ * A token evaluator, with stack and axis context
+ */
+class TokenExecutor
+{
+public:
+
+ /**
+ * Constructor
+ */
+ TokenExecutor();
+
+ /**
+ * Copy constructor
+ */
+ TokenExecutor(const TokenExecutor &other);
+
+ /**
+ * Destructor
+ */
+ virtual ~TokenExecutor();
+
+ /**
+ * Assign our values to those of the other
+ */
+ virtual void assign(const TokenExecutor &other);
+
+ /**
+ * Reset the stack to its original settings
+ */
+ virtual void reset();
+
+ /**
+ * Execute a list upon a given node. For each Axis encountered,
+ * get the nodes encountered so far, and execute the rest of the
+ * list of tokens upon each of the nodes.
+ */
+ int execute(std::vector<Token> &tokens,
+ int position,
+ const NodePtr node,
+ NodeList &nodeList);
+
+ /**
+ * Execute a token list on the stack
+ */
+ bool execute(TokenList &list,
+ const NodePtr node,
+ NodeList &result);
+
+private:
+
+ /**
+ *
+ */
+ TokenList tokenList;
+
+ /**
+ *
+ */
+ NodeList nodeList;
+
+
+};
+
+
+
+
+} // namespace xpath
+} // namespace dom
+} // namespace w3c
+} // namespace org
+
+
+
+
+
+
+#endif /* __XPATHTOKEN_H__ */
+//########################################################################
+//# E N D O F F I L E
+//########################################################################
+