grim/gplate

some more testing migration stuff.

2012-09-04, Gary Kramlich
7f8e0e4f250f
some more testing migration stuff.
Variables aren't done yet
/*
* GPlate - GObject based templating library
* Copyright (C) 2007-2012 Gary Kramlich <grim@reaperworld.com>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gplate/gplate-tag.h>
#define GPLATE_TAG_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GPLATE_TYPE_TAG, GPlateTagPrivate))
/******************************************************************************
* Enums
*****************************************************************************/
enum {
PROP_ZERO,
PROP_TEMPLATE,
PROP_CONTENTS,
PROP_LAST,
};
/******************************************************************************
* Structs
*****************************************************************************/
typedef struct {
GPlateTemplate *tplate;
gchar *contents;
} GPlateTagPrivate;
/******************************************************************************
* Globals
*****************************************************************************/
static GObjectClass *parent_class = NULL;
/******************************************************************************
* Tag Stuff
*****************************************************************************/
static void
gplate_tag_real_set_template(GPlateTag *tag, GPlateTemplate *tplate) {
GPlateTagPrivate *priv = GPLATE_TAG_GET_PRIVATE(tag);
if(GPLATE_IS_TEMPLATE(tplate))
priv->tplate = g_object_ref(tplate);
}
static gchar *
gplate_tag_real_get_contents(const GPlateTag *tag) {
GPlateTagPrivate *priv = GPLATE_TAG_GET_PRIVATE(tag);
return (priv->contents) ? g_strdup(priv->contents) : NULL;
}
static void
gplate_tag_real_set_contents(GPlateTag *tag, const gchar *contents) {
GPlateTagPrivate *priv = GPLATE_TAG_GET_PRIVATE(tag);
g_free(priv->contents);
priv->contents = (contents) ? g_strdup(contents) : NULL;
}
/******************************************************************************
* Object Stuff
*****************************************************************************/
static void
gplate_tag_get_property(GObject *obj, guint param_id, GValue *value,
GParamSpec *pspec)
{
GPlateTag *tag = GPLATE_TAG(obj);
switch(param_id) {
case PROP_TEMPLATE:
g_value_set_object(value, gplate_tag_get_template(tag));
break;
case PROP_CONTENTS:
g_value_set_string(value, gplate_tag_get_contents(tag));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
break;
}
}
static void
gplate_tag_set_property(GObject *obj, guint param_id, const GValue *value,
GParamSpec *pspec)
{
GPlateTag *tag = GPLATE_TAG(obj);
switch(param_id) {
case PROP_TEMPLATE:
gplate_tag_real_set_template(tag, g_value_get_object(value));
break;
case PROP_CONTENTS:
gplate_tag_real_set_contents(tag, g_value_get_string(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
break;
}
}
static void
gplate_tag_finalize(GObject *obj) {
GPlateTagPrivate *priv = GPLATE_TAG_GET_PRIVATE(obj);
g_free(priv->contents);
G_OBJECT_CLASS(parent_class)->finalize(obj);
}
static void
gplate_tag_class_init(GPlateTagClass *klass) {
GObjectClass *obj_class = G_OBJECT_CLASS(klass);
GParamSpec *pspec = NULL;
parent_class = g_type_class_peek_parent(klass);
g_type_class_add_private(klass, sizeof(GPlateTagPrivate));
obj_class->get_property = gplate_tag_get_property;
obj_class->set_property = gplate_tag_set_property;
obj_class->finalize = gplate_tag_finalize;
klass->get_contents = gplate_tag_real_get_contents;
pspec = g_param_spec_object("template", "template",
"The template this tag belongs to.",
GPLATE_TYPE_TEMPLATE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property(obj_class, PROP_TEMPLATE, pspec);
pspec = g_param_spec_string("contents", "contents",
"The contents of the tag.",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property(obj_class, PROP_CONTENTS, pspec);
}
/******************************************************************************
* GPlateTag API
*****************************************************************************/
GType
gplate_tag_get_gtype(void) {
static GType type = 0;
if(type == 0) {
static const GTypeInfo info = {
sizeof(GPlateTagClass),
NULL,
NULL,
(GClassInitFunc)gplate_tag_class_init,
NULL,
NULL,
sizeof(GPlateTag),
0,
NULL,
};
type = g_type_register_static(G_TYPE_OBJECT,
"GPlateTag",
&info, G_TYPE_FLAG_ABSTRACT);
}
return type;
}
/**
* gplate_tag_get_template:
* @tag: The #GPlateTag.
*
* Gets the #GPlateTemplate to which @tag belongs.
*
* Return Value: The #GPlateTemplate that @tag belongs to.
*/
GPlateTemplate *
gplate_tag_get_template(const GPlateTag *tag) {
GPlateTagPrivate *priv = NULL;
g_return_val_if_fail(GPLATE_IS_TAG(tag), NULL);
priv = GPLATE_TAG_GET_PRIVATE(tag);
return priv->tplate;
}
/**
* gplate_tag_get_contents:
* @tag: The #GPlateTag whose contents to get.
*
* Gets the contents of @tag.
*
* Return Value: The contents of @tag.
*/
gchar *
gplate_tag_get_contents(const GPlateTag *tag) {
GPlateTagClass *klass = NULL;
g_return_val_if_fail(GPLATE_IS_TAG(tag), NULL);
klass = GPLATE_TAG_GET_CLASS(tag);
if(klass && klass->get_contents)
return klass->get_contents(tag);
return NULL;
}
/**
* gplate_tag_class_get_prefix:
* @tag_class: The #GPlateTagClass whose prefix to grab
*
* Gets the prefix from @tag_class.
*
* Note: This is used internally by #GPlateTemplateParser and should not be
* needed unless you are implementing a new tokenize function.
*
* Return Value: The prefix for @tag_class.
*/
const gchar *
gplate_tag_class_get_prefix(const GPlateTagClass *tag_class) {
g_return_val_if_fail(GPLATE_IS_TAG_CLASS(tag_class), NULL);
if(tag_class->get_prefix)
return tag_class->get_prefix(tag_class);
return NULL;
}
/**
* gplate_tag_class_get_suffix:
* @tag_class: The #GPlateTagClass whose suffix to grab
*
* Gets the suffix from @tag_class.
*
* Note: This is used internally by #GPlateTemplateParser and should not be
* needed unless you are implementing a new tokenize function.
*
* Return Value: The suffix for @tag_class.
*/
const gchar *
gplate_tag_class_get_suffix(const GPlateTagClass *tag_class) {
g_return_val_if_fail(GPLATE_IS_TAG_CLASS(tag_class), NULL);
if(tag_class->get_suffix)
return tag_class->get_suffix(tag_class);
return NULL;
}