devhelp r1096 - in trunk: . src



Author: rhult
Date: Fri Oct  3 11:41:20 2008
New Revision: 1096
URL: http://svn.gnome.org/viewvc/devhelp?rev=1096&view=rev

Log:
2008-10-03  Richard Hult  <richard imendio com>

	* src/dh-link.c:
	* src/dh-link.h: Add getters for the link members, change the
	deprecated bool to a bitfield of flags.
	- Use GSlice for the link struct.
	- Sort deprecated links after non-deprecated.


Modified:
   trunk/ChangeLog
   trunk/src/dh-link.c
   trunk/src/dh-link.h

Modified: trunk/src/dh-link.c
==============================================================================
--- trunk/src/dh-link.c	(original)
+++ trunk/src/dh-link.c	Fri Oct  3 11:41:20 2008
@@ -28,13 +28,15 @@
 GType
 dh_link_get_type (void)
 {
-  static GType type = 0;
-  if (G_UNLIKELY (type == 0)) {
-    type = g_boxed_type_register_static ("DhLink",
-                                         (GBoxedCopyFunc)dh_link_ref,
-                                         (GBoxedFreeFunc)dh_link_unref);
-  }
-  return type;
+        static GType type = 0;
+
+        if (G_UNLIKELY (type == 0)) {
+                type = g_boxed_type_register_static (
+                        "DhLink",
+                        (GBoxedCopyFunc) dh_link_ref,
+                        (GBoxedFreeFunc) dh_link_unref);
+        }
+        return type;
 }
 
 static void
@@ -45,7 +47,7 @@
 	g_free (link->page);
 	g_free (link->uri);
 
-	g_free (link);
+	g_slice_free (DhLink, link);
 }
 
 DhLink *
@@ -60,7 +62,7 @@
 	g_return_val_if_fail (name != NULL, NULL);
 	g_return_val_if_fail (uri != NULL, NULL);
 
-	link = g_new0 (DhLink, 1);
+	link = g_slice_new0 (DhLink);
 
 	link->type = type;
 
@@ -74,33 +76,35 @@
 	return link;
 }
 
-DhLink *
-dh_link_copy (const DhLink *link)
-{
-	return dh_link_new (link->type, link->name, link->book,
-			    link->page, link->uri);
-}
-
 gint
-dh_link_compare  (gconstpointer a, gconstpointer b)
+dh_link_compare  (gconstpointer a,
+                  gconstpointer b)
 {
-	gint book_diff;
-	gint page_diff;
+        const DhLink *la = a;
+        const DhLink *lb = b;
+	gint          flags_diff;
+	gint          book_diff;
+	gint          page_diff;
+
+        /* Sort deprecated hits last. */
+        flags_diff = (la->flags & DH_LINK_FLAGS_DEPRECATED) - 
+                (lb->flags & DH_LINK_FLAGS_DEPRECATED);
+        if (flags_diff != 0) {
+                return flags_diff;
+        }
 
-	book_diff = strcmp (((DhLink *)a)->book, ((DhLink *)b)->book);
+	book_diff = strcmp (la->book, lb->book);
 	if (book_diff == 0) {
-
-		if (((DhLink *)a)->page == 0 &&
-		    ((DhLink *)b)->page == 0) {
+		if (la->page == 0 && lb->page == 0) {
 			page_diff = 0;
 		} else {
-			page_diff =
-				(((DhLink *)a)->page && ((DhLink *)b)->page) ?
-				strcmp (((DhLink *)a)->page, ((DhLink *)b)->page) : -1;
+			page_diff = (la->page && lb->page) ?
+                                strcmp (la->page, lb->page) : -1;
 		}
 
-		if (page_diff == 0)
-			return strcmp (((DhLink *)a)->name, ((DhLink *)b)->name);
+		if (page_diff == 0) {
+			return strcmp (la->name, lb->name);
+                }
 
 		return page_diff;
 	}
@@ -130,17 +134,60 @@
 	}
 }
 
