TnyIterator

TnyIterator — A iterator type for a list

Synopsis




                    TnyIterator;
                    TnyIteratorIface;
void                tny_iterator_next                   (TnyIterator *self);
void                tny_iterator_prev                   (TnyIterator *self);
void                tny_iterator_first                  (TnyIterator *self);
void                tny_iterator_nth                    (TnyIterator *self,
                                                         guint nth);
GObject*            tny_iterator_get_current            (TnyIterator *self);
gboolean            tny_iterator_is_done                (TnyIterator *self);
TnyList*            tny_iterator_get_list               (TnyIterator *self);

Object Hierarchy


  GInterface
   +----TnyIterator

Description

An iterator for a TnyList is used for iterating over a list. The iterator is an instance that keeps the position state information. The TnyList instance will not by itself keep a position state. Only iterators can keep a position state for a list.

Details

TnyIterator

typedef struct _TnyIterator TnyIterator;

A position indicator for a TnyList

free-function: g_object_unref


TnyIteratorIface

typedef struct {
	GTypeInterface parent;

	void (*next) (TnyIterator *self);
	void (*prev) (TnyIterator *self);
	void (*first) (TnyIterator *self);
	void (*nth) (TnyIterator *self, guint nth);
	GObject* (*get_current) (TnyIterator *self);

	gboolean (*is_done) (TnyIterator *self);
	TnyList* (*get_list) (TnyIterator *self);
} TnyIteratorIface;


tny_iterator_next ()

void                tny_iterator_next                   (TnyIterator *self);

Moves the iterator to the next node

self : A TnyIterator

Since 1.0 audience: application-developer, type-implementer


tny_iterator_prev ()

void                tny_iterator_prev                   (TnyIterator *self);

Moves the iterator to the previous node

self : A TnyIterator

Since 1.0 audience: application-developer, type-implementer


tny_iterator_first ()

void                tny_iterator_first                  (TnyIterator *self);

Moves the iterator to the first node

self : A TnyIterator

Since 1.0 audience: application-developer, type-implementer


tny_iterator_nth ()

void                tny_iterator_nth                    (TnyIterator *self,
                                                         guint nth);

Moves the iterator to the nth node

self : A TnyIterator
nth : The nth position

Since 1.0 audience: application-developer, type-implementer


tny_iterator_get_current ()

GObject*            tny_iterator_get_current            (TnyIterator *self);

Returns the object at the current position. If there's no current position, this method returns NULL. If not NULL, the returned value must be unreferenced after use.

self : A TnyIterator instance
Returns : (null-ok) (caller-owns) (type-parameter G): the currect object or NULL

Since 1.0 audience: application-developer, type-implementer


tny_iterator_is_done ()

gboolean            tny_iterator_is_done                (TnyIterator *self);

Does the iterator point to some valid list item? You can use this property to make loops like:

Example:

TnyList *list = tny_simple_list_new ();
TnyIterator *iter = tny_list_create_iterator (list);
while (!tny_iterator_is_done (iter))
{
   GObject *cur = tny_iterator_get_current (iter);
   ...
   g_object_unref (cur);
   tny_iterator_next (iter);
}
g_object_unref (iter);
g_object_unref (list);

self : A TnyIterator
Returns : TRUE if it points to a valid list item, FALSE otherwise

Since 1.0 audience: application-developer, type-implementer


tny_iterator_get_list ()

TnyList*            tny_iterator_get_list               (TnyIterator *self);

Returns the list of which this iterator is an iterator. The returned list object should be unreferenced after use. Remember when using this property that lists shouldn't change while iterating them.

self : A TnyIterator
Returns : (caller-owns): The TnyList being iterated

Since 1.0 audience: application-developer, type-implementer

See Also

TnyList