[epiphany] sqlite-connection: Use G_DECLARE_FINAL_TYPE



commit 846fb0468fc58b8e5937e5d5d6bf0734b0363146
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Sun Feb 21 22:40:11 2016 -0600

    sqlite-connection: Use G_DECLARE_FINAL_TYPE

 lib/ephy-sqlite-connection.c |   39 +++++++++++++++------------------------
 lib/ephy-sqlite-connection.h |   25 ++-----------------------
 2 files changed, 17 insertions(+), 47 deletions(-)
---
diff --git a/lib/ephy-sqlite-connection.c b/lib/ephy-sqlite-connection.c
index 7ba02d5..10bc5d6 100644
--- a/lib/ephy-sqlite-connection.c
+++ b/lib/ephy-sqlite-connection.c
@@ -20,12 +20,11 @@
 
 #include <sqlite3.h>
 
-struct _EphySQLiteConnectionPrivate {
+struct _EphySQLiteConnection {
+  GObject parent_instance;
   sqlite3 *database;
 };
 
-#define EPHY_SQLITE_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), EPHY_TYPE_SQLITE_CONNECTION, 
EphySQLiteConnectionPrivate))
-
 G_DEFINE_TYPE (EphySQLiteConnection, ephy_sqlite_connection, G_TYPE_OBJECT);
 
 static void
@@ -40,14 +39,12 @@ ephy_sqlite_connection_class_init (EphySQLiteConnectionClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   object_class->finalize = ephy_sqlite_connection_finalize;
-  g_type_class_add_private (object_class, sizeof (EphySQLiteConnectionPrivate));
 }
 
 static void
 ephy_sqlite_connection_init (EphySQLiteConnection *self)
 {
-  self->priv = EPHY_SQLITE_CONNECTION_GET_PRIVATE (self);
-  self->priv->database = NULL;
+  self->database = NULL;
 }
 
 static GQuark get_ephy_sqlite_quark (void)
