23#ifndef libmath_nodes_h
24#define libmath_nodes_h
46template<
typename>
class TNodeVisitor;
47template<
typename>
class TNode;
48template<
typename>
class TUnaryNodeOp;
49template<
typename>
class TBinaryNodeOp;
71 if (FCurrent->
right()) {
72 FCurrent = FCurrent->
right();
74 while (FCurrent->
left())
75 FCurrent = FCurrent->
left();
79 while (FCurrent == p->
right()) {
84 if (FCurrent->
right() != p)
93 if (FCurrent->
left()) {
103 while (FCurrent == p->
left()) {
110 return FCurrent != last;
120 friend class TNode<T>;
127 TNode<T>& operator*()
const {
return *FCurrent; }
128 TNode<T> *operator->()
const {
return FCurrent; }
130 TNode<T> *get()
const {
return FCurrent; }
138 return a.get() == b.get();
142bool operator!=(
const TNodeIterator<T>& a,
const TNodeIterator<T>& b) {
143 return a.get() != b.get();
150template <
typename NodeType>
155 TOperandIter(NodeType *AOperator) : FOrigin(AOperator), FCurrent(FOrigin) {
156 do FCurrent = FCurrent->left();
157 while (inScope(FCurrent));
161 FOrigin(AProto.FOrigin), FCurrent(AProto.FCurrent) {}
163 NodeType& operator*()
const {
return *FCurrent; }
164 NodeType *operator->()
const {
return FCurrent; }
166 NodeType *get()
const {
return this ? FCurrent : 0; }
179 NodeType *p = FCurrent->parent();
182 while (p && FCurrent == p->right() && inScope(p)) {
190 if (!p || !inScope(p)) {
195 FCurrent = FCurrent->right();
196 if (inScope(FCurrent)) {
197 do FCurrent = FCurrent->left();
198 while (inScope(FCurrent));
203 bool inScope(
const NodeType *ANode)
const {
204 switch (FOrigin->nodeType()) {
205 case NodeType::PLUS_NODE:
206 case NodeType::MUL_NODE:
207 return ANode->nodeType() == FOrigin->nodeType();
216 return a.get() == b.get();
220bool operator!=(
const TOperandIter<T>& a,
const TOperandIter<T>& b) {
221 return a.get() != b.get();
390 std::auto_ptr<TNode<T> > FNode;
413 std::auto_ptr<TNode<T> > FLeft;
414 std::auto_ptr<TNode<T> > FRight;
573 std::string name()
const;
588 std::auto_ptr<TNode<T> > FCondition;
662#include <math++/nodes.tcc>
virtual TNode< T > * right() const
returns the left child node of the expression tree
TBinaryNodeOp(typename TBinaryNodeOp< T >::TNodeType AType, short APrio, TNode< T > *ALeft, TNode< T > *ARight)
creates an binary operator node of type AType
virtual bool equals(const TNode< T > *ANode) const
returns true, if given node equals to this one
virtual TNode< T > * left() const
returns the right child node of the expression tree
virtual TCosNode * clone() const
clones that node
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TDivNode * clone() const
clones that node
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TEquNode * clone() const
clones that node
virtual TFuncNode< T > * clone() const
clones that node
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TGreaterEquNode * clone() const
clones that node
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TGreaterNode * clone() const
clones that node
virtual TIfNode * clone() const
clones that node
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TLessEquNode * clone() const
clones that node
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TLessNode * clone() const
clones that node
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TLnNode * clone() const
clones that node
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TMulNode * clone() const
clones that node
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TNegNode< T > * clone() const
clones that node
virtual bool equals(const TNode< T > *ANode) const =0
returns true, if given node equals to this one
TNodeType nodeType() const
returns the type of this node
short priority() const
returns the node priority
TNode< T > * parent() const
returns the parent node (returns 0 if this node is the root node)
virtual TNode< T > * left() const
returns the left child node (returns 0 if this node doesn't support one)
virtual TNode< T > * right() const
returns the right child node (returns 0 if this node doesn't support one)
void parent(TNode< T > *AParent)
initializes the parent node with the given one
virtual ~TNode()
each virtual class needs a virtual destructor (this one does nothing)
iterator end()
iterator access to the end
virtual TNode< T > * clone() const =0
clones that node
virtual void accept(TNodeVisitor< T > &)=0
calls the visit method in TNodeVisitor<>
TNode(TNodeType ANodeType, short APriority, TNode< T > *AParentNode=0)
initializes this node for given node type.
iterator begin()
iterator access to the first value node in this operator level
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual bool equals(const TNode< T > *ANode) const
returns true, if given node equals to this one
virtual TNumberNode< T > * clone() const
clones that node
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual bool equals(const TNode< T > *ANode) const
returns true, if given node equals to this one
virtual TParamNode< T > * clone() const
clones that node
virtual TPlusNode< T > * clone() const
clones that node
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TPowNode * clone() const
clones that node
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TSinNode * clone() const
clones that node
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TSqrtNode * clone() const
clones that node
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TSymbolNode< T > * clone() const
clones that node
std::string symbol() const
returns the symbol's name
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual bool equals(const TNode< T > *ANode) const
returns true, if given node equals to this one
virtual TTanNode * clone() const
clones that node
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TUnEquNode * clone() const
clones that node
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TNode< T > * right() const
returns the child node (wrapper to the more declarative node() method)
TUnaryNodeOp(typename TUnaryNodeOp< T >::TNodeType AType, short APriority, TNode< T > *ANode)
creates an unary operator node of type AType.
virtual bool equals(const TNode< T > *ANode) const
returns true, if given node equals to this one
TNode< T > * node() const
returns the child node for that unary operator node.