23 #ifndef libmath_nodes_h
24 #define libmath_nodes_h
46 template<
typename>
class TNodeVisitor;
47 template<
typename>
class TNode;
48 template<
typename>
class TUnaryNodeOp;
49 template<
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();
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>
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;
413 std::auto_ptr<TNode<T> > FLeft;
414 std::auto_ptr<TNode<T> > FRight;
434 template <
typename T>
573 std::string name()
const;
588 std::auto_ptr<TNode<T> > FCondition;
662 #include <math++/nodes.tcc>