This repository has been archived on 2024-07-15. You can view files and clone it, but cannot push or open issues or pull requests.
hedera/sql/sql-holder.c

130 lines
3.3 KiB
C
Raw Normal View History

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);
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 * self, SqlRender * render, SqlBatch * batch)
2013-10-11 23:07:35 +00:00
{
SqlObject * object = batch ? sql_batch_get (batch, self->id) : NULL;
2013-10-11 23:07:35 +00:00
if (object)
sql_render_add_object (render, object);
2013-10-11 23:07:35 +00:00
else
sql_render_printf (render, "#%s", self->id);
2013-10-11 23:07:35 +00:00
}
static void sql_holder_find_holders (SqlHolder * self, SqlBatch * batch)
2013-12-16 11:11:47 +00:00
{
sql_batch_add (batch, self->id, NULL);
2013-12-16 11:11:47 +00:00
}
2013-10-11 23:07:35 +00:00
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
/**
* sql_holder_get_id:
* @self: the #SqlHolder
2013-10-11 23:07:35 +00:00
*
* Gets the identifier assigned to the holder.
*
* Return value: (transfer none): the id
**/
const gchar * sql_holder_get_id (SqlHolder * self)
2013-10-11 23:07:35 +00:00
{
g_return_val_if_fail (SQL_IS_HOLDER (self), NULL);
2013-10-11 23:07:35 +00:00
return self->id;
2013-10-11 23:07:35 +00:00
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
enum
{
PROP_ID = 1
};
static void sql_holder_set_property (SqlHolder * self, guint id,
2013-10-11 23:07:35 +00:00
const GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_ID:
g_free (self->id);
self->id = g_value_dup_string (value);
2013-10-11 23:07:35 +00:00
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
2013-10-11 23:07:35 +00:00
}
}
static void sql_holder_get_property (SqlHolder * self, guint id,
2013-10-11 23:07:35 +00:00
GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_ID:
g_value_set_string (value, sql_holder_get_id (self));
2013-10-11 23:07:35 +00:00
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
2013-10-11 23:07:35 +00:00
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
static void sql_holder_init (SqlHolder * self)
2013-10-11 23:07:35 +00:00
{
self->id = NULL;
2013-10-11 23:07:35 +00:00
}
static void sql_holder_finalize (SqlHolder * self)
2013-10-11 23:07:35 +00:00
{
g_free (self->id);
G_OBJECT_CLASS (sql_holder_parent_class)->finalize (G_OBJECT (self));
2013-10-11 23:07:35 +00:00
}
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
));
}