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
20 * Jürg Billeter <j@bitron.ch>
26 * Represents an attribute specified in the source code.
28 public class Vala
.Attribute
: CodeNode
{
30 * The name of the attribute type.
32 public string name
{ get; set; }
35 * Contains all specified attribute arguments.
37 public Vala
.Map
<string,string> args
= new HashMap
<string,string> (str_hash
, str_equal
);
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) {
48 this
.source_reference
= source_reference
;
52 * Adds an attribute argument.
54 * @param arg named argument
56 public void add_argument (string key
, string value
) {
57 args
.set (key
, value
);
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
);
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
);
84 var noquotes
= value
.substring (1, (uint) (value
.length
- 2));
86 return noquotes
.compress ();
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
);
102 return value
.to_int ();
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
);
118 return value
.to_double ();
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 (args
.get (name
) == "true");