/* * Copyright (C) 2011 Benjamin Otte * * 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 2, 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, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "game-private.h" #include "game-data-resource.h" enum { PROP_0, PROP_DATA, PROP_SIZE }; G_DEFINE_ABSTRACT_TYPE (GameDataResource, game_data_resource, GAME_TYPE_RESOURCE) static void game_data_resource_get_property (GObject *object, guint param_id, GValue *value, GParamSpec * pspec) { GameDataResource *resource = GAME_DATA_RESOURCE (object); switch (param_id) { case PROP_DATA: g_value_set_pointer (value, resource->data); break; case PROP_SIZE: g_value_set_ulong (value, resource->size); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; } } static void game_data_resource_set_property (GObject *object, guint param_id, const GValue *value, GParamSpec *pspec) { switch (param_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; } } static void game_data_resource_dispose (GObject *object) { GameDataResource *resource = GAME_DATA_RESOURCE (object); game_data_resource_set_data (resource, NULL, 0); G_OBJECT_CLASS (game_data_resource_parent_class)->dispose (object); } static void game_data_resource_class_init (GameDataResourceClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->set_property = game_data_resource_set_property; object_class->get_property = game_data_resource_get_property; object_class->dispose = game_data_resource_dispose; g_object_class_install_property (object_class, PROP_DATA, g_param_spec_object ("data", _("data"), _("data of this resource"), GAME_TYPE_GAME, G_PARAM_READABLE)); g_object_class_install_property (object_class, PROP_SIZE, g_param_spec_ulong ("size", _("size"), _("size of the given data"), 0, G_MAXULONG, 0, G_PARAM_READABLE)); } static void game_data_resource_init (GameDataResource *resource) { } const guchar * game_data_resource_get_data (GameDataResource *resource) { g_return_val_if_fail (GAME_IS_DATA_RESOURCE (resource), NULL); return resource->data; } gsize game_data_resource_get_size (GameDataResource *resource) { g_return_val_if_fail (GAME_IS_DATA_RESOURCE (resource), 0); return resource->size; } void game_data_resource_set_data (GameDataResource *resource, guchar * data, gsize size) { g_return_if_fail (GAME_IS_DATA_RESOURCE (resource)); g_return_if_fail (size == 0 || data != NULL); g_return_if_fail (data == NULL || size != 0); g_free (resource->data); resource->data = data; resource->size = size; g_object_notify (G_OBJECT (resource), "data"); g_object_notify (G_OBJECT (resource), "size"); }