diff --git a/src/dom/xpathtoken.h b/src/dom/xpathtoken.h
index 26aee60f82f040f6be7aca23b945b62fc571169a..9039006278981536bb9302f0627bb10a091cef8d 100644 (file)
--- a/src/dom/xpathtoken.h
+++ b/src/dom/xpathtoken.h
-/**
- * Contains the StackItem stack;
- */
-typedef std::vector<StackItem> Stack;
-
-
//########################################################################
//# X P A T H T O K E N
//########################################################################
class Token;
-class TokenExecutor;
+class Stack;
-typedef bool (*TokenFunc)(Token &tok, TokenExecutor &exec);
+typedef bool (*TokenFunc)(Token &tok, Stack &stack);
/**
*/
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
*/
* Let this token execute itself on the given stack,
* possibly adding Nodes to the node list.
*/
- virtual bool execute(TokenExecutor &exec)
+ virtual bool execute(Stack &stack)
{
if (tokenFunc)
- return tokenFunc(*this, exec);
+ return tokenFunc(*this, stack);
return false;
}
type = TOK_NOP;
ival = 0L;
dval = 0.0;
+ //sval = ""; //not necessary
}
void assign(const Token &other)
//########################################################################
-//# C O N T E X T
+//# S T A C K
//########################################################################
/**
*
*/
-class Context
+class Stack
{
public:
/**
* Constructor
*/
- Context()
- { init(); }
-
- /**
- * Constructor
- */
- Context(int principalNodeTypeArg)
- { init(); principalNodeType = principalNodeTypeArg; }
+ Stack(TokenExecutor &par) : parent(par)
+ { clear(); }
/**
* Copy constructor
*/
- Context(const Context &other)
+ Stack(const Stack &other) : parent(other.parent)
{ assign(other); }
/**
* Destructor
*/
- virtual ~Context()
+ virtual ~Stack()
{}
/**
*
*/
- Context &operator=(const Context &other)
+ Stack &operator=(const Stack &other)
{ assign(other); return *this; }
/**
*
*/
- std::vector<Token> &getTokens()
- { return tokens; }
-
- /**
- *
- */
- void setTokens(const std::vector<Token> &tokensArg)
- { tokens = tokensArg; }
+ void push(StackItem &item)
+ { return stackItems.push_back(item); }
/**
*
*/
- void add(const Token &token)
- { tokens.push_back(token); }
-
- /**
- *
- */
- virtual void dump()
+ StackItem pop()
{
- for (unsigned int i=0 ; i<tokens.size() ; i++)
+ if (stackItems.size() < 1)
{
- Token token = tokens[i];
- token.dump();
+ //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()
{
- tokens.clear();
+ stackItems.clear();
+ principalNodeType = AXIS_ELEMENT;
}
private:
- void init()
- {
- principalNodeType = AXIS_ELEMENT;
- }
-
- void assign(const Context &other)
+ void assign(const Stack &other)
{
principalNodeType = other.principalNodeType;
- tokens = other.tokens;
+ stackItems = other.stackItems;
}
int principalNodeType;
- std::vector<Token> tokens;
+ std::vector<StackItem> stackItems;
+
+ TokenExecutor &parent;
};
+
+
//########################################################################
//# T O K E N L I S T
//########################################################################
virtual ~TokenList()
{ }
+
/**
*
*/
- virtual void add(const Context &contextArg)
- {
- contexts.push_back(currentContext);
- currentContext=contextArg;
- }
+ virtual void add(const Token &token)
+ { tokens.push_back(token); }
/**
*
*/
- virtual void add(const Token &token)
- { currentContext.add(token); }
+ virtual std::vector<Token> &getTokens()
+ { return tokens; }
/**
*
*/
virtual void dump()
{
- for (unsigned int i=0 ; i<contexts.size() ; i++)
+ for (unsigned int i=0 ; i<tokens.size() ; i++)
{
- Context context = contexts[i];
- context.dump();
+ Token token = tokens[i];
+ token.dump();
}
}
*/
virtual void clear()
{
- currentContext.clear();
- contexts.clear();
+ tokens.clear();
}
private:
void assign(const TokenList &other)
{
- currentContext = other.currentContext;
- contexts = other.contexts;
+ tokens = other.tokens;
}
- Context currentContext;
-
- std::vector<Context> contexts;
+ std::vector<Token> tokens;
};
virtual void reset();
/**
- * Push a stack item onto the stack
+ * 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.
*/
- virtual void push(StackItem &item);
-
- /**
- * Pop a stack item from the stack
- */
- virtual StackItem pop();
+ int execute(std::vector<Token> &tokens,
+ int position,
+ const NodePtr node,
+ NodeList &nodeList);
/**
* Execute a token list on the stack
*/
- NodeList execute(const TokenList &list, const Node *node);
+ bool execute(TokenList &list,
+ const NodePtr node,
+ NodeList &result);
private:
- /**
- * Contains the StackItem stack;
- */
- Stack stack;
-
-
/**
*
*/