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/vn/vn-set.c

150 lines
3.5 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/>.
*/
2014-07-11 13:01:22 +00:00
#include "vn-set.h"
2013-10-11 23:07:35 +00:00
/**
2014-07-11 13:01:22 +00:00
* SECTION: vn-set
2013-10-11 23:07:35 +00:00
* @Short_description: a group of objects
2014-07-11 13:01:22 +00:00
* @Title: VnSet
2013-10-11 23:07:35 +00:00
*
* A group of GObjects.
*/
2014-07-11 13:01:22 +00:00
static void vn_set_buildable_interface_init (GtkBuildableIface * iface);
2014-07-11 13:01:22 +00:00
G_DEFINE_TYPE_WITH_CODE (VnSet, vn_set, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
2014-07-11 13:01:22 +00:00
vn_set_buildable_interface_init)
);
2013-10-11 23:07:35 +00:00
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Methods
/**
2014-07-11 13:01:22 +00:00
* vn_set_add:
* @obj: a #VnSet
2013-10-11 23:07:35 +00:00
* @child: a #GObject
*
* Adds a child identified whith @id to the group.
**/
2014-07-11 13:01:22 +00:00
void vn_set_add (VnSet * obj, GObject * child)
2013-10-11 23:07:35 +00:00
{
2014-07-11 13:01:22 +00:00
g_return_if_fail (VN_IS_SET (obj));
2013-10-11 23:07:35 +00:00
g_return_if_fail (G_IS_OBJECT (child));
obj->objects = g_list_prepend (obj->objects, child);
2013-10-14 12:08:06 +00:00
obj->count++;
2013-10-11 23:07:35 +00:00
}
/**
2014-07-11 13:01:22 +00:00
* vn_set_remove:
* @obj: a #VnSet
2013-10-11 23:07:35 +00:00
* @child: a #GObject contained by @obj
*
* Removes a child from the group.
**/
2014-07-11 13:01:22 +00:00
void vn_set_remove (VnSet * obj, GObject * child)
2013-10-11 23:07:35 +00:00
{
2014-07-11 13:01:22 +00:00
g_return_if_fail (VN_IS_SET (obj));
2013-10-11 23:07:35 +00:00
obj->objects = g_list_remove (obj->objects, child);
2013-10-14 12:08:06 +00:00
obj->count--;
2013-10-11 23:07:35 +00:00
}
/**
2014-07-11 13:01:22 +00:00
* vn_set_get_objects_list:
* @obj: a #VnSet
2013-10-11 23:07:35 +00:00
*
* Returns all the #GObject<!-- -->s in @obj, copying the list. This method is
2014-07-11 13:01:22 +00:00
* mainly for internal use, use vn_set_get_objects() instead if you don't need
* to do further use of the list of objects.
2013-10-11 23:07:35 +00:00
*
* Return value: (transfer container) (element-type GObject): a #GList with all
* the objects, that must be freed with #g_list_free
**/
2014-07-11 13:01:22 +00:00
GList * vn_set_get_objects_list (VnSet * obj)
2013-10-11 23:07:35 +00:00
{
2014-07-11 13:01:22 +00:00
g_return_val_if_fail (VN_IS_SET (obj), NULL);
2013-10-11 23:07:35 +00:00
return g_list_copy (obj->objects);
}
2013-10-14 12:08:06 +00:00
/**
2014-07-11 13:01:22 +00:00
* vn_set_get_objects:
* @obj: a #VnSet
2013-10-14 12:08:06 +00:00
*
* Returns all the #GObject<!-- -->s in @obj.
*
* Return value: (transfer none) (element-type GObject): a #GList with all
* the objects, that must not be freed
**/
2014-07-11 13:01:22 +00:00
const GList * vn_set_get_objects (VnSet * obj)
2013-10-14 12:08:06 +00:00
{
2014-07-11 13:01:22 +00:00
g_return_val_if_fail (VN_IS_SET (obj), NULL);
2013-10-14 12:08:06 +00:00
return obj->objects;
}
/**
2014-07-11 13:01:22 +00:00
* vn_set_get_length:
* @obj: a #VnSet
2013-10-14 12:08:06 +00:00
*
* Returns the number of childs currently contained in @obj.
*
* Return value: the number of childs
**/
2014-07-11 13:01:22 +00:00
guint vn_set_get_length (VnSet * obj)
2013-10-14 12:08:06 +00:00
{
2014-07-11 13:01:22 +00:00
g_return_val_if_fail (VN_IS_SET (obj), 0);
2013-10-14 12:08:06 +00:00
return obj->count;
}
2014-07-11 13:01:22 +00:00
static void vn_set_buildable_add_child (GtkBuildable * obj,
2013-10-11 23:07:35 +00:00
GtkBuilder * builder, GObject * child, const gchar * type)
{
2014-07-11 13:01:22 +00:00
vn_set_add (VN_SET (obj), child);
2013-10-11 23:07:35 +00:00
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
2014-07-11 13:01:22 +00:00
static void vn_set_init (VnSet * obj)
2013-10-11 23:07:35 +00:00
{
obj->objects = NULL;
2013-10-14 12:08:06 +00:00
obj->count = 0;
2013-10-11 23:07:35 +00:00
}
2014-07-11 13:01:22 +00:00
static void vn_set_finalize (VnSet * obj)
2013-10-11 23:07:35 +00:00
{
2014-07-11 13:01:22 +00:00
GObjectClass * parent = g_type_class_peek_parent (VN_SET_GET_CLASS (obj));
2013-10-11 23:07:35 +00:00
g_list_free (obj->objects);
parent->finalize (G_OBJECT (obj));
}
2014-07-11 13:01:22 +00:00
static void vn_set_class_init (VnSetClass * klass)
2013-10-11 23:07:35 +00:00
{
GObjectClass * k = G_OBJECT_CLASS (klass);
2014-07-11 13:01:22 +00:00
k->finalize = (GObjectFinalizeFunc) vn_set_finalize;
2013-10-11 23:07:35 +00:00
}
2014-07-11 13:01:22 +00:00
static void vn_set_buildable_interface_init (GtkBuildableIface * iface)
2013-10-11 23:07:35 +00:00
{
2014-07-11 13:01:22 +00:00
iface->add_child = vn_set_buildable_add_child;
2013-10-11 23:07:35 +00:00
}