Logo Search packages:      
Sourcecode: vala version File versions

valaattribute.c

/* valaattribute.vala
 *
 * Copyright (C) 2006-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 "valaattribute.h"
#include <gee/arraylist.h>
#include <gee/collection.h>
#include <vala/valasourcereference.h>
#include <vala/valaattribute.h>
#include <vala/valanamedargument.h>
#include <vala/valaliteralexpression.h>
#include <vala/valaliteral.h>
#include <vala/valastringliteral.h>
#include <vala/valaintegerliteral.h>
#include <vala/valabooleanliteral.h>

struct _ValaAttributePrivate {
      char* _name;
};
#define VALA_ATTRIBUTE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VALA_TYPE_ATTRIBUTE, ValaAttributePrivate))
enum  {
      VALA_ATTRIBUTE_DUMMY_PROPERTY,
      VALA_ATTRIBUTE_NAME
};
static gpointer vala_attribute_parent_class = NULL;
static void vala_attribute_dispose (GObject * obj);


/**
 * Creates a new attribute.
 *
 * @param name             attribute type name
 * @param source_reference reference to source code
 * @return                 newly created attribute
 */
ValaAttribute* vala_attribute_new (const char* name, ValaSourceReference* source_reference)
{
      ValaAttribute * self;
      g_return_val_if_fail (name != NULL, NULL);
      g_return_val_if_fail (source_reference == NULL || VALA_IS_SOURCE_REFERENCE (source_reference), NULL);
      self = g_object_newv (VALA_TYPE_ATTRIBUTE, 0, NULL);
      vala_attribute_set_name (self, name);
      vala_code_node_set_source_reference (VALA_CODE_NODE (self), source_reference);
      return self;
}


/**
 * Adds an attribute argument.
 *
 * @param arg named argument
 */
void vala_attribute_add_argument (ValaAttribute* self, ValaNamedArgument* arg)
{
      g_return_if_fail (VALA_IS_ATTRIBUTE (self));
      g_return_if_fail (VALA_IS_NAMED_ARGUMENT (arg));
      gee_collection_add (GEE_COLLECTION (self->args), arg);
}


/**
 * Returns whether this attribute has the specified named argument.
 *
 * @param name argument name
 * @return     true if the argument has been found, false otherwise
 */
gboolean vala_attribute_has_argument (ValaAttribute* self, const char* name)
{
      g_return_val_if_fail (VALA_IS_ATTRIBUTE (self), FALSE);
      g_return_val_if_fail (name != NULL, FALSE);
      {
            GeeList* arg_collection;
            GeeIterator* arg_it;
            arg_collection = self->args;
            arg_it = gee_iterable_iterator (GEE_ITERABLE (arg_collection));
            while (gee_iterator_next (arg_it)) {
                  ValaNamedArgument* arg;
                  arg = gee_iterator_get (arg_it);
                  {
                        /* FIXME: use hash table*/
                        if (g_utf8_collate (vala_named_argument_get_name (arg), name) == 0) {
                              gboolean __temp0;
                              return (__temp0 = TRUE, (arg == NULL ? NULL : (arg = (g_object_unref (arg), NULL))), (arg_it == NULL ? NULL : (arg_it = (g_object_unref (arg_it), NULL))), __temp0);
                        }
                        (arg == NULL ? NULL : (arg = (g_object_unref (arg), NULL)));
                  }
            }
            (arg_it == NULL ? NULL : (arg_it = (g_object_unref (arg_it), NULL)));
      }
      return FALSE;
}


/**
 * Returns the string value of the specified named argument.
 *
 * @param name argument name
 * @return     string value
 */
