Ardour  9.0-pre0-582-g084a23a80d
treeiter.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 // Generated by gmmproc 2.45.3 -- DO NOT MODIFY!
3 #ifndef _GTKMM_TREEITER_H
4 #define _GTKMM_TREEITER_H
5 
6 #include <gtkmmconfig.h>
7 
8 
9 #include <glibmm/ustring.h>
10 #include <sigc++/sigc++.h>
11 
12 /* $Id: treeiter.hg,v 1.14 2005/04/07 08:46:44 murrayc Exp $ */
13 
14 /* Copyright(C) 1998-2002 The gtkmm Development Team
15  *
16  * This library is free software, ) you can redistribute it and/or
17  * modify it under the terms of the GNU Lesser General Public
18  * License as published by the Free Software Foundation, ) either
19  * version 2.1 of the License, or(at your option) any later version.
20  *
21  * This library is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY, ) without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24  * Lesser General Public License for more details.
25  *
26  * You should have received a copy of the GNU Lesser General Public
27  * License along with this library, ) if not, write to the Free
28  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29  */
30 
31 
32 #include <gtkmm/treemodelcolumn.h>
33 #include <iterator>
34 #include <gtk/gtk.h> /* for GtkTreeIter */
35 
36 namespace Gtk
37 {
38 
39 class TreeModel;
40 class TreeRow;
41 class TreeNodeChildren;
42 
47 {
48  public:
49 #ifndef DOXYGEN_SHOULD_SKIP_THIS
50  typedef TreeIterBase CppObjectType;
51  typedef GtkTreeIter BaseObjectType;
52 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
53 
56  static GType get_type() G_GNUC_CONST;
57 
59 
60  explicit TreeIterBase(const GtkTreeIter* gobject); // always takes a copy
61 
63  GtkTreeIter* gobj() { return &gobject_; }
64 
66  const GtkTreeIter* gobj() const { return &gobject_; }
67 
68 protected:
70 
71 private:
72 
73 
74  //A wrap() for TreeIterBase* wouldn't be very helpful.
75 
76 
77 };
78 
79 
80 // In order to offer STL-like iterator functionality, we cannot wrap
81 // GtkTreeIter directly. Most GTK+ functions that operate on GtkTreeIter
82 // are virtual functions in GtkTreeModel. Therefore, the C++ TreeIter
83 // must store a pointer to the Gtk::TreeModel to which it belongs.
84 //
85 // Another problem, which is much worse, is that the GTK+ tree iterator
86 // doesn't support the STL-style half-open interval [begin,end). Instead,
87 // it uses a [first,last] interval, and functions return FALSE to indicate
88 // the end was reached. Also, some functions accept a NULL GtkTreeIter*,
89 // which will be interpreted as the end() iterator.
90 //
91 // Most of the immense complexity in the Gtk::TreeIter implementation is
92 // needed for proper emulation of [begin,end) intervals. Unfortunately,
93 // it's not even possible to encapsulate everything in the TreeIter
94 // class. Almost all wrapper methods dealing with GtkTreeIter must be
95 // carefully implemented by hand. TODO: document implementation details
96 
97 //TODO: Implement a const_iterator too:
98 //danielk says that this ConstTreeIter class should return a ConstTreeRow, which would not allow operator=.
99 
129 class TreeIter : public TreeIterBase
130 {
131 public:
132  typedef std::bidirectional_iterator_tag iterator_category;
134  typedef int difference_type;
135  typedef const Gtk::TreeRow& reference;
136  typedef const Gtk::TreeRow* pointer;
137 
139 
141  const TreeIter operator++(int);
142 
146 
149  const TreeIter operator--(int);
150 
151  inline reference operator*() const;
152  inline pointer operator->() const;
153 
154  bool equal(const TreeIter& other) const;
155 
158  operator bool() const;
159 
165  int get_stamp() const;
166 
173  void set_stamp(int stamp);
174 
175 #ifndef DOXYGEN_SHOULD_SKIP_THIS
176 
177  explicit TreeIter(TreeModel* model); // used in TreeModel methods
178  TreeIter(GtkTreeModel* model, const GtkTreeIter* iter); // used by signal proxies
179 
180  void set_model_refptr(const Glib::RefPtr<TreeModel>& model);
181  void set_model_gobject(GtkTreeModel* model);
182  GtkTreeModel* get_model_gobject() const;
183 
184  void setup_end_iterator(const TreeIter& last_valid);
185 
186  const GtkTreeIter* get_gobject_if_not_end() const
187  { return (!is_end_) ? &gobject_ : 0; }
188 
189  const GtkTreeIter* get_parent_gobject_if_end() const
190  { return (is_end_ && gobject_.stamp) ? &gobject_ : 0; }
191 
192 protected:
193 
194  // Yes, using a simple TreeModel* rather than Glib::RefPtr<TreeModel>
195  // violates the general policy. But Gtk::TreeIter should have a trivial
196  // copy constructor and assignment operator, i.e. it must contain only
197  // POD (plain old data).
198  //
199  // Gtk::TreeIter is copied a lot, particularly often as return value from
200  // methods. Postfix ++ must return by value, and STL algorithms usually
201  // pass iterators by value, too. With a RefPtr<> as member data, copying
202  // would no longer be trivial, and even cause frequent calls to reference()
203  // and unreference(). That usually doesn't matter much for GUI stuff, but
204  // Gtk::TreeModel is used as a generic container. Imagine a for-loop that
205  // checks whether iter != children.end() on each iteration.
206 
207  TreeModel* model_;
208  bool is_end_;
209 
210  friend class Gtk::TreeRow;
211  friend class Gtk::TreeNodeChildren;
212  friend class Gtk::TreeModel;
213 
214 #endif // DOXYGEN_SHOULD_SKIP_THIS
215 };
216 
218 inline bool operator==(const TreeIter& lhs, const TreeIter& rhs)
219  { return lhs.equal(rhs); }
220 
222 inline bool operator!=(const TreeIter& lhs, const TreeIter& rhs)
223  { return !lhs.equal(rhs); }
224 
225 
226 template <class ColumnType>
228 {
229 public:
230 #ifndef DOXYGEN_SHOULD_SKIP_THIS
231  inline TreeValueProxy(const TreeRow& row, const TreeModelColumn<ColumnType>& column);
232 #endif
233 
234  inline TreeValueProxy<ColumnType>& operator=(const ColumnType& data);
235  inline operator ColumnType() const;
236 
237 private:
238  const TreeRow& row_;
240 
241  // no copy assignment
243 };
244 
245 
257 class TreeRow : public TreeIter //We use public inheritance so that we can cast from a TreeRow to a TreeIter.
258 {
259 public:
260 
269  template <class ColumnType> inline
271 
281  template <class ColumnType>
282  void set_value(const TreeModelColumn<ColumnType>& column, const ColumnType& data) const;
283 
290  template <class ColumnType>
291  void set_value(int column, const ColumnType& data) const;
292 
302  template <class ColumnType>
303  ColumnType get_value(const TreeModelColumn<ColumnType>& column) const;
304 
314  template <class ColumnType>
315  void get_value(int column, ColumnType& data) const;
316 
320  const TreeNodeChildren& children() const;
321 
325  TreeIter parent() const;
326 
329  operator bool() const;
330 
332  GtkTreeIter* gobj() { return TreeIter::gobj(); }
333 
335  const GtkTreeIter* gobj() const { return TreeIter::gobj(); }
336 
337 private:
338  // Forwarders to Gtk::TreeModel virtual methods.
339  void set_value_impl(int column, const Glib::ValueBase& value) const;
340  void get_value_impl(int column, Glib::ValueBase& value) const;
341 };
342 
343 
344 //TODO: Document begin(), end(), size(), etc, in an STL-style way. murrayc.
345 
351 {
352 public:
354  typedef unsigned int size_type;
355  typedef int difference_type;
357 
358  #ifndef GLIBMM_HAVE_SUN_REVERSE_ITERATOR
359  typedef std::reverse_iterator<iterator> reverse_iterator;
360  #else
361  typedef std::reverse_iterator<iterator, std::random_access_iterator_tag,
362  int, int&, int*, ptrdiff_t> reverse_iterator;
363  #endif
364 
365  typedef Gtk::TreeIter const_iterator; //TODO: Make it a real const_iterator.
366 
367  #ifndef GLIBMM_HAVE_SUN_REVERSE_ITERATOR
368  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
369  #else
370  typedef std::reverse_iterator<const_iterator, std::random_access_iterator_tag,
371  int, const int&, const int*, ptrdiff_t> const_reverse_iterator;
372  #endif
373 
378 
379  // Note: there is no advantage in not inlining these methods.
380  // We can't change them without breaking ABI anyway.
385 
387 
388  size_type size() const;
389  bool empty() const;
390  operator bool() const { return !empty(); }
391 
392 #ifndef DOXYGEN_SHOULD_SKIP_THIS
393 
394  explicit TreeNodeChildren(TreeModel* model)
395  : TreeIter(model) {}
396 
397  const GtkTreeIter* get_parent_gobject() const
398  { return (gobject_.stamp != 0) ? &gobject_ : 0; }
399 
400 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
401 };
402 
403 
404 #ifndef DOXYGEN_SHOULD_SKIP_THIS
405 
406 /**** Gtk::TreeIter ********************************************************/
407 
408 inline
410 {
411  return static_cast<const TreeRow&>(*this);
412 }
413 
414 inline
416 {
417  return static_cast<const TreeRow*>(this);
418 }
419 
420 
421 /**** Gtk::TreeValueProxy<> ************************************************/
422 
423 template <class ColumnType> inline
424 TreeValueProxy<ColumnType>::TreeValueProxy(const TreeRow& row, const TreeModelColumn<ColumnType>& column)
425 :
426  row_ (row),
427  column_ (column)
428 {}
429 
430 template <class ColumnType> inline
431 TreeValueProxy<ColumnType>& TreeValueProxy<ColumnType>::operator=(const ColumnType& data)
432 {
433  row_.set_value(column_, data);
434  return *this;
435 }
436 
437 template <class ColumnType> inline
438 TreeValueProxy<ColumnType>::operator ColumnType() const
439 {
440  return row_.get_value(column_);
441 }
442 
443 
444 /**** Gtk::TreeRow *********************************************************/
445 
446 template <class ColumnType> inline
447 TreeValueProxy<ColumnType> TreeRow::operator[](const TreeModelColumn<ColumnType>& column) const
448 {
449  return TreeValueProxy<ColumnType>(*this, column);
450 }
451 
452 template <class ColumnType>
453 void TreeRow::set_value(const TreeModelColumn<ColumnType>& column, const ColumnType& data) const
454 {
455  typedef typename Gtk::TreeModelColumn<ColumnType>::ValueType ValueType;
456 
457  ValueType value;
458  value.init(column.type());
459 
460  value.set(data);
461  this->set_value_impl(column.index(), value);
462 }
463 
464 template <class ColumnType>
465 void TreeRow::set_value(int column, const ColumnType& data) const
466 {
467  //This could fail at run-time, because the wrong ColumnType might be used.
468  //It's only for dynamically generated model columns.
469 
470  typedef typename Gtk::TreeModelColumn<ColumnType> type_cppcolumn;
471  typedef typename type_cppcolumn::ValueType ValueType;
472 
473  ValueType value;
474  value.init(ValueType::value_type());
475 
476  value.set(data);
477  this->set_value_impl(column, value);
478 }
479 
480 template <class ColumnType>
481 ColumnType TreeRow::get_value(const TreeModelColumn<ColumnType>& column) const
482 {
483  typedef typename Gtk::TreeModelColumn<ColumnType>::ValueType ValueType;
484 
485  ValueType value;
486  this->get_value_impl(column.index(), value);
487 
488  return value.get();
489 }
490 
491 template <class ColumnType>
492 void TreeRow::get_value(int column, ColumnType& data) const
493 {
494  //This could fail at run-time, because the wrong ColumnType might be used.
495  //It's only for dynamically generated model columns.
496 
497  typedef typename Gtk::TreeModelColumn<ColumnType>::ValueType ValueType;
498 
499  ValueType value;
500  this->get_value_impl(column, value);
501 
502  data = value.get();
503 }
504 
505 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
506 
507 } // namespace Gtk
508 
509 
510 namespace Glib
511 {
512 
513 #ifndef DOXYGEN_SHOULD_SKIP_THIS
514 template <>
515 class Value<Gtk::TreeIterBase> : public Glib::Value_Boxed<Gtk::TreeIterBase>
516 {};
517 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
518 
519 } // namespace Glib
520 
521 
522 #endif /* _GTKMM_TREEITER_H */
523 
GtkTreeIter * gobj()
Provides access to the underlying C instance.
Definition: treeiter.h:63
const GtkTreeIter * gobj() const
Provides access to the underlying C instance.
Definition: treeiter.h:66
GtkTreeIter gobject_
Definition: treeiter.h:69
static GType get_type() G_GNUC_CONST
bool operator==(const TreeIter &lhs, const TreeIter &rhs)
Definition: treeiter.h:218
TreeIter & operator++()
const TreeIter operator++(int)
const Gtk::TreeRow & reference
Definition: treeiter.h:135
const Gtk::TreeRow * pointer
Definition: treeiter.h:136
bool equal(const TreeIter &other) const
bool operator!=(const TreeIter &lhs, const TreeIter &rhs)
Definition: treeiter.h:222
pointer operator->() const
const TreeIter operator--(int)
int get_stamp() const
int difference_type
Definition: treeiter.h:134
reference operator*() const
std::bidirectional_iterator_tag iterator_category
Definition: treeiter.h:132
Gtk::TreeRow value_type
Definition: treeiter.h:133
void set_stamp(int stamp)
TreeIter & operator--()
Glib::Value< T > ValueType
size_type size() const
std::reverse_iterator< iterator > reverse_iterator
Definition: treeiter.h:359
Gtk::TreeIter const_iterator
Definition: treeiter.h:365
Gtk::TreeRow value_type
Definition: treeiter.h:353
const_reverse_iterator rbegin() const
Definition: treeiter.h:383
reverse_iterator rend()
Definition: treeiter.h:382
const_iterator begin() const
const_reverse_iterator rend() const
Definition: treeiter.h:384
unsigned int size_type
Definition: treeiter.h:354
value_type operator[](size_type index) const
const_iterator end() const
Gtk::TreeIter iterator
Definition: treeiter.h:356
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: treeiter.h:368
reverse_iterator rbegin()
Definition: treeiter.h:381
const GtkTreeIter * gobj() const
Provides access to the underlying C GObject.
Definition: treeiter.h:335
const TreeNodeChildren & children() const
GtkTreeIter * gobj()
Provides access to the underlying C GObject.
Definition: treeiter.h:332
TreeIter parent() const
ColumnType get_value(const TreeModelColumn< ColumnType > &column) const
void set_value(const TreeModelColumn< ColumnType > &column, const ColumnType &data) const
void get_value_impl(int column, Glib::ValueBase &value) const
void set_value(int column, const ColumnType &data) const
TreeValueProxy< ColumnType > operator[](const TreeModelColumn< ColumnType > &column) const
void get_value(int column, ColumnType &data) const
void set_value_impl(int column, const Glib::ValueBase &value) const
TreeValueProxy< ColumnType > & operator=(const ColumnType &data)
const TreeModelColumn< ColumnType > & column_
Definition: treeiter.h:239
TreeValueProxy< ColumnType > & operator=(const TreeValueProxy< ColumnType > &)
const TreeRow & row_
Definition: treeiter.h:238
struct _GtkTreeModel GtkTreeModel
Definition: gtktreemodel.h:46
Definition: ardour_ui.h:188
Definition: lobject.h:100