[retro-gtk] Add RetroOptionIterator



commit 14ae17859f76922fb5764922f5de92348d57d902
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Sun May 6 18:37:59 2018 +0200

    Add RetroOptionIterator
    
    This will allow to iterate over the options offered by the core.

 retro-gtk/meson.build                     |  2 +
 retro-gtk/retro-gtk.h                     |  1 +
 retro-gtk/retro-option-iterator-private.h | 18 ++++++++
 retro-gtk/retro-option-iterator.c         | 77 +++++++++++++++++++++++++++++++
 retro-gtk/retro-option-iterator.h         | 25 ++++++++++
 5 files changed, 123 insertions(+)
---
diff --git a/retro-gtk/meson.build b/retro-gtk/meson.build
index fb810b2..01e38d0 100644
--- a/retro-gtk/meson.build
+++ b/retro-gtk/meson.build
@@ -30,6 +30,7 @@ retro_gtk_sources = [
   'retro-module-iterator.c',
   'retro-module-query.c',
   'retro-option.c',
+  'retro-option-iterator.c',
   'retro-pa-player.c',
   'retro-pixdata.c',
   'retro-pixel-format.c',
@@ -55,6 +56,7 @@ retro_gtk_headers = [
   'retro-module-iterator.h',
   'retro-module-query.h',
   'retro-option.h',
+  'retro-option-iterator.h',
   'retro-pixdata.h',
   'retro-rumble-effect.h',
   'retro-video-filter.h',
diff --git a/retro-gtk/retro-gtk.h b/retro-gtk/retro-gtk.h
index 7304459..9ca8e0c 100644
--- a/retro-gtk/retro-gtk.h
+++ b/retro-gtk/retro-gtk.h
@@ -23,6 +23,7 @@
 #include "retro-module-iterator.h"
 #include "retro-module-query.h"
 #include "retro-option.h"
+#include "retro-option-iterator.h"
 #include "retro-pixdata.h"
 #include "retro-video-filter.h"
 
diff --git a/retro-gtk/retro-option-iterator-private.h b/retro-gtk/retro-option-iterator-private.h
new file mode 100644
index 0000000..de06ec2
--- /dev/null
+++ b/retro-gtk/retro-option-iterator-private.h
@@ -0,0 +1,18 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#ifndef RETRO_OPTION_ITERATOR_PRIVATE_H
+#define RETRO_OPTION_ITERATOR_PRIVATE_H
+
+#if !defined(__RETRO_GTK_INSIDE__) && !defined(RETRO_GTK_COMPILATION)
+# error "Only <retro-gtk.h> can be included directly."
+#endif
+
+#include "retro-option-iterator.h"
+
+G_BEGIN_DECLS
+
+RetroOptionIterator *retro_option_iterator_new (GHashTable *options);
+
+G_END_DECLS
+
+#endif /* RETRO_OPTION_ITERATOR_PRIVATE_H */
diff --git a/retro-gtk/retro-option-iterator.c b/retro-gtk/retro-option-iterator.c
new file mode 100644
index 0000000..18be4c4
--- /dev/null
+++ b/retro-gtk/retro-option-iterator.c
@@ -0,0 +1,77 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#include "retro-option-iterator.h"
+
+struct _RetroOptionIterator
+{
+  GObject parent_instance;
+  GHashTableIter iterator;
+};
+
+G_DEFINE_TYPE (RetroOptionIterator, retro_option_iterator, G_TYPE_OBJECT)
+
+/* Private */
+
+static void
+retro_option_iterator_finalize (GObject *object)
+{
+  G_OBJECT_CLASS (retro_option_iterator_parent_class)->finalize (object);
+}
+
+static void
+retro_option_iterator_class_init (RetroOptionIteratorClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = retro_option_iterator_finalize;
+}
+
+static void
+retro_option_iterator_init (RetroOptionIterator *self)
+{
+}
+
+/* Public */
+
+/**
+ * retro_option_iterator_next:
+ * @self: a #RetroOptionIterator
+ * @key: (out) (optional): return location for the key
+ * @option: (out) (optional) (nullable): return location for the option
+ *
+ * Fetch the next #RetroOption and its key.
+ *
+ * Returns: %FALSE if it reached the end, %TRUE otherwise
+ */
+gboolean
+retro_option_iterator_next (RetroOptionIterator  *self,
+                            guint               **key,
+                            RetroOption         **option)
+{
+  g_return_val_if_fail (RETRO_IS_OPTION_ITERATOR (self), FALSE);
+  g_return_val_if_fail (key != NULL, FALSE);
+  g_return_val_if_fail (option != NULL, FALSE);
+
+  return g_hash_table_iter_next (&self->iterator, (gpointer *) key, (gpointer *) option);
+}
+
+/**
+ * retro_option_iterator_new:
+ * @options: (element-type guint Retrooption): A #GHashTable
+ *
+ * Creates a new #RetroOptionIterator.
+ *
+ * Returns: (transfer full): a new #RetroOptionIterator
+ */
+RetroOptionIterator *
+retro_option_iterator_new (GHashTable *options)
+{
+  RetroOptionIterator *self;
+
+  g_return_val_if_fail (options != NULL, NULL);
+
+  self = g_object_new (RETRO_TYPE_OPTION_ITERATOR, NULL);
+  g_hash_table_iter_init (&self->iterator, options);
+
+  return self;
+}
diff --git a/retro-gtk/retro-option-iterator.h b/retro-gtk/retro-option-iterator.h
new file mode 100644
index 0000000..dc67576
--- /dev/null
+++ b/retro-gtk/retro-option-iterator.h
@@ -0,0 +1,25 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#ifndef RETRO_OPTION_ITERATOR_H
+#define RETRO_OPTION_ITERATOR_H
+
+#if !defined(__RETRO_GTK_INSIDE__) && !defined(RETRO_GTK_COMPILATION)
+# error "Only <retro-gtk.h> can be included directly."
+#endif
+
+#include <glib-object.h>
+#include "retro-option.h"
+
+G_BEGIN_DECLS
+
+#define RETRO_TYPE_OPTION_ITERATOR (retro_option_iterator_get_type())
+
+G_DECLARE_FINAL_TYPE (RetroOptionIterator, retro_option_iterator, RETRO, OPTION_ITERATOR, GObject)
+
+gboolean retro_option_iterator_next (RetroOptionIterator  *self,
+                                     guint               **key,
+                                     RetroOption         **option);
+
+G_END_DECLS
+
+#endif /* RETRO_OPTION_ITERATOR_H */


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