Dillo
iterator.hh
Go to the documentation of this file.
1 #ifndef __ITERATOR_HH__
2 #define __ITERATOR_HH__
3 
4 #ifndef __INCLUDED_FROM_DW_CORE_HH__
5 # error Do not include this file directly, use "core.hh" instead.
6 #endif
7 
8 namespace dw {
9 namespace core {
10 
20 {
21 protected:
22  Iterator(Widget *widget, Content::Type mask, bool atEnd);
23  Iterator(Iterator &it);
24  ~Iterator();
25 
27 
28 private:
31 
32 public:
33  bool equals (Object *other);
34 
35  inline Widget *getWidget () { return widget; }
36  inline Content *getContent () { return &content; }
37  inline Content::Type getMask () { return mask; }
38 
39  virtual void unref ();
40 
46  virtual bool next () = 0;
47 
53  virtual bool prev () = 0;
54 
63  virtual void highlight (int start, int end, HighlightLayer layer) = 0;
64 
73  virtual void unhighlight (int direction, HighlightLayer layer) = 0;
74 
82  virtual void getAllocation (int start, int end, Allocation *allocation) = 0;
83 
84  inline Iterator *cloneIterator () { return (Iterator*)clone(); }
85 
86  static void scrollTo (Iterator *it1, Iterator *it2, int start, int end,
87  HPosition hpos, VPosition vpos);
88 };
89 
90 
95 class EmptyIterator: public Iterator
96 {
97 private:
99 
100 public:
101  EmptyIterator (Widget *widget, Content::Type mask, bool atEnd);
102 
104  int compareTo(lout::misc::Comparable *other);
105  bool next ();
106  bool prev ();
107  void highlight (int start, int end, HighlightLayer layer);
108  void unhighlight (int direction, HighlightLayer layer);
109  void getAllocation (int start, int end, Allocation *allocation);
110 };
111 
112 
117 class TextIterator: public Iterator
118 {
119 private:
121  const char *text;
122 
124 
125 public:
127  const char *text);
128 
129  int compareTo(lout::misc::Comparable *other);
130 
131  bool next ();
132  bool prev ();
133  void getAllocation (int start, int end, Allocation *allocation);
134 };
135 
136 
146 {
147 private:
148  class Stack: public lout::container::typed::Vector<Iterator>
149  {
150  public:
151  inline Stack (): lout::container::typed::Vector<Iterator> (4, false) { }
152  ~Stack ();
153  inline Iterator *getTop () { return get (size () - 1); }
154  inline void push (Iterator *it) { put(it, -1); }
155  inline void pop() { getTop()->unref (); remove (size () - 1); }
156  };
157 
159 
161  bool fromEnd);
163  bool fromEnd);
164 
168 
169  inline DeepIterator () { }
170 
171 public:
172  DeepIterator(Iterator *it);
173  ~DeepIterator();
174 
176 
178  inline Iterator *getTopIterator () { return stack.getTop(); }
179  inline Content *getContent () { return &content; }
180 
181  bool isEmpty ();
182 
183  bool next ();
184  bool prev ();
186  int compareTo(lout::misc::Comparable *other);
187 
196  inline void highlight (int start, int end, HighlightLayer layer)
197  { stack.getTop()->highlight (start, end, layer); }
198 
206  inline void getAllocation (int start, int end, Allocation *allocation)
207  { stack.getTop()->getAllocation (start, end, allocation); }
208 
209  inline void unhighlight (int direction, HighlightLayer layer)
210  { stack.getTop()->unhighlight (direction, layer); }
211 
212  inline static void scrollTo (DeepIterator *it1, DeepIterator *it2,
213  int start, int end,
214  HPosition hpos, VPosition vpos)
215  { Iterator::scrollTo(it1->stack.getTop(), it2->stack.getTop(),
216  start, end, hpos, vpos); }
217 };
218 
220 {
221 public:
222  // START and END must not clash with any char value
223  // neither for signed nor unsigned char.
224  enum { START = 257, END = 258 };
225 
226 private:
228  int pos, ch;
229 
230  CharIterator ();
231 
232 public:
233  CharIterator (Widget *widget);
234  ~CharIterator ();
235 
237  int compareTo(lout::misc::Comparable *other);
238 
239  bool next ();
240  bool prev ();
241  inline int getChar() { return ch; }
243 
244  static void highlight (CharIterator *it1, CharIterator *it2,
245  HighlightLayer layer);
246  static void unhighlight (CharIterator *it1, CharIterator *it2,
247  HighlightLayer layer);
248 
249  inline static void scrollTo (CharIterator *it1, CharIterator *it2,
250  HPosition hpos, VPosition vpos)
251  { DeepIterator::scrollTo(it1->it, it2->it, it1->pos, it2->pos,
252  hpos, vpos); }
253 };
254 
255 } // namespace dw
256 } // namespace core
257 
258 #endif // __ITERATOR_HH__