codegen: Add get_field_cvalue and load_field
[vala-lang.git] / vala / valaattribute.vala
blob68d753910f800959a0ff08c294b6fa9025f9c055
1 /* valaattribute.vala
3 * Copyright (C) 2006-2008 Jürg Billeter
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 using GLib;
25 /**
26 * Represents an attribute specified in the source code.
28 public class Vala.Attribute : CodeNode {
29 /**
30 * The name of the attribute type.
32 public string name { get; set; }
34 /**
35 * Contains all specified attribute arguments.
37 public Vala.Map<string,string> args = new HashMap<string,string> (str_hash, str_equal);
39 /**
40 * Creates a new attribute.
42 * @param name attribute type name
43 * @param source_reference reference to source code
44 * @return newly created attribute
46 public Attribute (string name, SourceReference? source_reference = null) {
47 this.name = name;
48 this.source_reference = source_reference;
51 /**
52 * Adds an attribute argument.
54 * @param arg named argument
56 public void add_argument (string key, string value) {
57 args.set (key, value);
60 /**
61 * Returns whether this attribute has the specified named argument.
63 * @param name argument name
64 * @return true if the argument has been found, false otherwise
66 public bool has_argument (string name) {
67 return args.contains (name);
70 /**
71 * Returns the string value of the specified named argument.
73 * @param name argument name
74 * @return string value
76 public string? get_string (string name) {
77 string value = args.get (name);
79 if (value == null) {
80 return null;
83 /* remove quotes */
84 var noquotes = value.substring (1, (uint) (value.length - 2));
85 /* unescape string */
86 return noquotes.compress ();
89 /**
90 * Returns the integer value of the specified named argument.
92 * @param name argument name
93 * @return integer value
95 public int get_integer (string name) {
96 string value = args.get (name);
98 if (value == null) {
99 return 0;
102 return int.parse (value);
106 * Returns the double value of the specified named argument.
108 * @param name argument name
109 * @return double value
111 public double get_double (string name) {
112 string value = args.get (name);
114 if (value == null) {
115 return 0;
118 return double.parse (value);
122 * Returns the boolean value of the specified named argument.
124 * @param name argument name
125 * @return boolean value
127 public bool get_bool (string name) {
128 return bool.parse (args.get (name));