From efe45e9601a268566ddbb99c917beeca76be50a0 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Sat, 25 Sep 2010 20:59:20 +0200
Subject: Convert LdSymbol into an abstract class.
Created LdLuaSymbol, which subclasses LdSymbol.
---
src/ld-lua-symbol.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/ld-lua-symbol.h | 63 +++++++++++++++++++++++++++++++++++
src/ld-symbol.c | 47 ++++++++++----------------
src/ld-symbol.h | 13 ++++++--
4 files changed, 187 insertions(+), 32 deletions(-)
create mode 100644 src/ld-lua-symbol.c
create mode 100644 src/ld-lua-symbol.h
(limited to 'src')
diff --git a/src/ld-lua-symbol.c b/src/ld-lua-symbol.c
new file mode 100644
index 0000000..9b87f72
--- /dev/null
+++ b/src/ld-lua-symbol.c
@@ -0,0 +1,96 @@
+/*
+ * ld-lua-symbol.c
+ *
+ * This file is a part of logdiag.
+ * Copyright Přemysl Janouch 2010. All rights reserved.
+ *
+ * See the file LICENSE for licensing information.
+ *
+ */
+
+#include
+
+#include "config.h"
+
+#include "ld-library.h"
+#include "ld-symbol.h"
+#include "ld-symbol-category.h"
+#include "ld-lua.h"
+#include "ld-lua-symbol.h"
+
+
+/**
+ * SECTION:ld-lua-symbol
+ * @short_description: A symbol.
+ * @see_also: #LdSymbol
+ *
+ * #LdLuaSymbol is an implementation of #LdSymbol.
+ */
+
+/*
+ * LdLuaSymbolPrivate:
+ * @lua: Parent Lua object.
+ */
+struct _LdLuaSymbolPrivate
+{
+ LdLua *lua;
+};
+
+G_DEFINE_TYPE (LdLuaSymbol, ld_lua_symbol, LD_TYPE_SYMBOL);
+
+static void ld_lua_symbol_finalize (GObject *gobject);
+
+
+static void
+ld_lua_symbol_class_init (LdLuaSymbolClass *klass)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = ld_lua_symbol_finalize;
+
+ g_type_class_add_private (klass, sizeof (LdLuaSymbolPrivate));
+}
+
+static void
+ld_lua_symbol_init (LdLuaSymbol *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE
+ (self, LD_TYPE_LUA_SYMBOL, LdLuaSymbolPrivate);
+}
+
+static void
+ld_lua_symbol_finalize (GObject *gobject)
+{
+ LdLuaSymbol *self;
+
+ self = LD_LUA_SYMBOL (gobject);
+ g_object_unref (self->priv->lua);
+
+ /* Chain up to the parent class. */
+ G_OBJECT_CLASS (ld_lua_symbol_parent_class)->finalize (gobject);
+}
+
+
+/**
+ * ld_symbol_new:
+ * @library: A library object.
+ * @filename: The file from which the symbol will be loaded.
+ *
+ * Load a symbol from a file into the library.
+ */
+LdSymbol *
+ld_lua_symbol_new (LdSymbolCategory *parent, LdLua *lua)
+{
+ LdLuaSymbol *symbol;
+
+ symbol = g_object_new (LD_TYPE_LUA_SYMBOL, NULL);
+
+ /* TODO: Create a separate ld-symbol-private.h, include it in this file
+ * and then assign and ref the parent category here.
+ */
+
+ symbol->priv->lua = lua;
+ g_object_ref (lua);
+}
+
diff --git a/src/ld-lua-symbol.h b/src/ld-lua-symbol.h
new file mode 100644
index 0000000..a90feb7
--- /dev/null
+++ b/src/ld-lua-symbol.h
@@ -0,0 +1,63 @@
+/*
+ * ld-lua-symbol.h
+ *
+ * This file is a part of logdiag.
+ * Copyright Přemysl Janouch 2010. All rights reserved.
+ *
+ * See the file LICENSE for licensing information.
+ *
+ */
+
+#ifndef __LD_LUA_SYMBOL_H__
+#define __LD_LUA_SYMBOL_H__
+
+G_BEGIN_DECLS
+
+
+#define LD_TYPE_LUA_SYMBOL (ld_lua_symbol_get_type ())
+#define LD_LUA_SYMBOL(obj) (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), LD_TYPE_LUA_SYMBOL, LdLuaSymbol))
+#define LD_LUA_SYMBOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \
+ ((klass), LD_TYPE_LUA_SYMBOL, LdLuaSymbolClass))
+#define LD_IS_LUA_SYMBOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), LD_TYPE_LUA_SYMBOL))
+#define LD_IS_LUA_SYMBOL_CLASS(klass) (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((klass), LD_TYPE_LUA_SYMBOL))
+#define LD_LUA_SYMBOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), LD_LUA_SYMBOL, LdLuaSymbolClass))
+
+typedef struct _LdLuaSymbol LdLuaSymbol;
+typedef struct _LdLuaSymbolPrivate LdLuaSymbolPrivate;
+typedef struct _LdLuaSymbolClass LdLuaSymbolClass;
+
+
+/**
+ * LdLuaSymbol:
+ * @name: The name of this symbol.
+ */
+struct _LdLuaSymbol
+{
+/*< private >*/
+ LdSymbol parent_instance;
+ LdLuaSymbolPrivate *priv;
+};
+
+/**
+ * LdLuaSymbolClass:
+ * @parent_class: The parent class.
+ */
+struct _LdLuaSymbolClass
+{
+ LdSymbolClass parent_class;
+};
+
+
+GType ld_lua_symbol_get_type (void) G_GNUC_CONST;
+
+LdSymbol *ld_lua_symbol_new (LdSymbolCategory *parent, LdLua *lua);
+
+
+G_END_DECLS
+
+#endif /* ! __LD_LUA_SYMBOL_H__ */
+
diff --git a/src/ld-symbol.c b/src/ld-symbol.c
index 4bfe6a2..9dc4394 100644
--- a/src/ld-symbol.c
+++ b/src/ld-symbol.c
@@ -28,18 +28,17 @@
/*
* LdSymbolPrivate:
- * @library: The parent LdLibrary.
- * The library contains the real function for rendering.
+ * @parent: The parent LdSymbolCategory. It is used to identify
+ * the object within it's library.
*/
struct _LdSymbolPrivate
{
- LdLibrary *library;
+ LdSymbolCategory *parent;
};
-G_DEFINE_TYPE (LdSymbol, ld_symbol, G_TYPE_OBJECT);
+G_DEFINE_ABSTRACT_TYPE (LdSymbol, ld_symbol, G_TYPE_OBJECT);
-static void
-ld_symbol_finalize (GObject *gobject);
+static void ld_symbol_finalize (GObject *gobject);
static void
@@ -57,7 +56,7 @@ static void
ld_symbol_init (LdSymbol *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE
- (self, LD_TYPE_SYMBOL_LIBRARY, LdSymbolPrivate);
+ (self, LD_TYPE_SYMBOL, LdSymbolPrivate);
}
static void
@@ -66,29 +65,12 @@ ld_symbol_finalize (GObject *gobject)
LdSymbol *self;
self = LD_SYMBOL (gobject);
- g_object_unref (self->priv->library);
+ g_object_unref (self->priv->parent);
/* Chain up to the parent class. */
G_OBJECT_CLASS (ld_symbol_parent_class)->finalize (gobject);
}
-/**
- * ld_symbol_new:
- * @library: A library object.
- * @filename: The file from which the symbol will be loaded.
- *
- * Load a symbol from a file into the library.
- */
-LdSymbol *ld_symbol_new (LdLibrary *library)
-{
- LdSymbol *symbol;
-
- symbol = g_object_new (LD_TYPE_SYMBOL, NULL);
-
- symbol->priv->library = library;
- g_object_ref (library);
-}
-
/**
* ld_symbol_build_identifier:
* @self: A symbol object.
@@ -96,9 +78,10 @@ LdSymbol *ld_symbol_new (LdLibrary *library)
* Build an identifier for the symbol.
* The identifier is in the format "Category/Category/Symbol".
*/
-char *
+gchar *
ld_symbol_build_identifier (LdSymbol *self)
{
+ /* TODO: Implement. */
return NULL;
}
@@ -106,12 +89,18 @@ ld_symbol_build_identifier (LdSymbol *self)
* ld_symbol_draw:
* @self: A symbol object.
* @cr: A cairo surface to be drawn on.
- * @param: Parameters for the symbol in a table.
*
* Draw the symbol onto a Cairo surface.
*/
void
-ld_symbol_draw (LdSymbol *self, cairo_t *cr, GHashTable *param)
+ld_symbol_draw (LdSymbol *self, cairo_t *cr)
{
- return;
+ LdSymbolClass *klass;
+
+ g_return_if_fail (LD_IS_SYMBOL (self));
+ g_return_if_fail (cr != NULL);
+
+ klass = LD_SYMBOL_GET_CLASS (self);
+ if (klass->draw)
+ klass->draw (self, cr);
}
diff --git a/src/ld-symbol.h b/src/ld-symbol.h
index f3a2d35..3d5967c 100644
--- a/src/ld-symbol.h
+++ b/src/ld-symbol.h
@@ -45,19 +45,26 @@ struct _LdSymbol
gchar *name;
};
+/**
+ * LdSymbolClass:
+ * @parent_class: The parent class.
+ * @draw: Draw the symbol on a Cairo surface.
+ */
struct _LdSymbolClass
{
GObjectClass parent_class;
+
+ void (*draw) (LdSymbol *self, cairo_t *cr);
};
GType ld_symbol_get_type (void) G_GNUC_CONST;
-LdSymbol *ld_symbol_new (LdLibrary *library);
gchar *ld_symbol_build_identifier (LdSymbol *self);
-void ld_symbol_draw (LdSymbol *self, cairo_t *cr, GHashTable *param);
-/* TODO: An interface for symbol terminals. */
+void ld_symbol_draw (LdSymbol *self, cairo_t *cr);
+
+/* TODO: An interface for symbol terminals etc. */
G_END_DECLS
--
cgit v1.2.3-70-g09d2