Logo Search packages:      
Sourcecode: vala version File versions

readonlyset.c

/* readonlyset.vala
 *
 * Copyright (C) 2007  Jürg Billeter
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.

 * This library 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
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 *    Jürg Billeter <j@bitron.ch>
 */

#include "readonlyset.h"
#include <gee/readonlyset.h>

typedef struct _GeeReadOnlySetIterator GeeReadOnlySetIterator;
typedef struct _GeeReadOnlySetIteratorClass GeeReadOnlySetIteratorClass;
typedef struct _GeeReadOnlySetIteratorPrivate GeeReadOnlySetIteratorPrivate;
struct _GeeReadOnlySetPrivate {
      GeeSet* _set;
      GBoxedCopyFunc g_dup_func;
      GDestroyNotify g_destroy_func;
};
#define GEE_READ_ONLY_SET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GEE_TYPE_READ_ONLY_SET, GeeReadOnlySetPrivate))
enum  {
      GEE_READ_ONLY_SET_DUMMY_PROPERTY,
      GEE_READ_ONLY_SET_SIZE,
      GEE_READ_ONLY_SET_SET,
      GEE_READ_ONLY_SET_G_DUP_FUNC,
      GEE_READ_ONLY_SET_G_DESTROY_FUNC
};
static GeeIterator* gee_read_only_set_real_iterator (GeeIterable* base);
static gboolean gee_read_only_set_real_contains (GeeCollection* base, gpointer item);
static gboolean gee_read_only_set_real_add (GeeCollection* base, gpointer item);
static gboolean gee_read_only_set_real_remove (GeeCollection* base, gpointer item);
static void gee_read_only_set_real_clear (GeeCollection* base);

#define GEE_READ_ONLY_SET_TYPE_ITERATOR (gee_read_only_set_iterator_get_type ())
#define GEE_READ_ONLY_SET_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_READ_ONLY_SET_TYPE_ITERATOR, GeeReadOnlySetIterator))
#define GEE_READ_ONLY_SET_ITERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEE_READ_ONLY_SET_TYPE_ITERATOR, GeeReadOnlySetIteratorClass))
#define GEE_READ_ONLY_SET_IS_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_READ_ONLY_SET_TYPE_ITERATOR))
#define GEE_READ_ONLY_SET_IS_ITERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEE_READ_ONLY_SET_TYPE_ITERATOR))
#define GEE_READ_ONLY_SET_ITERATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEE_READ_ONLY_SET_TYPE_ITERATOR, GeeReadOnlySetIteratorClass))

struct _GeeReadOnlySetIterator {
      GObject parent;
      GeeReadOnlySetIteratorPrivate * priv;
};
struct _GeeReadOnlySetIteratorClass {
      GObjectClass parent;
};
enum  {
      GEE_READ_ONLY_SET_ITERATOR_DUMMY_PROPERTY,
      GEE_READ_ONLY_SET_ITERATOR_G_DUP_FUNC,
      GEE_READ_ONLY_SET_ITERATOR_G_DESTROY_FUNC
};
static gboolean gee_read_only_set_iterator_real_next (GeeIterator* base);
static gpointer gee_read_only_set_iterator_real_get (GeeIterator* base);
static gpointer gee_read_only_set_iterator_parent_class = NULL;
static GeeIteratorIface* gee_read_only_set_iterator_gee_iterator_parent_iface = NULL;
GType gee_read_only_set_iterator_get_type (void);
static gpointer gee_read_only_set_parent_class = NULL;
static GeeIterableIface* gee_read_only_set_gee_iterable_parent_iface = NULL;
static GeeCollectionIface* gee_read_only_set_gee_collection_parent_iface = NULL;
static GeeSetIface* gee_read_only_set_gee_set_parent_iface = NULL;
static void gee_read_only_set_dispose (GObject * obj);


GeeReadOnlySet* gee_read_only_set_new (GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, GeeSet* set)
{
      GeeReadOnlySet * self;
      g_return_val_if_fail (set == NULL || GEE_IS_SET (set), NULL);
      self = g_object_newv (GEE_TYPE_READ_ONLY_SET, 0, NULL);
      gee_read_only_set_set_set (self, set);
      self->priv->g_dup_func = g_dup_func;
      self->priv->g_destroy_func = g_destroy_func;
      return self;
}


static GeeIterator* gee_read_only_set_real_iterator (GeeIterable* base)
{
      GeeReadOnlySet * self;
      self = ((GeeReadOnlySet*) base);
      if (self->priv->_set == NULL) {
            return GEE_ITERATOR (g_object_new (GEE_READ_ONLY_SET_TYPE_ITERATOR, NULL));
      }
      return gee_iterable_iterator (GEE_ITERABLE (self->priv->_set));
}


