MADARA  3.1.8
IteratorImpl.h
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 #ifndef _MADARA_TREE_ITERATOR_IMPL_H_
3 #define _MADARA_TREE_ITERATOR_IMPL_H_
4 
5 #include <stdlib.h>
6 #include <stdexcept>
7 
11 
12 namespace madara
13 {
14  namespace utility
15  {
16  template <typename T>
17  class Refcounter;
18  }
19 
20  namespace expression
21  {
22  class ComponentNode;
23  class ExpressionTreeIterator;
24  class ExpressionTree;
25 
42  {
43  friend class ExpressionTreeIterator;
44 
45  public:
48 
50  virtual ~ExpressionTreeIteratorImpl (void);
51 
54  virtual ExpressionTree operator* (void) = 0;
55 
58  virtual const ExpressionTree operator* (void) const = 0;
59 
61  virtual void operator++ (void) = 0;
62 
64  virtual bool operator== (const ExpressionTreeIteratorImpl &rhs)
65  const = 0;
66 
68  virtual bool operator!= (const ExpressionTreeIteratorImpl &rhs)
69  const = 0;
70 
72  virtual ExpressionTreeIteratorImpl *clone(void) = 0;
73 
75  typedef ::std::forward_iterator_tag iterator_category;
77  typedef int *pointer;
78  typedef int &reference;
79  typedef int difference_type;
80 
81  protected:
84  };
85 
94  {
95  friend class ExpressionTreeIterator;
97  public:
101  InOrderIteratorImpl (const ExpressionTree &tree,
102  bool end_iter = false);
103 
105  virtual ~InOrderIteratorImpl (void);
106 
109  virtual ExpressionTree operator* (void);
110 
113  virtual const ExpressionTree operator* (void) const;
114 
116  virtual void operator++ (void);
117 
119  virtual bool operator== (const ExpressionTreeIteratorImpl &rhs)
120  const;
121 
123  virtual bool operator!= (const ExpressionTreeIteratorImpl &lhs)
124  const;
125 
127  virtual ExpressionTreeIteratorImpl *clone (void);
128 
129  // = Necessary traits
130  typedef ::std::forward_iterator_tag iterator_category;
132  typedef int *pointer;
133  typedef int &reference;
134  typedef int difference_type;
135 
136  private:
139  };
140 
149  {
152 
153  public:
157  PreOrderIteratorImpl (const ExpressionTree &tree,
158  bool end_iter = false);
159 
161  virtual ~PreOrderIteratorImpl ();
162 
165  virtual ExpressionTree operator* (void);
166 
169  virtual const ExpressionTree operator* (void) const;
170 
172  virtual void operator++ (void);
173 
175  virtual bool operator== (const ExpressionTreeIteratorImpl &rhs)
176  const;
177 
179  virtual bool operator!= (const ExpressionTreeIteratorImpl &lhs)
180  const;
181 
183  virtual ExpressionTreeIteratorImpl *clone (void);
184 
185  // = Necessary traits
186  typedef ::std::forward_iterator_tag iterator_category;
188  typedef int *pointer;
189  typedef int &reference;
190  typedef int difference_type;
191 
192  private:
195  };
196 
205  {
208  public:
209 
214  bool end_iter = false);
215 
217  virtual ~PostOrderIteratorImpl (void);
218 
221  virtual ExpressionTree operator* (void);
222 
225  virtual const ExpressionTree operator* (void) const;
226 
228  virtual void operator++ (void);
229 
231  virtual bool operator== (const ExpressionTreeIteratorImpl &rhs)
232  const;
233 
235  virtual bool operator!= (const ExpressionTreeIteratorImpl &lhs)
236  const;
237 
239  virtual ExpressionTreeIteratorImpl *clone (void);
240 
241  // = Necessary traits
242  typedef ::std::forward_iterator_tag iterator_category;
244  typedef int *pointer;
245  typedef int &reference;
246  typedef int difference_type;
247 
248  private:
251  };
252 
262  {
265  public:
266 
271  bool end_iter = false);
272 
275 
278  virtual ExpressionTree operator* (void);
279 
282  virtual const ExpressionTree operator* (void) const;
283 
285  virtual void operator++ (void);
286 
288  virtual bool operator== (const ExpressionTreeIteratorImpl &rhs) const;
289 
291  virtual bool operator!= (const ExpressionTreeIteratorImpl &lhs) const;
292 
294  virtual ExpressionTreeIteratorImpl *clone (void);
295 
296  // = Necessary traits
297  typedef ::std::forward_iterator_tag iterator_category;
299  typedef int *pointer;
300  typedef int &reference;
301  typedef int difference_type;
302 
303  private:
305  // @@ Consider zapping this.
307  };
308  }
309 }
310 #endif /* _MADARA_TREE_ITERATOR_IMPL_H_ */
This class encapsulates an entry in a KnowledgeBase.
::std::forward_iterator_tag iterator_category
Definition: IteratorImpl.h:186
Encapsulates a MADARA KaRL expression into an evaluatable tree.
madara::knowledge::KnowledgeRecord value_type
Definition: IteratorImpl.h:187
madara::utility::LQueue< ExpressionTree > queue_
Our current position in the iteration.
Definition: IteratorImpl.h:306
madara::utility::LStack< ExpressionTree > stack_
Our current position in the iteration.
Definition: IteratorImpl.h:138
Iterates through an ExpressionTree in in-order.
Definition: IteratorImpl.h:93
madara::knowledge::KnowledgeRecord value_type
Definition: IteratorImpl.h:131
Non-const iterator for traversing an expression tree.
Definition: Iterator.h:26
madara::utility::LStack< ExpressionTree > stack_
Our current position in the iteration.
Definition: IteratorImpl.h:250
madara::knowledge::KnowledgeRecord value_type
Definition: IteratorImpl.h:76
auto operator*(const Tracked< T > &lhs, const Tracked< U > &rhs) -> decltype(lhs.get()*rhs.get())
Definition: Tracked.h:276
madara::knowledge::KnowledgeRecord value_type
Definition: IteratorImpl.h:243
Iterates through an ExpressionTree in post-order.
Definition: IteratorImpl.h:204
madara::utility::LStack< ExpressionTree > stack_
Our current position in the iteration.
Definition: IteratorImpl.h:194
::std::forward_iterator_tag iterator_category
Definition: IteratorImpl.h:130
Iterates through an ExpressionTree in level-order.
Definition: IteratorImpl.h:260
auto operator==(const Tracked< T > &lhs, const Tracked< U > &rhs) -> decltype(lhs.get()==rhs.get())
Definition: Tracked.h:244
auto operator!=(const Tracked< T > &lhs, const Tracked< U > &rhs) -> decltype(lhs.get()!=rhs.get())
Definition: Tracked.h:245
Iterates through an ExpressionTree in level-order.
Definition: IteratorImpl.h:148
Provides utility functions and classes for common tasks and needs.
Definition: IteratorImpl.h:14
Defines a generic "last-in/first-out" (LIFO) Abstract Data Type (ADT) using a stack that&#39;s implemente...
Definition: LStack.h:29
Copyright (c) 2015 Carnegie Mellon University.
::std::forward_iterator_tag iterator_category
= Necessary traits
Definition: IteratorImpl.h:75
::std::forward_iterator_tag iterator_category
Definition: IteratorImpl.h:242
Implementation of the ExpressionTreeIterator pattern that is used to define the various iterations al...
Definition: IteratorImpl.h:41
Defines a generic "first-in/first-out" (FIFO) Abstract Data Type (ADT) using a circular linked list...
Definition: LQueue.h:38
const ExpressionTree & tree_
The tree we are iterating over.
Definition: IteratorImpl.h:83
This template class provides transparent reference counting of its template parameter T...
Definition: IteratorImpl.h:17
auto operator++(Tracked< T > &lhs) -> decltype(++lhs.get_mut())
Definition: Tracked.h:301