[gnome-builder/wip/libide: 91/153] libide: add _ide_diagnostics_new() and used G_DEFINE_BOXED_TYPE()



commit 8eae38d6efac4b49a44b21e6878824b2d032820d
Author: Christian Hergert <christian hergert me>
Date:   Wed Feb 11 19:11:54 2015 -0800

    libide: add _ide_diagnostics_new() and used G_DEFINE_BOXED_TYPE()

 libide/ide-diagnostics.c |   35 ++++++++++++++++++++---------------
 libide/ide-private.h     |    2 ++
 2 files changed, 22 insertions(+), 15 deletions(-)
---
diff --git a/libide/ide-diagnostics.c b/libide/ide-diagnostics.c
index f415f14..2eaba80 100644
--- a/libide/ide-diagnostics.c
+++ b/libide/ide-diagnostics.c
@@ -16,32 +16,37 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "ide-diagnostic.h"
 #include "ide-diagnostics.h"
 
+G_DEFINE_BOXED_TYPE (IdeDiagnostics, ide_diagnostics,
+                     ide_diagnostics_ref, ide_diagnostics_unref)
+
 struct _IdeDiagnostics
 {
   volatile gint  ref_count;
   GPtrArray     *diagnostics;
 };
 
-GType
-ide_diagnostics_get_type (void)
+/**
+ * _ide_diagnostics_new:
+ * @ar: (transfer full) (nullable): an array of #IdeDiagnostic.
+ *
+ * Creates a new #IdeDiagnostics container structure for @ar.
+ * Ownership of @ar is transfered to the resulting structure.
+ *
+ * Returns: (transfer full): A newly allocated #IdeDiagnostics.
+ */
+IdeDiagnostics *
+_ide_diagnostics_new (GPtrArray *ar)
 {
-  static gsize type_id;
-
-  if (g_once_init_enter (&type_id))
-    {
-      gsize _type_id;
+  IdeDiagnostics *ret;
 
-      _type_id = g_boxed_type_register_static (
-          "IdeDiagnostics",
-          (GBoxedCopyFunc)ide_diagnostics_ref,
-          (GBoxedFreeFunc)ide_diagnostics_unref);
-
-      g_once_init_leave (&type_id, _type_id);
-    }
+  ret = g_slice_new0 (IdeDiagnostics);
+  ret->ref_count = 1;
+  ret->diagnostics = ar ? ar : g_ptr_array_new_with_free_func (g_object_unref);
 
-  return type_id;
+  return ret;
 }
 
 IdeDiagnostics *
diff --git a/libide/ide-private.h b/libide/ide-private.h
index 00296b7..8d8aed9 100644
--- a/libide/ide-private.h
+++ b/libide/ide-private.h
@@ -39,6 +39,8 @@ void _ide_diagnostician_add_provider    (IdeDiagnostician      *self,
 void _ide_diagnostician_remove_provider (IdeDiagnostician      *self,
                                          IdeDiagnosticProvider *provider);
 
+IdeDiagnostics *_ide_diagnostics_new (GPtrArray *ar);
+
 
 G_END_DECLS
 


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