static gboolean gee_read_only_set_real_contains (GeeCollection* base, gpointer item)
{
      GeeReadOnlySet * self;
      self = ((GeeReadOnlySet*) base);
      if (self->priv->_set == NULL) {
            return FALSE;
      }
      return gee_collection_contains (GEE_COLLECTION (self->priv->_set), item);
}


static gboolean gee_read_only_set_real_add (GeeCollection* base, gpointer item)
{
      GeeReadOnlySet * self;
      self = ((GeeReadOnlySet*) base);
      g_assert_not_reached ();
      return FALSE;
}


static gboolean gee_read_only_set_real_remove (GeeCollection* base, gpointer item)
{
      GeeReadOnlySet * self;
      self = ((GeeReadOnlySet*) base);
      g_assert_not_reached ();
      return FALSE;
}


static void gee_read_only_set_real_clear (GeeCollection* base)
{
      GeeReadOnlySet * self;
      self = ((GeeReadOnlySet*) base);
      g_assert_not_reached ();
}


static gint gee_read_only_set_real_get_size (GeeReadOnlySet* self)
{
      g_return_val_if_fail (GEE_IS_READ_ONLY_SET (self), 0);
      return gee_collection_get_size (((GeeCollection*) self->priv->_set));
}


void gee_read_only_set_set_set (GeeReadOnlySet* self, GeeSet* value)
{
      GeeSet* __temp8;
      GeeSet* __temp7;
      g_return_if_fail (GEE_IS_READ_ONLY_SET (self));
      __temp8 = NULL;
      __temp7 = NULL;
      self->priv->_set = (__temp8 = (__temp7 = value, (__temp7 == NULL ? NULL : g_object_ref (__temp7))), (self->priv->_set == NULL ? NULL : (self->priv->_set = (g_object_unref (self->priv->_set), NULL))), __temp8);
}


static gboolean gee_read_only_set_iterator_real_next (GeeIterator* base)
{
      GeeReadOnlySetIterator * self;
      self = ((GeeReadOnlySetIterator*) base);
      return FALSE;
}


static gpointer gee_read_only_set_iterator_real_get (GeeIterator* base)
{
      GeeReadOnlySetIterator * self;
      self = ((GeeReadOnlySetIterator*) base);
      return NULL;
}


static void gee_read_only_set_iterator_class_init (GeeReadOnlySetIteratorClass * klass)
{
      gee_read_only_set_iterator_parent_class = g_type_class_peek_parent (klass);
      g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_READ_ONLY_SET_ITERATOR_G_DUP_FUNC, g_param_spec_pointer ("g-dup-func", "dup func", "dup func", G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE));
      g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_READ_ONLY_SET_ITERATOR_G_DESTROY_FUNC, g_param_spec_pointer ("g-destroy-func", "destroy func", "destroy func", G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE));
}


static void gee_read_only_set_iterator_gee_iterator_interface_init (GeeIteratorIface * iface)
{
      gee_read_only_set_iterator_gee_iterator_parent_iface = g_type_interface_peek_parent (iface);
      iface->next = gee_read_only_set_iterator_real_next;
      iface->get = gee_read_only_set_iterator_real_get;
}


static void gee_read_only_set_iterator_init (GeeReadOnlySetIterator * self)
{
}


GType gee_read_only_set_iterator_get_type (void)
{
      static GType gee_read_only_set_iterator_type_id = 0;
      if (G_UNLIKELY (gee_read_only_set_iterator_type_id == 0)) {
            static const GTypeInfo g_define_type_info = { sizeof (GeeReadOnlySetIteratorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gee_read_only_set_iterator_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GeeReadOnlySetIterator), 0, (GInstanceInitFunc) gee_read_only_set_iterator_init };
            static const GInterfaceInfo gee_iterator_info = { (GInterfaceInitFunc) gee_read_only_set_iterator_gee_iterator_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
            gee_read_only_set_iterator_type_id = g_type_register_static (G_TYPE_OBJECT, "GeeReadOnlySetIterator", &g_define_type_info, 0);
            g_type_add_interface_static (gee_read_only_set_iterator_type_id, GEE_TYPE_ITERATOR, &gee_iterator_info);
      }
      return gee_read_only_set_iterator_type_id;
}


static void gee_read_only_set_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec)
{
      GeeReadOnlySet * self;
      self = GEE_READ_ONLY_SET (object);
      switch (property_id) {
            case GEE_READ_ONLY_SET_SIZE:
            g_value_set_int (value, gee_read_only_set_real_get_size (self));
            break;
      }
}


