[bijiben] lazy-serializer: Port to G_DECLARE_FINAL_TYPE
- From: Mohammed Sadiq <pksadiq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben] lazy-serializer: Port to G_DECLARE_FINAL_TYPE
- Date: Tue, 21 Nov 2017 05:22:56 +0000 (UTC)
commit 4d7f331698a415b878645a587d5197e02fd1ef87
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date: Sun Nov 19 18:53:11 2017 +0530
lazy-serializer: Port to G_DECLARE_FINAL_TYPE
* Use G_DECLARE_FINAL_TYPE to avoid boilerplate code
* Don't use private members.
This class isn't derivable. So there isn't any difference.
This is a part of effort to clean up codebase and make the code more
maintainable.
https://bugzilla.gnome.org/show_bug.cgi?id=789696
src/libbiji/serializer/biji-lazy-serializer.c | 110 +++++++++++-------------
src/libbiji/serializer/biji-lazy-serializer.h | 27 +------
2 files changed, 52 insertions(+), 85 deletions(-)
---
diff --git a/src/libbiji/serializer/biji-lazy-serializer.c b/src/libbiji/serializer/biji-lazy-serializer.c
index 843e01f..f2c632b 100644
--- a/src/libbiji/serializer/biji-lazy-serializer.c
+++ b/src/libbiji/serializer/biji-lazy-serializer.c
@@ -34,10 +34,10 @@ enum
static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
-G_DEFINE_TYPE (BijiLazySerializer, biji_lazy_serializer, G_TYPE_OBJECT);
-
-struct _BijiLazySerializerPrivate
+struct _BijiLazySerializer
{
+ GObject parent_instance;
+
BijiNoteObj *note;
xmlBufferPtr buf;
@@ -47,6 +47,8 @@ struct _BijiLazySerializerPrivate
xmlTextReaderPtr inner;
};
+G_DEFINE_TYPE (BijiLazySerializer, biji_lazy_serializer, G_TYPE_OBJECT)
+
static void
biji_lazy_serializer_get_property (GObject *object,
guint property_id,
@@ -58,7 +60,7 @@ biji_lazy_serializer_get_property (GObject *object,
switch (property_id)
{
case PROP_NOTE:
- g_value_set_object (value, self->priv->note);
+ g_value_set_object (value, self->note);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -76,7 +78,7 @@ biji_lazy_serializer_set_property (GObject *object,
switch (property_id)
{
case PROP_NOTE:
- self->priv->note = g_value_get_object (value);
+ self->note = g_value_get_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -86,24 +88,16 @@ biji_lazy_serializer_set_property (GObject *object,
static void
biji_lazy_serializer_init (BijiLazySerializer *self)
{
- BijiLazySerializerPrivate *priv;
-
- priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
- BIJI_TYPE_LAZY_SERIALIZER,
- BijiLazySerializerPrivate);
- self->priv = priv;
-
- priv->buf = xmlBufferCreate();
+ self->buf = xmlBufferCreate();
}
static void
biji_lazy_serializer_finalize (GObject *object)
{
BijiLazySerializer *self = BIJI_LAZY_SERIALIZER (object);
- BijiLazySerializerPrivate *priv = self->priv;
- xmlBufferFree (priv->buf);
- xmlFreeTextReader (priv->inner);
+ xmlBufferFree (self->buf);
+ xmlFreeTextReader (self->inner);
G_OBJECT_CLASS (biji_lazy_serializer_parent_class)->finalize (object);
}
@@ -126,8 +120,6 @@ biji_lazy_serializer_class_init (BijiLazySerializerClass *klass)
G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class,PROP_NOTE,properties[PROP_NOTE]);
-
- g_type_class_add_private (klass, sizeof (BijiLazySerializerPrivate));
}
static void
@@ -155,20 +147,18 @@ serialize_tags (gchar *tag, xmlTextWriterPtr writer)
static void
serialize_html (BijiLazySerializer *self)
{
- BijiLazySerializerPrivate *priv = self->priv;
- gchar *html = biji_note_obj_get_html (priv->note);
+ gchar *html = biji_note_obj_get_html (self->note);
if (!html)
return;
- xmlTextWriterWriteRaw(priv->writer, BAD_CAST html);
+ xmlTextWriterWriteRaw(self->writer, BAD_CAST html);
g_free (html);
}
static gboolean
biji_lazy_serialize_internal (BijiLazySerializer *self)
{
- BijiLazySerializerPrivate *priv = self->priv;
GList *tags;
GdkRGBA color;
gchar *date, *color_str;
@@ -176,98 +166,98 @@ biji_lazy_serialize_internal (BijiLazySerializer *self)
const gchar *path;
GTimeVal time = {0, 0};
- priv->writer = xmlNewTextWriterMemory(priv->buf, 0);
+ self->writer = xmlNewTextWriterMemory(self->buf, 0);
// Header
- xmlTextWriterStartDocument (priv->writer,"1.0","utf-8",NULL);
+ xmlTextWriterStartDocument (self->writer,"1.0","utf-8",NULL);
- xmlTextWriterStartElement (priv->writer, BAD_CAST "note");
- xmlTextWriterWriteAttributeNS (priv->writer, NULL,
+ xmlTextWriterStartElement (self->writer, BAD_CAST "note");
+ xmlTextWriterWriteAttributeNS (self->writer, NULL,
BAD_CAST "version",NULL,
BAD_CAST "1");
- xmlTextWriterWriteAttributeNS (priv->writer, BAD_CAST "xmlns",
+ xmlTextWriterWriteAttributeNS (self->writer, BAD_CAST "xmlns",
BAD_CAST "link", NULL,
BAD_CAST "http://projects.gnome.org/bijiben/link");
- xmlTextWriterWriteAttributeNS (priv->writer, BAD_CAST "xmlns", BAD_CAST "size", NULL,
+ xmlTextWriterWriteAttributeNS (self->writer, BAD_CAST "xmlns", BAD_CAST "size", NULL,
BAD_CAST "http://projects.gnome.org/bijiben/size");
- xmlTextWriterWriteAttributeNS (priv->writer, NULL, BAD_CAST "xmlns", NULL,
+ xmlTextWriterWriteAttributeNS (self->writer, NULL, BAD_CAST "xmlns", NULL,
BAD_CAST "http://projects.gnome.org/bijiben");
// <Title>
- serialize_node (priv->writer,
+ serialize_node (self->writer,
"title",
- (gchar*) biji_item_get_title (BIJI_ITEM (priv->note)));
+ (gchar*) biji_item_get_title (BIJI_ITEM (self->note)));
// <text>
- xmlTextWriterWriteRaw(priv->writer, BAD_CAST "\n ");
- xmlTextWriterStartElement(priv->writer, BAD_CAST "text");
- xmlTextWriterWriteAttributeNS(priv->writer, BAD_CAST "xml",
+ xmlTextWriterWriteRaw(self->writer, BAD_CAST "\n ");
+ xmlTextWriterStartElement(self->writer, BAD_CAST "text");
+ xmlTextWriterWriteAttributeNS(self->writer, BAD_CAST "xml",
BAD_CAST "space", NULL,
BAD_CAST "preserve");
serialize_html (self);
// </text>
- xmlTextWriterEndElement(priv->writer);
+ xmlTextWriterEndElement(self->writer);
// <last-change-date>
- time.tv_sec = biji_item_get_mtime (BIJI_ITEM (priv->note));
+ time.tv_sec = biji_item_get_mtime (BIJI_ITEM (self->note));
date = g_time_val_to_iso8601 (&time);
if (date)
{
- serialize_node (priv->writer, "last-change-date", date);
+ serialize_node (self->writer, "last-change-date", date);
g_free (date);
}
- time.tv_sec = biji_note_obj_get_last_metadata_change_date (priv->note);
+ time.tv_sec = biji_note_obj_get_last_metadata_change_date (self->note);
date = g_time_val_to_iso8601 (&time);
if (date)
{
- serialize_node (priv->writer, "last-metadata-change-date", date);
+ serialize_node (self->writer, "last-metadata-change-date", date);
g_free (date);
}
- time.tv_sec = biji_note_obj_get_create_date (priv->note);
+ time.tv_sec = biji_note_obj_get_create_date (self->note);
date = g_time_val_to_iso8601 (&time);
if (date)
{
- serialize_node (priv->writer, "create-date", date);
+ serialize_node (self->writer, "create-date", date);
g_free (date);
}
- serialize_node (priv->writer, "cursor-position", "0");
- serialize_node (priv->writer, "selection-bound-position", "0");
- serialize_node (priv->writer, "width", "0");
- serialize_node (priv->writer, "height", "0");
- serialize_node (priv->writer, "x", "0");
- serialize_node (priv->writer, "y", "0");
+ serialize_node (self->writer, "cursor-position", "0");
+ serialize_node (self->writer, "selection-bound-position", "0");
+ serialize_node (self->writer, "width", "0");
+ serialize_node (self->writer, "height", "0");
+ serialize_node (self->writer, "x", "0");
+ serialize_node (self->writer, "y", "0");
- if (biji_note_obj_get_rgba (priv->note, &color))
+ if (biji_note_obj_get_rgba (self->note, &color))
{
color_str = gdk_rgba_to_string (&color);
- serialize_node (priv->writer, "color", color_str);
+ serialize_node (self->writer, "color", color_str);
g_free (color_str);
}
//<tags>
- xmlTextWriterWriteRaw(priv->writer, BAD_CAST "\n ");
- xmlTextWriterStartElement (priv->writer, BAD_CAST "tags");
- tags = biji_note_obj_get_notebooks (priv->note);
- g_list_foreach (tags, (GFunc) serialize_tags, priv->writer);
- xmlTextWriterEndElement (priv->writer);
+ xmlTextWriterWriteRaw (self->writer, BAD_CAST "\n ");
+ xmlTextWriterStartElement (self->writer, BAD_CAST "tags");
+ tags = biji_note_obj_get_notebooks (self->note);
+ g_list_foreach (tags, (GFunc) serialize_tags, self->writer);
+ xmlTextWriterEndElement (self->writer);
g_list_free (tags);
// <open-on-startup>
- serialize_node (priv->writer, "open-on-startup", "False");
+ serialize_node (self->writer, "open-on-startup", "False");
// <note>
- xmlTextWriterWriteRaw(priv->writer, BAD_CAST "\n ");
- xmlTextWriterEndElement(priv->writer);
+ xmlTextWriterWriteRaw (self->writer, BAD_CAST "\n ");
+ xmlTextWriterEndElement (self->writer);
- xmlFreeTextWriter(priv->writer);
+ xmlFreeTextWriter(self->writer);
- path = biji_item_get_uuid (BIJI_ITEM (priv->note));
- retval = g_file_set_contents (path, (gchar*) priv->buf->content, -1, NULL);
+ path = biji_item_get_uuid (BIJI_ITEM (self->note));
+ retval = g_file_set_contents (path, (gchar*) self->buf->content, -1, NULL);
return retval;
}
diff --git a/src/libbiji/serializer/biji-lazy-serializer.h b/src/libbiji/serializer/biji-lazy-serializer.h
index b0822e1..439a3f7 100644
--- a/src/libbiji/serializer/biji-lazy-serializer.h
+++ b/src/libbiji/serializer/biji-lazy-serializer.h
@@ -29,32 +29,9 @@
G_BEGIN_DECLS
-#define BIJI_TYPE_LAZY_SERIALIZER (biji_lazy_serializer_get_type ())
-#define BIJI_LAZY_SERIALIZER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BIJI_TYPE_LAZY_SERIALIZER,
BijiLazySerializer))
-#define BIJI_LAZY_SERIALIZER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BIJI_TYPE_LAZY_SERIALIZER,
BijiLazySerializerClass))
-#define BIJI_IS_LAZY_SERIALIZER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BIJI_TYPE_LAZY_SERIALIZER))
-#define BIJI_IS_LAZY_SERIALIZER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BIJI_TYPE_LAZY_SERIALIZER))
-#define BIJI_LAZY_SERIALIZER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BIJI_TYPE_LAZY_SERIALIZER,
BijiLazySerializerClass))
-
-typedef struct _BijiLazySerializerClass BijiLazySerializerClass;
-typedef struct _BijiLazySerializer BijiLazySerializer;
-
-typedef struct _BijiLazySerializerPrivate BijiLazySerializerPrivate;
-
-struct _BijiLazySerializerClass
-{
- GObjectClass parent_class;
-};
-
-struct _BijiLazySerializer
-{
- GObject parent_instance;
- BijiLazySerializerPrivate *priv;
-};
-
-
-GType biji_lazy_serializer_get_type (void) G_GNUC_CONST;
+#define BIJI_TYPE_LAZY_SERIALIZER (biji_lazy_serializer_get_type ())
+G_DECLARE_FINAL_TYPE (BijiLazySerializer, biji_lazy_serializer, BIJI, LAZY_SERIALIZER, GObject)
gboolean biji_lazy_serialize (BijiNoteObj *note);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]