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/gvn/gvn-param.c

233 lines
5.6 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 "gvn-misc.h"
#include "gvn-param.h"
#include "gvn-value.h"
/**
* SECTION: gvn-param
* @Short_description:
* @Title: GvnParam
**/
G_DEFINE_INTERFACE (GvnParam, gvn_param, G_TYPE_OBJECT);
2013-10-11 23:07:35 +00:00
enum {
VALUE_CHANGED
,SPEC_CHANGED
,STATUS_CHANGED
,LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = {0};
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
/**
* gvn_param_get_value:
* @self: a #GvnParam where be took the value
2013-10-11 23:07:35 +00:00
*
* Gets the value of param.
*
* Return value: (transfer none): the #GValue
**/
const GValue * gvn_param_get_value (GvnParam * self)
2013-10-11 23:07:35 +00:00
{
g_return_val_if_fail (GVN_IS_PARAM (self), NULL);
return GVN_PARAM_GET_INTERFACE (self)->get_value (self);
2013-10-11 23:07:35 +00:00
}
/**
* gvn_param_request_value:
* @self: #GvnParam object where @value wants to be validated.
2013-10-11 23:07:35 +00:00
* @value: new value.
* @err: (out) (allow-none): the return location for an allocated @GError, or
* NULL to ignore errors.
*
* Sets @value into @self.
2013-10-11 23:07:35 +00:00
*
* Return value: %TRUE if assigment is valid, %FALSE otherwise.
**/
gboolean gvn_param_request_value (GvnParam * self, const GValue * value, GError ** err)
2013-10-11 23:07:35 +00:00
{
g_return_val_if_fail (GVN_IS_PARAM (self), FALSE);
2013-10-11 23:07:35 +00:00
g_return_val_if_fail (G_IS_VALUE (value), FALSE);
return GVN_PARAM_GET_INTERFACE (self)->request_value (self, value, err);
2013-10-11 23:07:35 +00:00
}
/**
* gvn_param_set_value:
* @self: #GvnParam object where @value wants to be validated.
* @value: new value.
2013-10-11 23:07:35 +00:00
*
* Sets @value into @self.
2013-10-11 23:07:35 +00:00
**/
void gvn_param_set_value (GvnParam * self, const GValue * value)
2013-10-11 23:07:35 +00:00
{
g_return_val_if_fail (GVN_IS_PARAM (self), FALSE);
g_return_val_if_fail (G_IS_VALUE (value), FALSE);
gvn_param_request_value (self, value, NULL);
2013-10-11 23:07:35 +00:00
}
2014-07-22 10:10:13 +00:00
gboolean gvn_param_get_boolean (GvnParam * self)
{
if (!gvn_value_is_null (self->value))
return g_value_get_boolean (self->value);
return FALSE;
}
gint gvn_param_get_int (GvnParam * self)
{
if (!gvn_value_is_null (self->value))
return g_value_get_int (self->value);
return 0;
}
glong gvn_param_get_long (GvnParam * self)
{
if (!gvn_value_is_null (self->value))
return g_value_get_long (self->value);
return 0L;
}
gdouble gvn_param_get_double (GvnParam * self)
{
if (!gvn_value_is_null (self->value))
return g_value_get_double (self->value);
return 0.0;
}
const gchar * gvn_param_get_string (GvnParam * self)
{
if (!gvn_value_is_null (self->value))
return g_value_get_string (self->value);
return NULL;
}
2013-10-11 23:07:35 +00:00
/**
* gvn_param_get_master:
* @self: a #GvnParam where be took the value
2013-10-11 23:07:35 +00:00
*
* Gets the master param of @self
2013-10-11 23:07:35 +00:00
*
* Return value: (transfer none): the master #GvnParam or %NULL if it haven't.
**/
GvnParam * gvn_param_get_master (GvnParam * self)
2013-10-11 23:07:35 +00:00
{
g_return_val_if_fail (GVN_IS_PARAM (self), NULL);
2013-10-11 23:07:35 +00:00
return GVN_PARAM_GET_INTERFACE (self)->get_master (self);
2013-10-11 23:07:35 +00:00
}
/**
* gvn_param_set_master:
* @self: #GvnParam object
* @master: #GvnParam master
2013-10-11 23:07:35 +00:00
*
* Sets @dst as a master of @src
**/
void gvn_param_set_master (GvnParam * self, GvnParam * master)
2013-10-11 23:07:35 +00:00
{
g_return_val_if_fail (GVN_IS_PARAM (self), NULL);
g_return_val_if_fail (GVN_IS_PARAM (master), NULL);
GVN_PARAM_GET_INTERFACE (self)->set_master (self, master);
2013-10-11 23:07:35 +00:00
}
/**
* gvn_param_get_spec:
* @self: #GvnParam object
2013-10-11 23:07:35 +00:00
*
* Gets the #GvnParamSpec of @self
2013-10-11 23:07:35 +00:00
*
* Return value: (transfer none): the #GvnParamSpec
2013-10-11 23:07:35 +00:00
**/
const GvnParamSpec * gvn_param_get_spec (GvnParam * self)
2013-10-11 23:07:35 +00:00
{
g_return_val_if_fail (GVN_IS_PARAM (self), NULL);
2013-10-11 23:07:35 +00:00
return GVN_PARAM_GET_INTERFACE (self)->get_spec (self);
2013-10-11 23:07:35 +00:00
}
/**
* gvn_param_get_status:
* @self: #GvnParam object
2013-10-11 23:07:35 +00:00
*
* Gets the status of @self
2013-10-11 23:07:35 +00:00
*
* Return value: the current status of the param.
2013-10-11 23:07:35 +00:00
**/
GvnParamStatus gvn_param_get_status (GvnParam * self)
2013-10-11 23:07:35 +00:00
{
g_return_val_if_fail (GVN_IS_PARAM (self), GVN_PARAM_STATUS_OK);
2013-10-11 23:07:35 +00:00
return GVN_PARAM_GET_INTERFACE (self)->get_status (self);
2013-10-11 23:07:35 +00:00
}
/**
* gvn_param_value_changed:
* @self: a #GvnParam
2013-10-11 23:07:35 +00:00
*
* Emits the "value-changed" signal for that param.
**/
void gvn_param_value_changed (GvnParam * self)
2013-10-11 23:07:35 +00:00
{
g_signal_emit (self, signals[VALUE_CHANGED], 0, gvn_param_get_value (self));
2013-10-11 23:07:35 +00:00
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
static void gvn_param_default_init (GvnParamInterface * iface)
2013-10-11 23:07:35 +00:00
{
signals[VALUE_CHANGED] = g_signal_new ("value-changed",
GVN_TYPE_PARAM, G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, G_TYPE_VALUE
);
signals[SPEC_CHANGED] = g_signal_new ("spec-changed",
GVN_TYPE_PARAM, G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0
);
signals[STATUS_CHANGED] = g_signal_new ("status-changed",
GVN_TYPE_PARAM, G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0
);
g_object_interface_install_property (iface,
2013-10-11 23:07:35 +00:00
g_param_spec_boxed ("value"
,_("Value")
,_("The value of the param")
,G_TYPE_VALUE
,G_PARAM_READWRITE
));
g_object_interface_install_property (iface,
2013-10-11 23:07:35 +00:00
g_param_spec_object ("master"
,_("Master")
,_("The master parameter")
2013-10-11 23:07:35 +00:00
,GVN_TYPE_PARAM
,G_PARAM_READWRITE
));
}