gtkmm 4.14.0
Public Types | Public Member Functions | Related Functions | List of all members
Gtk::TreeIter< T > Class Template Reference

Typedefed as TreeModel::iterator and TreeModel::const_iterator. More...

#include <gtkmm/treeiter.h>

Inheritance diagram for Gtk::TreeIter< T >:
Inheritance graph
[legend]

Public Types

using iterator_category = std::bidirectional_iterator_tag
 TreeIter instances can be incremented and decremented. More...
 
using value_type = T
 The TreeRow or TreeConstRow type to which the iterator refers. More...
 
using difference_type = int
 This is not used. More...
 
using reference = T &
 A reference to the TreeRow or TreeConstRow type, as yielded by operator*() More...
 
using pointer = T *
 A pointer to the TreeRow or TreeConstRow type, as yielded by operator->() More...
 

Public Member Functions

 TreeIter ()
 Default constructor creates an invalid iterator, not referring to a model. More...
 
template<typename T2 , typename = typename std::enable_if< std::is_same<T, TreeConstRow>::value && std::is_same<T2, TreeRow>::value, T2>::type>
 TreeIter (const TreeIter< T2 > & src)
 iterator to const_iterator conversion. More...
 
template<typename T2 , typename = typename std::enable_if< std::is_same<T, TreeConstRow>::value && std::is_same<T2, TreeRow>::value, T2>::type>
TreeIteroperator= (const TreeIter< T2 > & src)
 iterator to const_iterator assignment. More...
 
TreeIteroperator++ ()
 Increment the iterator to refer to the next position in the model, and return a reference to the iterator as it is after the increment. More...
 
TreeIter operator++ (int)
 Increment the iterator to refer to the next position in the model, but return a copy of the iterator as it was before the increment. More...
 
TreeIteroperator-- ()
 Note that this is very slow compared to operator++(). More...
 
TreeIter operator-- (int)
 Note that this is very slow compared to operator++(int). More...
 
reference operator* () const
 Dereference the iterator to get a TreeRow or TreeConstRow, as appropriate. More...
 
pointer operator-> () const
 Dereference the iterator to get a TreeRow or TreeConstRow, as appropriate. More...
 
 operator bool () const
 Discover whether the iterator is valid, and not equal to end(). More...
 
- Public Member Functions inherited from Gtk::TreeIterBase3
bool equal (const TreeIterBase3 & other) const
 
int get_stamp () const
 This is only useful when implementing a custom Gtk::TreeModel class. More...
 
void set_stamp (int stamp)
 This is only useful when implementing a custom Gtk::TreeModel class. More...
 
- Public Member Functions inherited from Gtk::TreeIterBase
 TreeIterBase (const TreeIterBase & other) noexcept
 
TreeIterBaseoperator= (const TreeIterBase & other) noexcept
 
 TreeIterBase (TreeIterBase && other) noexcept
 
TreeIterBaseoperator= (TreeIterBase && other) noexcept
 
 TreeIterBase ()
 
 TreeIterBase (const GtkTreeIter * gobject)
 
GtkTreeIter * gobj ()
 Provides access to the underlying C instance. More...
 
const GtkTreeIter * gobj () const
 Provides access to the underlying C instance. More...
 

Related Functions

(Note that these are not member functions.)

bool operator== (const TreeIterBase3 & lhs, const TreeIterBase3 & rhs)
 
bool operator!= (const TreeIterBase3 & lhs, const TreeIterBase3 & rhs)
 

Additional Inherited Members

- Static Public Member Functions inherited from Gtk::TreeIterBase
static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...
 
- Protected Attributes inherited from Gtk::TreeIterBase
GtkTreeIter gobject_
 

Detailed Description

template<typename T>
class Gtk::TreeIter< T >

Typedefed as TreeModel::iterator and TreeModel::const_iterator.

A Gtk::TreeModel::iterator is a reference to a specific node on a specific model. It is a generic structure with an integer and three generic pointers. These are filled in by the model in a model-specific way.

One can convert a path to an iterator by calling Gtk::TreeModel::get_iter().

These iterators are the primary way of accessing a model and are similar to the iterators used by Gtk::TextBuffer. The model interface defines a set of operations using them for navigating the model.