+const gchar *
+dh_link_get_name (DhLink *link)
+{
+        return link->name;
+}
+
+const gchar *
+dh_link_get_book (DhLink *link)
+{
+        return link->book;
+}
+
+const gchar *
+dh_link_get_page (DhLink *link)
+{
+        return link->page;
+}
+
+const gchar *
+dh_link_get_uri (DhLink *link)
+{
+        return link->uri;
+}
+
+DhLinkType
+dh_link_get_link_type (DhLink *link)
+{
+        return link->type;
+}
+
 gboolean
 dh_link_get_is_deprecated (DhLink *link)
 {
-	return link->is_deprecated;
+        return link->flags & DH_LINK_FLAGS_DEPRECATED;
 }
 
 void
 dh_link_set_is_deprecated (DhLink   *link,
 			   gboolean  is_deprecated)
 {
-	link->is_deprecated = is_deprecated;
+        link->flags |= DH_LINK_FLAGS_DEPRECATED;
+}         
+
+DhLinkFlags
+dh_link_get_flags (DhLink *link)
+{
+	return link->flags;
+}
+
+void
+dh_link_set_flags (DhLink      *link,
+                   DhLinkFlags  flags)
+{
+        link->flags = flags;
 }
 
 const gchar *

Modified: trunk/src/dh-link.h
==============================================================================
--- trunk/src/dh-link.h	(original)
+++ trunk/src/dh-link.h	Fri Oct  3 11:41:20 2008
@@ -36,22 +36,26 @@
         DH_LINK_TYPE_TYPEDEF
 } DhLinkType;
 
-typedef struct {
+typedef enum {
+        DH_LINK_FLAGS_NONE       = 0,
+        DH_LINK_FLAGS_DEPRECATED = 1 << 0
+} DhLinkFlags;
+
+typedef struct _DhLink DhLink;
+struct _DhLink {
         gchar       *name;
-        gchar       *book;
-        gchar       *page;
         gchar       *uri;
-        DhLinkType   type;
 
-        /* FIXME: Use an enum or flags for this when we know more about what we
-         * can do (or keep the actual deprecation string).
-         */
-        gboolean     is_deprecated;
+        gchar       *book;
+        gchar       *page;
 
         guint        ref_count;
-} DhLink;
 
-#define DH_TYPE_LINK dh_link_get_type ()
+        DhLinkType   type : 8;
+        DhLinkFlags  flags : 8;
+};
+
+#define DH_TYPE_LINK (dh_link_get_type ())
 
 GType        dh_link_get_type           (void);
 DhLink *     dh_link_new                (DhLinkType     type,
@@ -59,7 +63,6 @@
 					 const gchar   *book,
 					 const gchar   *page,
 					 const gchar   *uri);
-DhLink *     dh_link_copy               (const DhLink  *link);
 void         dh_link_free               (DhLink        *link);
 gint         dh_link_compare            (gconstpointer  a,
 					 gconstpointer  b);
@@ -67,7 +70,15 @@
 void         dh_link_unref              (DhLink        *link);
 gboolean     dh_link_get_is_deprecated  (DhLink        *link);
 void         dh_link_set_is_deprecated  (DhLink        *link,
-					 gboolean       is_deprecated);
+                                         gboolean       is_deprecated);
+const gchar *dh_link_get_name           (DhLink        *link);
+const gchar *dh_link_get_book           (DhLink        *link);
+const gchar *dh_link_get_page           (DhLink        *link);
+const gchar *dh_link_get_uri            (DhLink        *link);
+DhLinkFlags  dh_link_get_flags          (DhLink        *link);
+void         dh_link_set_flags          (DhLink        *link,
+					 DhLinkFlags    flags);
+DhLinkType   dh_link_get_link_type      (DhLink        *link);
 const gchar *dh_link_get_type_as_string (DhLink        *link);
 
 #endif /* __DH_LINK_H__ */



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