Convert LdSymbol into an abstract class.

Created LdLuaSymbol, which subclasses LdSymbol.
This commit is contained in:
Přemysl Eric Janouch 2010-09-25 20:59:20 +02:00
parent 23a1f25130
commit efe45e9601
5 changed files with 191 additions and 34 deletions

View File

@ -91,7 +91,8 @@ set (logdiag_SOURCES
src/ld-library.c src/ld-library.c
src/ld-symbol-category.c src/ld-symbol-category.c
src/ld-symbol.c src/ld-symbol.c
src/ld-lua.c) src/ld-lua.c
src/ld-lua-symbol.c)
set (logdiag_HEADERS set (logdiag_HEADERS
${CMAKE_CURRENT_BINARY_DIR}/config.h ${CMAKE_CURRENT_BINARY_DIR}/config.h
src/ld-marshal.h src/ld-marshal.h
@ -101,7 +102,8 @@ set (logdiag_HEADERS
src/ld-library.h src/ld-library.h
src/ld-symbol-category.h src/ld-symbol-category.h
src/ld-symbol.h src/ld-symbol.h
src/ld-lua.h) src/ld-lua.h
src/ld-lua-symbol.h)
# Generate a configure file # Generate a configure file
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.h.in configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.h.in

96
src/ld-lua-symbol.c Normal file
View File

@ -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 <gtk/gtk.h>
#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);
}

63
src/ld-lua-symbol.h Normal file
View File

@ -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__ */

View File

@ -28,18 +28,17 @@
/* /*
* LdSymbolPrivate: * LdSymbolPrivate:
* @library: The parent LdLibrary. * @parent: The parent LdSymbolCategory. It is used to identify
* The library contains the real function for rendering. * the object within it's library.
*/ */
struct _LdSymbolPrivate 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 static void ld_symbol_finalize (GObject *gobject);
ld_symbol_finalize (GObject *gobject);
static void static void
@ -57,7 +56,7 @@ static void
ld_symbol_init (LdSymbol *self) ld_symbol_init (LdSymbol *self)
{ {
self->priv = G_TYPE_INSTANCE_GET_PRIVATE self->priv = G_TYPE_INSTANCE_GET_PRIVATE
(self, LD_TYPE_SYMBOL_LIBRARY, LdSymbolPrivate); (self, LD_TYPE_SYMBOL, LdSymbolPrivate);
} }
static void static void
@ -66,29 +65,12 @@ ld_symbol_finalize (GObject *gobject)
LdSymbol *self; LdSymbol *self;
self = LD_SYMBOL (gobject); self = LD_SYMBOL (gobject);
g_object_unref (self->priv->library); g_object_unref (self->priv->parent);
/* Chain up to the parent class. */ /* Chain up to the parent class. */
G_OBJECT_CLASS (ld_symbol_parent_class)->finalize (gobject); 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: * ld_symbol_build_identifier:
* @self: A symbol object. * @self: A symbol object.
@ -96,9 +78,10 @@ LdSymbol *ld_symbol_new (LdLibrary *library)
* Build an identifier for the symbol. * Build an identifier for the symbol.
* The identifier is in the format "Category/Category/Symbol". * The identifier is in the format "Category/Category/Symbol".
*/ */
char * gchar *
ld_symbol_build_identifier (LdSymbol *self) ld_symbol_build_identifier (LdSymbol *self)
{ {
/* TODO: Implement. */
return NULL; return NULL;
} }
@ -106,12 +89,18 @@ ld_symbol_build_identifier (LdSymbol *self)
* ld_symbol_draw: * ld_symbol_draw:
* @self: A symbol object. * @self: A symbol object.
* @cr: A cairo surface to be drawn on. * @cr: A cairo surface to be drawn on.
* @param: Parameters for the symbol in a table.
* *
* Draw the symbol onto a Cairo surface. * Draw the symbol onto a Cairo surface.
*/ */
void 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);
} }

View File

@ -45,19 +45,26 @@ struct _LdSymbol
gchar *name; gchar *name;
}; };
/**
* LdSymbolClass:
* @parent_class: The parent class.
* @draw: Draw the symbol on a Cairo surface.
*/
struct _LdSymbolClass struct _LdSymbolClass
{ {
GObjectClass parent_class; GObjectClass parent_class;
void (*draw) (LdSymbol *self, cairo_t *cr);
}; };
GType ld_symbol_get_type (void) G_GNUC_CONST; GType ld_symbol_get_type (void) G_GNUC_CONST;
LdSymbol *ld_symbol_new (LdLibrary *library);
gchar *ld_symbol_build_identifier (LdSymbol *self); 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 G_END_DECLS