The lifecycle of an iterator can be a little confusing at first. Iterators are expected to always be valid for as long as the model is unchanged (and doesn't emit a signal). Additionally, some models guarantee that an iterator is valid for as long as the node it refers to is valid (most notably the Gtk::TreeStore and Gtk::ListStore).

One can convert an iterator to a TreeRow or TreeConstRow, as appropriate, by dereferencing it via TreeIter::operator*() or TreeIter::operator->(). The row classes can give nicer syntax by avoiding repeatedly dereferencing iterators. But see the warning re: reference safety in the doc of TreeIter::operator*().

Although generally uninteresting, as one always has to allow for the case where iterators do not persist beyond a signal, some very important performance enhancements were made in the sort model. As a result, the Gtk::TreeModel::Flags::ITERS_PERSIST flag was added to indicate this behaviour - see Gtk::TreeModel::get_flags().

Template Parameters
TTreeRow for an iterator, TreeConstRow for a const_iterator.
Deprecated:
4.10: Use Gio::ListModel instead.

Member Typedef Documentation

◆ difference_type

template <typename T >
using Gtk::TreeIter< T >::difference_type = int

This is not used.

◆ iterator_category

template <typename T >
using Gtk::TreeIter< T >::iterator_category = std::bidirectional_iterator_tag

TreeIter instances can be incremented and decremented.

◆ pointer

template <typename T >
using Gtk::TreeIter< T >::pointer = T*

A pointer to the TreeRow or TreeConstRow type, as yielded by operator->()

◆ reference

template <typename T >
using Gtk::TreeIter< T >::reference = T&

A reference to the TreeRow or TreeConstRow type, as yielded by operator*()

◆ value_type

template <typename T >
using Gtk::TreeIter< T >::value_type = T

The TreeRow or TreeConstRow type to which the iterator refers.

Constructor & Destructor Documentation

◆ TreeIter() [1/2]

template <typename T >
Gtk::TreeIter< T >::TreeIter ( )

Default constructor creates an invalid iterator, not referring to a model.

◆ TreeIter() [2/2]

template <typename T >
template <typename T2 , typename = typename std::enable_if< std::is_same<T, TreeConstRow>::value && std::is_same<T2, TreeRow>::value, T2>::type>
Gtk::TreeIter< T >::TreeIter ( const TreeIter< T2 > &  src)

iterator to const_iterator conversion.

Member Function Documentation

◆ operator bool()

template <typename T >
Gtk::TreeIter< T >::operator bool ( ) const
inlineexplicit

Discover whether the iterator is valid, and not equal to end().

For instance,

if (treeiter)
do_something();
Since gtkmm 3.22:

◆ operator*()

template <typename T >
reference Gtk::TreeIter< T >::operator* ( ) const
inline

Dereference the iterator to get a TreeRow or TreeConstRow, as appropriate.

Warning: The returned reference is implemented by casting from *this, and so the returned reference is only valid while this iter is. Thus, if you do something like auto& row = *model->append(), you get a dangling reference to the returned temporary and undefined behaviour. Thus for such cases, you must copy the returned row via auto row = *model->append() or equivalent. This risk cannot be mitigated in gtkmm v4, and the class will not be in v5.

◆ operator++() [1/2]

template <typename T >
TreeIter & Gtk::TreeIter< T >::operator++ ( )

Increment the iterator to refer to the next position in the model, and return a reference to the iterator as it is after the increment.

◆ operator++() [2/2]

template <typename T >
TreeIter Gtk::TreeIter< T >::operator++ ( int  )

Increment the iterator to refer to the next position in the model, but return a copy of the iterator as it was before the increment.

◆ operator--() [1/2]

template <typename T >
TreeIter & Gtk::TreeIter< T >::operator-- ( )

Note that this is very slow compared to operator++().

Decrement the iterator to refer to the previous position in the model, and return a reference to the iterator as it is after the decrement.

◆ operator--() [2/2]

template <typename T >
TreeIter Gtk::TreeIter< T >::operator-- ( int  )

Note that this is very slow compared to operator++(int).

Decrement the iterator to refer to the previous position in the model, but return a copy of the iterator as it was before the decrement.

◆ operator->()

template <typename T >
pointer Gtk::TreeIter< T >::operator-> ( ) const
inline

Dereference the iterator to get a TreeRow or TreeConstRow, as appropriate.

◆ operator=()

template <typename T >
template <typename T2 , typename = typename std::enable_if< std::is_same<T, TreeConstRow>::value && std::is_same<T2, TreeRow>::value, T2>::type>
TreeIter & Gtk::TreeIter< T >::operator= ( const TreeIter< T2 > &  src)

iterator to const_iterator assignment.

Friends And Related Function Documentation

◆ operator!=()

template <typename T >
bool operator!= ( const TreeIterBase3 lhs,
const TreeIterBase3 rhs 
)
related

◆ operator==()

template <typename T >
bool operator== ( const TreeIterBase3 lhs,
const TreeIterBase3 rhs 
)
related