char* vala_attribute_get_string (ValaAttribute* self, const char* name)
{
      g_return_val_if_fail (VALA_IS_ATTRIBUTE (self), NULL);
      g_return_val_if_fail (name != NULL, NULL);
      {
            GeeList* arg_collection;
            GeeIterator* arg_it;
            arg_collection = self->args;
            arg_it = gee_iterable_iterator (GEE_ITERABLE (arg_collection));
            while (gee_iterator_next (arg_it)) {
                  ValaNamedArgument* arg;
                  arg = gee_iterator_get (arg_it);
                  {
                        /* FIXME: use hash table*/
                        if (g_utf8_collate (vala_named_argument_get_name (arg), name) == 0) {
                              if (VALA_IS_LITERAL_EXPRESSION (vala_named_argument_get_argument (arg))) {
                                    ValaLiteral* __temp2;
                                    ValaLiteral* lit;
                                    __temp2 = NULL;
                                    lit = (__temp2 = vala_literal_expression_get_literal ((VALA_LITERAL_EXPRESSION (vala_named_argument_get_argument (arg)))), (__temp2 == NULL ? NULL : g_object_ref (__temp2)));
                                    if (VALA_IS_STRING_LITERAL (lit)) {
                                          char* __temp3;
                                          __temp3 = NULL;
                                          return (__temp3 = vala_string_literal_eval ((VALA_STRING_LITERAL (lit))), (lit == NULL ? NULL : (lit = (g_object_unref (lit), NULL))), (arg == NULL ? NULL : (arg = (g_object_unref (arg), NULL))), (arg_it == NULL ? NULL : (arg_it = (g_object_unref (arg_it), NULL))), __temp3);
                                    }
                                    (lit == NULL ? NULL : (lit = (g_object_unref (lit), NULL)));
                              }
                        }
                        (arg == NULL ? NULL : (arg = (g_object_unref (arg), NULL)));
                  }
            }
            (arg_it == NULL ? NULL : (arg_it = (g_object_unref (arg_it), NULL)));
      }
      return NULL;
}


/**
 * Returns the integer value of the specified named argument.
 *
 * @param name argument name
 * @return     integer value
 */
gint vala_attribute_get_integer (ValaAttribute* self, const char* name)
{
      g_return_val_if_fail (VALA_IS_ATTRIBUTE (self), 0);
      g_return_val_if_fail (name != NULL, 0);
      {
            GeeList* arg_collection;
            GeeIterator* arg_it;
            arg_collection = self->args;
            arg_it = gee_iterable_iterator (GEE_ITERABLE (arg_collection));
            while (gee_iterator_next (arg_it)) {
                  ValaNamedArgument* arg;
                  arg = gee_iterator_get (arg_it);
                  {
                        /* FIXME: use hash table*/
                        if (g_utf8_collate (vala_named_argument_get_name (arg), name) == 0) {
                              if (VALA_IS_LITERAL_EXPRESSION (vala_named_argument_get_argument (arg))) {
                                    ValaLiteral* __temp5;
                                    ValaLiteral* lit;
                                    __temp5 = NULL;
                                    lit = (__temp5 = vala_literal_expression_get_literal ((VALA_LITERAL_EXPRESSION (vala_named_argument_get_argument (arg)))), (__temp5 == NULL ? NULL : g_object_ref (__temp5)));
                                    if (VALA_IS_INTEGER_LITERAL (lit)) {
                                          gint __temp6;
                                          return (__temp6 = atoi (vala_integer_literal_get_value ((VALA_INTEGER_LITERAL (lit)))), (lit == NULL ? NULL : (lit = (g_object_unref (lit), NULL))), (arg == NULL ? NULL : (arg = (g_object_unref (arg), NULL))), (arg_it == NULL ? NULL : (arg_it = (g_object_unref (arg_it), NULL))), __temp6);
                                    }
                                    (lit == NULL ? NULL : (lit = (g_object_unref (lit), NULL)));
                              }
                        }
                        (arg == NULL ? NULL : (arg = (g_object_unref (arg), NULL)));
                  }
            }
            (arg_it == NULL ? NULL : (arg_it = (g_object_unref (arg_it), NULL)));
      }
      return 0;
}


/**
 * Returns the boolean value of the specified named argument.
 *
 * @param name argument name
 * @return     boolean value
 */
