[poppler] glib/poppler-action.cc glib/poppler-annot.cc glib/poppler-document.cc glib/poppler-page.cc glib/poppler-private.h

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Sat Feb 21 03:07:52 PST 2009


 glib/poppler-action.cc   |   26 ------------
 glib/poppler-annot.cc    |   15 +------
 glib/poppler-document.cc |   44 ++++----------------
 glib/poppler-page.cc     |   99 +++++++++--------------------------------------
 glib/poppler-private.h   |   20 +++++++++
 5 files changed, 53 insertions(+), 151 deletions(-)

New commits:
commit 943fca42b5fa815fad650e42da4ad6e806adc3b1
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Sat Feb 21 12:08:00 2009 +0100

    [glib] Add a macro to define boxed types

diff --git a/glib/poppler-action.cc b/glib/poppler-action.cc
index 080eb27..f23b343 100644
--- a/glib/poppler-action.cc
+++ b/glib/poppler-action.cc
@@ -19,18 +19,7 @@
 #include "poppler.h"
 #include "poppler-private.h"
 
-GType
-poppler_dest_get_type (void)
-{
-  static GType our_type = 0;
-
-  if (our_type == 0)
-    our_type = g_boxed_type_register_static ("PopplerDest",
-					     (GBoxedCopyFunc) poppler_dest_copy,
-					     (GBoxedFreeFunc) poppler_dest_free);
-
-  return our_type;
-}
+POPPLER_DEFINE_BOXED_TYPE (PopplerDest, poppler_dest, poppler_dest_copy, poppler_dest_free)
 
 /**
  * poppler_dest_copy:
@@ -73,18 +62,7 @@ poppler_dest_free (PopplerDest *dest)
 	g_free (dest);
 }
 
-GType
-poppler_action_get_type (void)
-{
-  static GType our_type = 0;
-
-  if (our_type == 0)
-    our_type = g_boxed_type_register_static ("PopplerAction",
-					     (GBoxedCopyFunc) poppler_action_copy,
-					     (GBoxedFreeFunc) poppler_action_free);
-
-  return our_type;
-}
+POPPLER_DEFINE_BOXED_TYPE (PopplerAction, poppler_action, poppler_action_copy, poppler_action_free)
 
 /**
  * poppler_action_free:
diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc
index 067afcc..a2c51e4 100644
--- a/glib/poppler-annot.cc
+++ b/glib/poppler-annot.cc
@@ -697,18 +697,9 @@ poppler_annot_free_text_get_callout_line (PopplerAnnotFreeText *poppler_annot)
 }
 
 /* PopplerAnnotCalloutLine */
-GType
-poppler_annot_callout_line_get_type (void)
-{
-  static GType our_type = 0;
-
-  if (our_type == 0)
-    our_type = g_boxed_type_register_static ("PopplerAnnotCalloutLine",
-                                             (GBoxedCopyFunc) poppler_annot_callout_line_copy,
-                                             (GBoxedFreeFunc) poppler_annot_callout_line_free);
-
-  return our_type;
-}
+POPPLER_DEFINE_BOXED_TYPE (PopplerAnnotCalloutLine, poppler_annot_callout_line,
+			   poppler_annot_callout_line_copy,
+			   poppler_annot_callout_line_free)
 
 /**
  * poppler_annot_callout_line_new:
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index 352149b..6402e69 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -874,18 +874,9 @@ struct _PopplerIndexIter
 };
 
 
-GType
-poppler_index_iter_get_type (void)
-{
-  static GType our_type = 0;
-
-  if (our_type == 0)
-    our_type = g_boxed_type_register_static ("PopplerIndexIter",
-					     (GBoxedCopyFunc) poppler_index_iter_copy,
-					     (GBoxedFreeFunc) poppler_index_iter_free);
-
-  return our_type;
-}
+POPPLER_DEFINE_BOXED_TYPE (PopplerIndexIter, poppler_index_iter,
+			   poppler_index_iter_copy,
+			   poppler_index_iter_free)
 
 /**
  * poppler_index_iter_copy:
@@ -1122,18 +1113,9 @@ struct _PopplerFontsIter
 	int index;
 };
 
-GType
-poppler_fonts_iter_get_type (void)
-{
-  static GType our_type = 0;
-
-  if (our_type == 0)
-    our_type = g_boxed_type_register_static ("PopplerFontsIter",
-					     (GBoxedCopyFunc) poppler_fonts_iter_copy,
-					     (GBoxedFreeFunc) poppler_fonts_iter_free);
-
-  return our_type;
-}
+POPPLER_DEFINE_BOXED_TYPE (PopplerFontsIter, poppler_fonts_iter,
+			   poppler_fonts_iter_copy,
+			   poppler_fonts_iter_free)
 
 const char *
 poppler_fonts_iter_get_full_name (PopplerFontsIter *iter)
@@ -1557,17 +1539,9 @@ struct _PopplerLayersIter {
   int index;
 };
 
-GType
-poppler_layers_iter_get_type (void)
-{
-  static GType our_type = 0;
-
-  if (our_type == 0)
-    our_type = g_boxed_type_register_static ("PopplerLayersIter",
-					     (GBoxedCopyFunc) poppler_layers_iter_copy,
-					     (GBoxedFreeFunc) poppler_layers_iter_free);
-  return our_type;
-}
+POPPLER_DEFINE_BOXED_TYPE (PopplerLayersIter, poppler_layers_iter,
+			   poppler_layers_iter_copy,
+			   poppler_layers_iter_free)
 
 /**
  * poppler_layers_iter_copy:
diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc
index 29d124d..e17d4de 100644
--- a/glib/poppler-page.cc
+++ b/glib/poppler-page.cc
@@ -1771,18 +1771,9 @@ poppler_page_free_annot_mapping (GList *list)
 
 /* PopplerRectangle type */
 
