[gtk/wip/otte/listview] set: Add an iter



commit 9757582e8d559a4c186177f3b239c082652b8ed0
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jan 6 20:22:13 2019 -0500

    set: Add an iter

 gtk/gtkset.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkset.h | 14 ++++++++++++++
 2 files changed, 61 insertions(+)
---
diff --git a/gtk/gtkset.c b/gtk/gtkset.c
index 1c8827ccbd..66abce010d 100644
--- a/gtk/gtkset.c
+++ b/gtk/gtkset.c
@@ -33,6 +33,14 @@ struct _GtkSet
   GArray *ranges;
 };
 
+typedef struct
+{
+  GtkSet *set;
+  Range *current;
+  int idx;
+  guint pos;
+} GtkRealSetIter;
+
 GtkSet *
 gtk_set_new (void)
 {
@@ -229,6 +237,45 @@ gtk_set_shift (GtkSet *set,
     }
 }
 
+void
+gtk_set_iter_init (GtkSetIter *iter,
+                   GtkSet     *set)
+{
+  GtkRealSetIter *ri = (GtkRealSetIter *)iter;
+
+  ri->set = set;
+  ri->idx = -1;
+  ri->current = 0;
+}
+
+gboolean
+gtk_set_iter_next (GtkSetIter *iter,
+                   guint      *item)
+{
+  GtkRealSetIter *ri = (GtkRealSetIter *)iter;
+
+  if (ri->idx == -1)
+    { 
+next_range:
+      ri->idx++;
+
+      if (ri->idx == ri->set->ranges->len)
+        return FALSE;
+
+      ri->current = &g_array_index (ri->set->ranges, Range, ri->idx);
+      ri->pos = ri->current->first;
+    }
+  else
+    {
+      ri->pos++;
+      if (ri->pos == ri->current->first + ri->current->n_items)
+        goto next_range;
+    }
+
+  *item = ri->pos;
+  return TRUE;
+}
+
 #if 0
 void
 gtk_set_dump (GtkSet *set)
diff --git a/gtk/gtkset.h b/gtk/gtkset.h
index c8573d1d43..060c2b113a 100644
--- a/gtk/gtkset.h
+++ b/gtk/gtkset.h
@@ -23,6 +23,15 @@
 #include <glib.h>
 
 typedef struct _GtkSet GtkSet;
+typedef struct _GtkSetIter GtkSetIter;
+
+struct _GtkSetIter
+{
+  gpointer dummy1;
+  gpointer dummy2;
+  int      dummy3;
+  int      dummy4;
+};
 
 GtkSet   *gtk_set_new          (void);
 void      gtk_set_free         (GtkSet   *set);
@@ -46,4 +55,9 @@ void      gtk_set_shift        (GtkSet   *set,
                                 guint     first,
                                 int       shift);
 
+void      gtk_set_iter_init    (GtkSetIter *iter,
+                                GtkSet     *set);
+gboolean  gtk_set_iter_next    (GtkSetIter *iter,
+                                guint      *item);
+
 #endif  /* __GTK_SET_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]