gboolean vala_attribute_get_bool (ValaAttribute* self, const char* name)
{
      g_return_val_if_fail (VALA_IS_ATTRIBUTE (self), FALSE);
      g_return_val_if_fail (name != NULL, FALSE);
      {
            GeeList* arg_collection;
            GeeIterator* arg_it;
            arg_collection = self->args;
            arg_it = gee_iterable_iterator (GEE_ITERABLE (arg_collection));
            while (gee_iterator_next (arg_it)) {
                  ValaNamedArgument* arg;
                  arg = gee_iterator_get (arg_it);
                  {
                        /* FIXME: use hash table*/
                        if (g_utf8_collate (vala_named_argument_get_name (arg), name) == 0) {
                              if (VALA_IS_LITERAL_EXPRESSION (vala_named_argument_get_argument (arg))) {
                                    ValaLiteral* __temp8;
                                    ValaLiteral* lit;
                                    __temp8 = NULL;
                                    lit = (__temp8 = vala_literal_expression_get_literal ((VALA_LITERAL_EXPRESSION (vala_named_argument_get_argument (arg)))), (__temp8 == NULL ? NULL : g_object_ref (__temp8)));
                                    if (VALA_IS_BOOLEAN_LITERAL (lit)) {
                                          gboolean __temp9;
                                          return (__temp9 = vala_boolean_literal_get_value ((VALA_BOOLEAN_LITERAL (lit))), (lit == NULL ? NULL : (lit = (g_object_unref (lit), NULL))), (arg == NULL ? NULL : (arg = (g_object_unref (arg), NULL))), (arg_it == NULL ? NULL : (arg_it = (g_object_unref (arg_it), NULL))), __temp9);
                                    }
                                    (lit == NULL ? NULL : (lit = (g_object_unref (lit), NULL)));
                              }
                        }
                        (arg == NULL ? NULL : (arg = (g_object_unref (arg), NULL)));
                  }
            }
            (arg_it == NULL ? NULL : (arg_it = (g_object_unref (arg_it), NULL)));
      }
      return FALSE;
}


char* vala_attribute_get_name (ValaAttribute* self)
{
      g_return_val_if_fail (VALA_IS_ATTRIBUTE (self), NULL);
      return self->priv->_name;
}


void vala_attribute_set_name (ValaAttribute* self, const char* value)
{
      char* __temp12;
      g_return_if_fail (VALA_IS_ATTRIBUTE (self));
      __temp12 = NULL;
      self->priv->_name = (__temp12 = g_strdup (value), (self->priv->_name = (g_free (self->priv->_name), NULL)), __temp12);
}


static void vala_attribute_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec)
{
      ValaAttribute * self;
      self = VALA_ATTRIBUTE (object);
      switch (property_id) {
            case VALA_ATTRIBUTE_NAME:
            g_value_set_string (value, vala_attribute_get_name (self));
            break;
      }
}


static void vala_attribute_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec)
{
      ValaAttribute * self;
      self = VALA_ATTRIBUTE (object);
      switch (property_id) {
            case VALA_ATTRIBUTE_NAME:
            vala_attribute_set_name (self, g_value_get_string (value));
            break;
      }
}


static void vala_attribute_class_init (ValaAttributeClass * klass)
{
      vala_attribute_parent_class = g_type_class_peek_parent (klass);
      g_type_class_add_private (klass, sizeof (ValaAttributePrivate));
      G_OBJECT_CLASS (klass)->get_property = vala_attribute_get_property;
      G_OBJECT_CLASS (klass)->set_property = vala_attribute_set_property;
      G_OBJECT_CLASS (klass)->dispose = vala_attribute_dispose;
      g_object_class_install_property (G_OBJECT_CLASS (klass), VALA_ATTRIBUTE_NAME, g_param_spec_string ("name", "foo", "bar", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
}


static void vala_attribute_init (ValaAttribute * self)
{
      self->priv = VALA_ATTRIBUTE_GET_PRIVATE (self);
      self->args = GEE_LIST (gee_array_list_new (g_object_ref, g_object_unref, g_direct_equal));
}


static void vala_attribute_dispose (GObject * obj)
{
      ValaAttribute * self;
      ValaAttributeClass * klass;
      GObjectClass * parent_class;
      self = VALA_ATTRIBUTE (obj);
      (self->priv->_name = (g_free (self->priv->_name), NULL));
      (self->args == NULL ? NULL : (self->args = (g_object_unref (self->args), NULL)));
      klass = VALA_ATTRIBUTE_CLASS (g_type_class_peek (VALA_TYPE_ATTRIBUTE));
      parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
      parent_class->dispose (obj);
}


GType vala_attribute_get_type (void)
{
      static GType vala_attribute_type_id = 0;
      if (G_UNLIKELY (vala_attribute_type_id == 0)) {
            static const GTypeInfo g_define_type_info = { sizeof (ValaAttributeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_attribute_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaAttribute), 0, (GInstanceInitFunc) vala_attribute_init };
            vala_attribute_type_id = g_type_register_static (VALA_TYPE_CODE_NODE, "ValaAttribute", &g_define_type_info, 0);
      }
      return vala_attribute_type_id;
}





Generated by  Doxygen 1.6.0   Back to index