-GType
-poppler_rectangle_get_type (void)
-{
-  static GType our_type = 0;
-
-  if (G_UNLIKELY (our_type == 0))
-    our_type = g_boxed_type_register_static ("PopplerRectangle",
-					     (GBoxedCopyFunc) poppler_rectangle_copy,
-					     (GBoxedFreeFunc) poppler_rectangle_free);
-
-  return our_type;
-}
+POPPLER_DEFINE_BOXED_TYPE (PopplerRectangle, poppler_rectangle,
+			   poppler_rectangle_copy,
+			   poppler_rectangle_free)
 
 PopplerRectangle *
 poppler_rectangle_new (void)
@@ -1810,18 +1801,7 @@ poppler_rectangle_free (PopplerRectangle *rectangle)
 }
 
 /* PopplerColor type */
-GType
-poppler_color_get_type (void)
-{
-  static GType our_type = 0;
-
-  if (G_UNLIKELY (our_type == 0))
-    our_type = g_boxed_type_register_static ("PopplerColor",
-					     (GBoxedCopyFunc) poppler_color_copy,
-					     (GBoxedFreeFunc) poppler_color_free);
-
-  return our_type;
-}
+POPPLER_DEFINE_BOXED_TYPE (PopplerColor, poppler_color, poppler_color_copy, poppler_color_free)
 
 PopplerColor *
 poppler_color_new (void)
@@ -1847,18 +1827,9 @@ poppler_color_free (PopplerColor *color)
 }
 
 /* PopplerLinkMapping type */
-GType
-poppler_link_mapping_get_type (void)
-{
-  static GType our_type = 0;
-
-  if (G_UNLIKELY (our_type == 0))
-    our_type = g_boxed_type_register_static ("PopplerLinkMapping",
-					     (GBoxedCopyFunc) poppler_link_mapping_copy,
-					     (GBoxedFreeFunc) poppler_link_mapping_free);
-
-  return our_type;
-}
+POPPLER_DEFINE_BOXED_TYPE (PopplerLinkMapping, poppler_link_mapping,
+			   poppler_link_mapping_copy,
+			   poppler_link_mapping_free)
 
 PopplerLinkMapping *
 poppler_link_mapping_new (void)
@@ -1890,18 +1861,9 @@ poppler_link_mapping_free (PopplerLinkMapping *mapping)
 }
 
 /* Poppler Image mapping type */
