--- a/ChangeLog Thu Jan 01 01:04:23 2009 -0600
+++ b/ChangeLog Fri Jan 02 07:53:56 2009 -0600
@@ -1,3 +1,6 @@
+Version 0.0.3 ??/??/????: + * Added an iterator to GPlateObjectVariable Version 0.0.2 09/20/2008:
* Fixed the bug where a default tag that didn't start with a word rendered
--- a/gplate/variables/gplate-object-variable.c Thu Jan 01 01:04:23 2009 -0600
+++ b/gplate/variables/gplate-object-variable.c Fri Jan 02 07:53:56 2009 -0600
@@ -29,6 +29,11 @@
#define GPLATE_OBJECT_VARIABLE_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GPLATE_TYPE_OBJECT_VARIABLE, GPlateObjectVariablePrivate))
+#define GPLATE_TYPE_OBJECT_VARIABLE_ITERATOR (gplate_object_variable_iterator_get_gtype()) +#define GPLATE_OBJECT_VARIABLE_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GPLATE_TYPE_OBJECT_VARIABLE_ITERATOR, GPlateObjectVariableIterator)) +static GType gplate_object_variable_iterator_get_gtype(void); /******************************************************************************
*****************************************************************************/
@@ -45,23 +50,215 @@
} GPlateObjectVariablePrivate;
+ GPlateObjectVariable *objvar; +} GPlateObjectVariableIterator; +} GPlateObjectVariableIteratorClass; /******************************************************************************
*****************************************************************************/
static GObjectClass *parent_class = NULL;
+static GObjectClass *iterator_parent_class = NULL; +/****************************************************************************** + *****************************************************************************/ +gplate_variable_from_paramspec(GObject *obj, GParamSpec *pspec) { + GPlateVariable *variable = NULL; + const gchar *name = g_param_spec_get_name(pspec); + g_object_get_property(obj, name, &value); + switch(G_PARAM_SPEC_VALUE_TYPE(pspec)) { + gplate_variable_new_from_string(name, + g_value_get_string(&value)); + gplate_variable_new_from_integer(name, + g_value_get_int(&value)); + gplate_variable_new_from_float(name, + g_value_get_float(&value)); + gplate_variable_new_from_double(name, + g_value_get_double(&value)); + variable = gplate_object_variable_new_from_object(name, + g_value_get_object(&value)); /******************************************************************************
+ * Iterator Interface Stuff + *****************************************************************************/ +gplate_object_variable_iterator_has_next(const GPlateIterator *iter) { + GPlateObjectVariableIterator *realiter = + GPLATE_OBJECT_VARIABLE_ITERATOR(iter); + return (realiter->current < realiter->total - 1); + return (realiter->elements != NULL); +gplate_object_variable_iterator_next(GPlateIterator *iter) { + GPlateObjectVariableIterator *realiter = NULL; + GParamSpec *pspec = NULL; + realiter = GPLATE_OBJECT_VARIABLE_ITERATOR(iter); + if(!realiter->inited) { + realiter->inited = TRUE; + if(realiter->current >= realiter->total) + pspec = realiter->elements[realiter->current]; + obj = gplate_object_variable_get_object(realiter->objvar); + return gplate_variable_from_paramspec(obj, pspec); +gplate_object_variable_iterator_iface_init(GPlateIteratorIface *iface) { + iface->has_next = gplate_object_variable_iterator_has_next; + iface->next = gplate_object_variable_iterator_next; +/****************************************************************************** + * Iterator Object Stuff + *****************************************************************************/ +gplate_object_variable_iterator_finalize(GObject *obj) { + GPlateObjectVariableIterator *iter = GPLATE_OBJECT_VARIABLE_ITERATOR(obj); + g_object_unref(iter->objvar); + g_free(iter->elements); + G_OBJECT_CLASS(iterator_parent_class)->finalize(obj); +gplate_object_variable_iterator_class_init( + GPlateObjectVariableIteratorClass *klass) + GObjectClass *obj_class = G_OBJECT_CLASS(klass); + iterator_parent_class = g_type_class_peek_parent(klass); + obj_class->finalize = gplate_object_variable_iterator_finalize; +/****************************************************************************** + *****************************************************************************/ +gplate_object_variable_iterator_get_gtype(void) { + if(G_UNLIKELY(type == 0)) { + static const GTypeInfo info = { + sizeof(GPlateObjectVariableIteratorClass), + (GClassInitFunc)gplate_object_variable_iterator_class_init, + sizeof(GPlateObjectVariableIterator), + static const GInterfaceInfo iterator_info = { + (GInterfaceInitFunc)gplate_object_variable_iterator_iface_init, + type = g_type_register_static(G_TYPE_OBJECT, + "GPlateObjectVariableIterator", + g_type_add_interface_static(type, GPLATE_TYPE_ITERATOR, +gplate_object_variable_iterator_new(GPlateObjectVariable *objvar) { + GPlateIterator *iter = NULL; + GPlateObjectVariableIterator *realiter = NULL; + GPlateObjectVariablePrivate *priv = NULL; + GObjectClass *klass = NULL; + iter = g_object_new(GPLATE_TYPE_OBJECT_VARIABLE_ITERATOR, NULL); + realiter = GPLATE_OBJECT_VARIABLE_ITERATOR(iter); + realiter->objvar = g_object_ref(objvar); + priv = GPLATE_OBJECT_VARIABLE_GET_PRIVATE(objvar); + klass = G_OBJECT_GET_CLASS(priv->object); + realiter->elements = g_object_class_list_properties(klass, + realiter->inited = FALSE; +/****************************************************************************** + * Collection Interface Stuff *****************************************************************************/
gplate_object_variable_find_variable(const GPlateCollection *collection,
GPlateObjectVariablePrivate *priv = NULL;
- GPlateVariable *variable = NULL;
GParamSpec *pspec = NULL;
GObjectClass *obj_class = NULL;
gchar *aname = NULL, *dot = NULL;
g_return_val_if_fail(name, NULL);
@@ -94,48 +291,24 @@
if(!G_IS_PARAM_SPEC(pspec))
- /* We know the type early, so we'll initialize our value to that type */
- g_value_init(&val, G_PARAM_SPEC_VALUE_TYPE(pspec));
+ /* now we have the value, so let's create our variable */ + return gplate_variable_from_paramspec(priv->object, pspec); - /* now we have the value, so let's create our variable */
- switch(G_PARAM_SPEC_VALUE_TYPE(pspec)) {
- gplate_variable_new_from_string(g_param_spec_get_name(pspec),
- g_value_get_string(&val));
- gplate_variable_new_from_integer(g_param_spec_get_name(pspec),
- g_value_get_int(&val));
- gplate_variable_new_from_float(g_param_spec_get_name(pspec),
- g_value_get_float(&val));
- gplate_variable_new_from_double(g_param_spec_get_name(pspec),
- g_value_get_double(&val));
- variable = gplate_object_variable_new_from_object(
- g_param_spec_get_name(pspec),
- g_value_get_object(&val));
+gplate_object_variable_get_iterator(GPlateCollection *collection) { + GPlateObjectVariable *objvar = GPLATE_OBJECT_VARIABLE(collection); + return gplate_object_variable_iterator_new(objvar); gplate_object_variable_collection_init(GPlateCollectionIface *iface) {
iface->find_variable = gplate_object_variable_find_variable;
iface->add_variable_with_name = NULL;
+ iface->remove_variable = NULL; + iface->remove_all = NULL; + iface->get_iterator = gplate_object_variable_get_iterator; /******************************************************************************