23 #ifndef libmath_nodes_h
24 #define libmath_nodes_h
47 template<
typename>
class TNode;
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();
142 bool operator!=(
const TNodeIterator<T>& a,
const TNodeIterator<T>& b) {
143 return a.get() != b.get();
150 template <
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();
220 bool operator!=(
const TOperandIter<T>& a,
const TOperandIter<T>& b) {
221 return a.get() != b.get();
227 template <
typename T>
230 typedef TNodeIterator<T> iterator;
231 typedef const TNodeIterator<T> const_iterator;
233 typedef TOperandIter<TNode<T> > operand_iterator;
234 typedef TOperandIter<const TNode<T> > const_operand_iterator;
328 template<
typename T>
bool operator==(
const TNode<T>&,
const TNode<T>&);
329 template<
typename T>
bool operator!=(
const TNode<T>&,
const TNode<T>&);
362 std::string
symbol()
const;
390 std::auto_ptr<TNode<T> > FNode;
411 class TBinaryNodeOp :
public TNode<T> {
413 std::auto_ptr<TNode<T> > FLeft;
414 std::auto_ptr<TNode<T> > FRight;
422 virtual TNode<T> *
left()
const;
425 virtual TNode<T> *
right()
const;
427 virtual bool equals(
const TNode<T> *ANode)
const;
434 template <
typename T>
573 std::string name()
const;
588 std::auto_ptr<TNode<T> > FCondition;
662 #include <math++/nodes.tcc>
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TGreaterEquNode * 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 TNode< T > * right() const
returns the child node (wrapper to the more declarative node() method)
virtual TMulNode * clone() const
clones that node
TNodeType nodeType() const
returns the type of this node
virtual TFuncNode< T > * clone() const
clones that node
void parent(TNode< T > *AParent)
initializes the parent node with the given one
virtual TEquNode * clone() const
clones that node
virtual TGreaterNode * clone() const
clones that node
virtual TNode< T > * left() const
returns the left child node (returns 0 if this node doesn't support one)
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
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 bool equals(const TNode< T > *ANode) const
returns true, if given node equals to this one
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 void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TLessEquNode * clone() const
clones that node
virtual TSymbolNode< T > * 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 TNumberNode< T > * clone() const
clones that node
TNode< T > * node() const
returns the child node for that unary operator node.
virtual TSqrtNode * clone() const
clones that node
iterator begin()
iterator access to the first value node in this operator level
virtual bool equals(const TNode< T > *ANode) const =0
returns true, if given node equals to this one
virtual TNode< T > * right() const
returns the left child node of the expression tree
virtual TSinNode * 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
TNode(TNodeType ANodeType, short APriority, TNode< T > *AParentNode=0)
initializes this node for given node type.
virtual TParamNode< 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 ~TNode()
each virtual class needs a virtual destructor (this one does nothing)
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TNode< T > * right() const
returns the right child node (returns 0 if this node doesn't support one)
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
iterator end()
iterator access to the end
virtual bool equals(const TNode< T > *ANode) const
returns true, if given node equals to this one
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual void accept(TNodeVisitor< T > &)=0
calls the visit method in TNodeVisitor<>
virtual TNode< T > * left() const
returns the right child node of the expression tree
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TPowNode * 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 TCosNode * clone() const
clones that node
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TLessNode * clone() const
clones that node
virtual TDivNode * clone() const
clones that node
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TUnEquNode * clone() const
clones that node
TBinaryNodeOp(typename TBinaryNodeOp< T >::TNodeType AType, short APrio, TNode< T > *ALeft, TNode< T > *ARight)
creates an binary operator node of type AType
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual void accept(TNodeVisitor< T > &)
calls the visit method in TNodeVisitor<>
virtual TNode< T > * clone() const =0
clones that node
virtual TIfNode * clone() const
clones that node
TUnaryNodeOp(typename TUnaryNodeOp< T >::TNodeType AType, short APriority, TNode< T > *ANode)
creates an unary operator node of type AType.
virtual TLnNode * clone() const
clones that node