2013-10-11 23:07:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 - Juan Ferrer Toribio
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sql-holder.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION: sql-holder
|
|
|
|
* @Short_description:
|
|
|
|
* @Title: SqlHolder
|
|
|
|
**/
|
|
|
|
G_DEFINE_TYPE (SqlHolder, sql_holder, SQL_TYPE_OBJECT);
|
|
|
|
|
2013-10-14 11:59:07 +00:00
|
|
|
SqlObject * sql_holder_new (const gchar * id)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
|
|
|
return g_object_new (SQL_TYPE_HOLDER, "id", id, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
|
|
|
|
|
|
|
|
static void sql_holder_render (SqlHolder * obj, SqlRender * render)
|
|
|
|
{
|
|
|
|
SqlObject * held_object = NULL;
|
|
|
|
GSList * i = sql_render_get_ancestors (render);
|
|
|
|
|
|
|
|
for (; i && !held_object; i = i->next)
|
2013-10-14 11:59:07 +00:00
|
|
|
held_object = sql_object_get_held (held_object, obj->id);
|
2013-10-11 23:07:35 +00:00
|
|
|
|
|
|
|
if (held_object)
|
|
|
|
sql_render_add_object (render, held_object);
|
|
|
|
else
|
|
|
|
sql_render_printf (render, "#%s", obj->id);
|
|
|
|
}
|
|
|
|
|
2013-12-16 11:11:47 +00:00
|
|
|
static void sql_holder_find_holders (SqlHolder * obj, GQueue * holders)
|
|
|
|
{
|
|
|
|
g_queue_push_tail (holders, obj->id);
|
|
|
|
}
|
|
|
|
|
2013-10-11 23:07:35 +00:00
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sql_holder_get_id:
|
|
|
|
* @obj: the #SqlHolder
|
|
|
|
*
|
|
|
|
* Gets the identifier assigned to the holder.
|
|
|
|
*
|
|
|
|
* Return value: (transfer none): the id
|
|
|
|
**/
|
|
|
|
const gchar * sql_holder_get_id (SqlHolder * obj)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (SQL_IS_HOLDER (obj), NULL);
|
|
|
|
|
|
|
|
return obj->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_ID = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
static void sql_holder_set_property (SqlHolder * obj, guint id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case PROP_ID:
|
|
|
|
g_free (obj->id);
|
|
|
|
obj->id = g_value_dup_string (value);
|
|
|
|
break;
|
2013-10-14 11:59:07 +00:00
|
|
|
default:
|
2013-10-11 23:07:35 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sql_holder_get_property (SqlHolder * obj, guint id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case PROP_ID:
|
|
|
|
g_value_set_string (value, sql_holder_get_id (obj));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
|
|
|
|
|
|
|
static void sql_holder_init (SqlHolder * obj)
|
|
|
|
{
|
|
|
|
obj->id = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sql_holder_finalize (SqlHolder * obj)
|
|
|
|
{
|
|
|
|
g_free (obj->id);
|
|
|
|
G_OBJECT_CLASS (sql_holder_finalize)->finalize (G_OBJECT (obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sql_holder_class_init (SqlHolderClass * k)
|
|
|
|
{
|
|
|
|
GObjectClass * klass = G_OBJECT_CLASS (k);
|
|
|
|
klass->finalize = (GObjectFinalizeFunc) sql_holder_finalize;
|
|
|
|
klass->set_property = (GObjectSetPropertyFunc) sql_holder_set_property;
|
|
|
|
klass->get_property = (GObjectGetPropertyFunc) sql_holder_get_property;
|
|
|
|
SQL_OBJECT_CLASS (klass)->render = (SqlRenderFunc) sql_holder_render;
|
2013-12-16 11:11:47 +00:00
|
|
|
SQL_OBJECT_CLASS (klass)->find_holders = (SqlObjectFindHoldersFunc) sql_holder_find_holders;
|
2013-10-11 23:07:35 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (klass, PROP_ID,
|
|
|
|
g_param_spec_string ("id"
|
|
|
|
,_("Identifier")
|
|
|
|
,_("The holder identifier")
|
|
|
|
,NULL
|
|
|
|
,G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY
|
|
|
|
));
|
|
|
|
}
|