* @param name attribute name
* @return attribute
*/
- public Attribute? get_attribute (string name) {
+ public unowned Attribute? get_attribute (string name) {
// FIXME: use hash table
- foreach (Attribute a in attributes) {
+ foreach (unowned Attribute a in attributes) {
if (a.name == name) {
return a;
}
return null;
}
+ unowned Attribute get_or_create_attribute (string name) {
+ unowned Attribute? a = get_attribute (name);
+ if (a == null) {
+ var new_a = new Attribute (name, source_reference);
+ attributes.append (new_a);
+ a = new_a;
+ }
+ return (!) a;
+ }
+
/**
* Returns true if the specified attribute argument is set.
*
* @return true if the attribute has the given argument
*/
public bool has_attribute_argument (string attribute, string argument) {
- var a = get_attribute (attribute);
+ unowned Attribute? a = get_attribute (attribute);
if (a == null) {
return false;
}
* @param value true to add the attribute, false to remove it
*/
public void set_attribute (string name, bool value, SourceReference? source_reference = null) {
- var a = get_attribute (name);
+ unowned Attribute? a = get_attribute (name);
if (value && a == null) {
attributes.append (new Attribute (name, source_reference));
} else if (!value && a != null) {
* @param argument argument name
*/
public void remove_attribute_argument (string attribute, string argument) {
- var a = get_attribute (attribute);
+ unowned Attribute? a = get_attribute (attribute);
if (a != null) {
a.args.remove (argument);
if (a.args.size == 0) {
* @return string value
*/
public string? get_attribute_string (string attribute, string argument, string? default_value = null) {
- var a = get_attribute (attribute);
+ unowned Attribute? a = get_attribute (attribute);
if (a == null) {
return default_value;
}
* @return integer value
*/
public int get_attribute_integer (string attribute, string argument, int default_value = 0) {
- var a = get_attribute (attribute);
+ unowned Attribute? a = get_attribute (attribute);
if (a == null) {
return default_value;
}
if (attributes == null) {
return default_value;
}
- var a = get_attribute (attribute);
+ unowned Attribute? a = get_attribute (attribute);
if (a == null) {
return default_value;
}
if (attributes == null) {
return default_value;
}
- var a = get_attribute (attribute);
+ unowned Attribute? a = get_attribute (attribute);
if (a == null) {
return default_value;
}
return;
}
- var a = get_attribute (attribute);
- if (a == null) {
- a = new Attribute (attribute, source_reference);
- attributes.append (a);
- }
+ unowned Attribute a = get_or_create_attribute (attribute);
a.add_argument (argument, "\"%s\"".printf (value));
}
* @param value integer value
*/
public void set_attribute_integer (string attribute, string argument, int value, SourceReference? source_reference = null) {
- var a = get_attribute (attribute);
- if (a == null) {
- a = new Attribute (attribute, source_reference);
- attributes.append (a);
- }
+ unowned Attribute a = get_or_create_attribute (attribute);
a.add_argument (argument, value.to_string ());
}
* @param value double value
*/
public void set_attribute_double (string attribute, string argument, double value, SourceReference? source_reference = null) {
- var a = get_attribute (attribute);
- if (a == null) {
- a = new Attribute (attribute, source_reference);
- attributes.append (a);
- }
+ unowned Attribute a = get_or_create_attribute (attribute);
a.add_argument (argument, value.format (new char[double.DTOSTR_BUF_SIZE]));
}
* @param value bool value
*/
public void set_attribute_bool (string attribute, string argument, bool value, SourceReference? source_reference = null) {
- var a = get_attribute (attribute);
- if (a == null) {
- a = new Attribute (attribute, source_reference);
- attributes.append (a);
- }
+ unowned Attribute a = get_or_create_attribute (attribute);
a.add_argument (argument, value.to_string ());
}
* @param index attribute cache index
* @return attribute cache
*/
- public AttributeCache? get_attribute_cache (int index) {
+ public unowned AttributeCache? get_attribute_cache (int index) {
if (index >= attributes_cache.length) {
return null;
}