-GType
-poppler_image_mapping_get_type (void)
-{
-  static GType our_type = 0;
-
-  if (G_UNLIKELY (our_type == 0))
-    our_type = g_boxed_type_register_static ("PopplerImageMapping",
-					     (GBoxedCopyFunc) poppler_image_mapping_copy,
-					     (GBoxedFreeFunc) poppler_image_mapping_free);
-
-  return our_type;
-}
+POPPLER_DEFINE_BOXED_TYPE (PopplerImageMapping, poppler_image_mapping,
+			   poppler_image_mapping_copy,
+			   poppler_image_mapping_free)
 
 PopplerImageMapping *
 poppler_image_mapping_new (void)
@@ -1928,16 +1890,9 @@ poppler_image_mapping_free (PopplerImageMapping *mapping)
 }
 
 /* Page Transition */
-GType
-poppler_page_transition_get_type (void)
-{
-  static GType our_type = 0;
-  if (G_UNLIKELY (our_type == 0))
-    our_type = g_boxed_type_register_static("PopplerPageTransition",
-					    (GBoxedCopyFunc) poppler_page_transition_copy,
-					    (GBoxedFreeFunc) poppler_page_transition_free);
-  return our_type;
-}
+POPPLER_DEFINE_BOXED_TYPE (PopplerPageTransition, poppler_page_transition,
+			   poppler_page_transition_copy,
+			   poppler_page_transition_free)
 
 PopplerPageTransition *
 poppler_page_transition_new (void)
@@ -1963,16 +1918,9 @@ poppler_page_transition_free (PopplerPageTransition *transition)
 }
 
 /* Form Field Mapping Type */
-GType
-poppler_form_field_mapping_get_type (void)
-{
-  static GType our_type = 0;
-  if (G_UNLIKELY (our_type == 0))
-    our_type = g_boxed_type_register_static("PopplerFormFieldMapping",
-					    (GBoxedCopyFunc) poppler_form_field_mapping_copy,
-					    (GBoxedFreeFunc) poppler_form_field_mapping_free);
-  return our_type;
-}
+POPPLER_DEFINE_BOXED_TYPE (PopplerFormFieldMapping, poppler_form_field_mapping,
+			   poppler_form_field_mapping_copy,
+			   poppler_form_field_mapping_free)
 
 PopplerFormFieldMapping *
 poppler_form_field_mapping_new (void)
@@ -2007,18 +1955,9 @@ poppler_form_field_mapping_free (PopplerFormFieldMapping *mapping)
 }
 
 /* PopplerAnnot Mapping Type */
-GType
-poppler_annot_mapping_get_type (void)
-{
-  static GType our_type = 0;
-
-  if (our_type == 0)
-    our_type = g_boxed_type_register_static ("PopplerAnnotMapping",
-					     (GBoxedCopyFunc) poppler_annot_mapping_copy,
-					     (GBoxedFreeFunc) poppler_annot_mapping_free);
-
-  return our_type;
-}
+POPPLER_DEFINE_BOXED_TYPE (PopplerAnnotMapping, poppler_annot_mapping,
+			   poppler_annot_mapping_copy,
+			   poppler_annot_mapping_free)
 
 PopplerAnnotMapping *
 poppler_annot_mapping_new (void)
diff --git a/glib/poppler-private.h b/glib/poppler-private.h
index c4380ea..1cb1eac 100644
--- a/glib/poppler-private.h
+++ b/glib/poppler-private.h
@@ -112,4 +112,24 @@ PopplerAnnot      *_poppler_annot_free_text_new (Annot *annot);
 char *_poppler_goo_string_to_utf8(GooString *s);
 gboolean _poppler_convert_pdf_date_to_gtime (GooString *date,
 					     GTime     *gdate);
+
+/*
+ * A convenience macro for boxed type implementations, which defines a
+ * type_name_get_type() function registering the boxed type.
+ */
+#define POPPLER_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func)          \
+GType                                                                                 \
+type_name##_get_type (void)                                                           \
+{                                                                                     \
+        static volatile gsize g_define_type_id__volatile = 0;                         \
+	if (g_once_init_enter (&g_define_type_id__volatile)) {                        \
+	        GType g_define_type_id =                                              \
+		    g_boxed_type_register_static (g_intern_static_string (#TypeName), \
+		                                  (GBoxedCopyFunc) copy_func,         \
+						  (GBoxedFreeFunc) free_func);        \
+		g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);    \
+	}                                                                             \
+	return g_define_type_id__volatile;                                            \
+}
+
 #endif


More information about the poppler mailing list