@@ -71,16 +68,14 @@ ephy_sqlite_connection_new (void)
 gboolean
 ephy_sqlite_connection_open (EphySQLiteConnection *self, const gchar *filename, GError **error)
 {
-  EphySQLiteConnectionPrivate *priv = self->priv;
-
-  if (priv->database) {
+  if (self->database) {
     set_error_from_string ("Connection already open.", error);
     return FALSE;
   }
   
-  if (sqlite3_open (filename, &priv->database) != SQLITE_OK) {
+  if (sqlite3_open (filename, &self->database) != SQLITE_OK) {
     ephy_sqlite_connection_get_error (self, error);
-    priv->database = NULL;
+    self->database = NULL;
     return FALSE;
   }
 
@@ -90,10 +85,9 @@ ephy_sqlite_connection_open (EphySQLiteConnection *self, const gchar *filename,
 void
 ephy_sqlite_connection_close (EphySQLiteConnection *self)
 {
-  EphySQLiteConnectionPrivate *priv = self->priv;
-  if (priv->database) {
-    sqlite3_close (priv->database);
-    priv->database = NULL;
+  if (self->database) {
+    sqlite3_close (self->database);
+    self->database = NULL;
   }
 }
 
@@ -101,34 +95,31 @@ void
 ephy_sqlite_connection_get_error (EphySQLiteConnection *self, GError **error)
 {
   if (error)
-    *error = g_error_new_literal (get_ephy_sqlite_quark (), 0, sqlite3_errmsg (self->priv->database));
+    *error = g_error_new_literal (get_ephy_sqlite_quark (), 0, sqlite3_errmsg (self->database));
 }
 
 gboolean
 ephy_sqlite_connection_execute (EphySQLiteConnection *self, const char *sql, GError **error)
 {
-  EphySQLiteConnectionPrivate *priv = self->priv;
-  
-  if (priv->database == NULL) {
+  if (self->database == NULL) {
     set_error_from_string ("Connection not open.", error);
     return FALSE;
   }
   
-  return sqlite3_exec (priv->database, sql, NULL, NULL, NULL) == SQLITE_OK;
+  return sqlite3_exec (self->database, sql, NULL, NULL, NULL) == SQLITE_OK;
 }
 
 EphySQLiteStatement *
 ephy_sqlite_connection_create_statement (EphySQLiteConnection *self, const char *sql, GError **error)
 {
-  EphySQLiteConnectionPrivate *priv = self->priv;
   sqlite3_stmt *prepared_statement;
 
-  if (priv->database == NULL) {
+  if (self->database == NULL) {
     set_error_from_string ("Connection not open.", error);
     return NULL;
   }
 
-  if (sqlite3_prepare_v2 (priv->database, sql, -1, &prepared_statement, NULL) != SQLITE_OK) {
+  if (sqlite3_prepare_v2 (self->database, sql, -1, &prepared_statement, NULL) != SQLITE_OK) {
     ephy_sqlite_connection_get_error (self, error);
     return NULL;
   }
@@ -142,7 +133,7 @@ ephy_sqlite_connection_create_statement (EphySQLiteConnection *self, const char
 gint64
 ephy_sqlite_connection_get_last_insert_id (EphySQLiteConnection *self)
 {
-  return sqlite3_last_insert_rowid (self->priv->database);
+  return sqlite3_last_insert_rowid (self->database);
 }
 
 gboolean
diff --git a/lib/ephy-sqlite-connection.h b/lib/ephy-sqlite-connection.h
index bd9a4e2..a4b971c 100644
--- a/lib/ephy-sqlite-connection.h
+++ b/lib/ephy-sqlite-connection.h
@@ -23,30 +23,9 @@
 
 G_BEGIN_DECLS
 
-/* convenience macros */
-#define EPHY_TYPE_SQLITE_CONNECTION             (ephy_sqlite_connection_get_type())
-#define EPHY_SQLITE_CONNECTION(obj)             
(G_TYPE_CHECK_INSTANCE_CAST((obj),EPHY_TYPE_SQLITE_CONNECTION,EphySQLiteConnection))
-#define EPHY_SQLITE_CONNECTION_CLASS(klass)     
(G_TYPE_CHECK_CLASS_CAST((klass),EPHY_TYPE_SQLITE_CONNECTION,EphySQLiteConnectionClass))
-#define EPHY_IS_SQLITE_CONNECTION(obj)          
(G_TYPE_CHECK_INSTANCE_TYPE((obj),EPHY_TYPE_SQLITE_CONNECTION))
-#define EPHY_IS_SQLITE_CONNECTION_CLASS(klass)  
(G_TYPE_CHECK_CLASS_TYPE((klass),EPHY_TYPE_SQLITE_CONNECTION))
-#define EPHY_SQLITE_CONNECTION_GET_CLASS(obj)   
(G_TYPE_INSTANCE_GET_CLASS((obj),EPHY_TYPE_SQLITE_CONNECTION,EphySQLiteConnectionClass))
+#define EPHY_TYPE_SQLITE_CONNECTION (ephy_sqlite_connection_get_type ())
 
-typedef struct _EphySQLiteConnection                EphySQLiteConnection;
-typedef struct _EphySQLiteConnectionClass           EphySQLiteConnectionClass;
-typedef struct _EphySQLiteConnectionPrivate         EphySQLiteConnectionPrivate;
-
-struct _EphySQLiteConnection {
-     GObject parent;
-
-    /* private */
-    EphySQLiteConnectionPrivate *priv;
-};
-
-struct _EphySQLiteConnectionClass {
-    GObjectClass parent_class;
-};
-
-GType                   ephy_sqlite_connection_get_type                (void);
+G_DECLARE_FINAL_TYPE (EphySQLiteConnection, ephy_sqlite_connection, EPHY, SQLITE_CONNECTION, GObject)
 
 EphySQLiteConnection *  ephy_sqlite_connection_new                     (void);
 


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