static void gee_read_only_set_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec)
{
      GeeReadOnlySet * self;
      self = GEE_READ_ONLY_SET (object);
      switch (property_id) {
            case GEE_READ_ONLY_SET_SET:
            gee_read_only_set_set_set (self, g_value_get_object (value));
            break;
            case GEE_READ_ONLY_SET_G_DESTROY_FUNC:
            self->priv->g_destroy_func = g_value_get_pointer (value);
            break;
      }
}


static void gee_read_only_set_class_init (GeeReadOnlySetClass * klass)
{
      gee_read_only_set_parent_class = g_type_class_peek_parent (klass);
      g_type_class_add_private (klass, sizeof (GeeReadOnlySetPrivate));
      G_OBJECT_CLASS (klass)->get_property = gee_read_only_set_get_property;
      G_OBJECT_CLASS (klass)->set_property = gee_read_only_set_set_property;
      G_OBJECT_CLASS (klass)->dispose = gee_read_only_set_dispose;
      g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_READ_ONLY_SET_G_DUP_FUNC, g_param_spec_pointer ("g-dup-func", "dup func", "dup func", G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE));
      g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_READ_ONLY_SET_G_DESTROY_FUNC, g_param_spec_pointer ("g-destroy-func", "destroy func", "destroy func", G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE));
      g_object_class_override_property (G_OBJECT_CLASS (klass), GEE_READ_ONLY_SET_SIZE, "size");
      g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_READ_ONLY_SET_SET, g_param_spec_object ("set", "foo", "bar", GEE_TYPE_SET, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE));
}


static void gee_read_only_set_gee_iterable_interface_init (GeeIterableIface * iface)
{
      gee_read_only_set_gee_iterable_parent_iface = g_type_interface_peek_parent (iface);
      iface->iterator = gee_read_only_set_real_iterator;
}


static void gee_read_only_set_gee_collection_interface_init (GeeCollectionIface * iface)
{
      gee_read_only_set_gee_collection_parent_iface = g_type_interface_peek_parent (iface);
      iface->contains = gee_read_only_set_real_contains;
      iface->add = gee_read_only_set_real_add;
      iface->remove = gee_read_only_set_real_remove;
      iface->clear = gee_read_only_set_real_clear;
}


static void gee_read_only_set_gee_set_interface_init (GeeSetIface * iface)
{
      gee_read_only_set_gee_set_parent_iface = g_type_interface_peek_parent (iface);
}


static void gee_read_only_set_init (GeeReadOnlySet * self)
{
      self->priv = GEE_READ_ONLY_SET_GET_PRIVATE (self);
}


static void gee_read_only_set_dispose (GObject * obj)
{
      GeeReadOnlySet * self;
      GeeReadOnlySetClass * klass;
      GObjectClass * parent_class;
      self = GEE_READ_ONLY_SET (obj);
      (self->priv->_set == NULL ? NULL : (self->priv->_set = (g_object_unref (self->priv->_set), NULL)));
      klass = GEE_READ_ONLY_SET_CLASS (g_type_class_peek (GEE_TYPE_READ_ONLY_SET));
      parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
      parent_class->dispose (obj);
}


GType gee_read_only_set_get_type (void)
{
      static GType gee_read_only_set_type_id = 0;
      if (G_UNLIKELY (gee_read_only_set_type_id == 0)) {
            static const GTypeInfo g_define_type_info = { sizeof (GeeReadOnlySetClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gee_read_only_set_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GeeReadOnlySet), 0, (GInstanceInitFunc) gee_read_only_set_init };
            static const GInterfaceInfo gee_iterable_info = { (GInterfaceInitFunc) gee_read_only_set_gee_iterable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
            static const GInterfaceInfo gee_collection_info = { (GInterfaceInitFunc) gee_read_only_set_gee_collection_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
            static const GInterfaceInfo gee_set_info = { (GInterfaceInitFunc) gee_read_only_set_gee_set_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
            gee_read_only_set_type_id = g_type_register_static (G_TYPE_OBJECT, "GeeReadOnlySet", &g_define_type_info, 0);
            g_type_add_interface_static (gee_read_only_set_type_id, GEE_TYPE_ITERABLE, &gee_iterable_info);
            g_type_add_interface_static (gee_read_only_set_type_id, GEE_TYPE_COLLECTION, &gee_collection_info);
            g_type_add_interface_static (gee_read_only_set_type_id, GEE_TYPE_SET, &gee_set_info);
      }
      return gee_read_only_set_type_id;
}





Generated by  Doxygen 1.6.0   Back to index