Attributes can be compared to see if they match. They can also be made "fuzzy" by providing a user-specified tolerance, and then matching means abs(val1-val2) <= tol. An Attribute can also be "strict" if required: if so, then Attributes with Vector values are deemed to match if their values match element-wise. Otherwise, the Attributes match if any one element in one Attribute's value matches any one element in the other Attribute's value. In the latter case, the Attribute Vector values do not have to be conformant.
Attribute att("axisname", "Right ascension (J2000)"); ... AttributeValue<String>* pAv = dynamic_cast<AttributeValue<String>*>(att.getAttributeValue()); String axisname = pAv->getValue()(0); if (axisname == "Right ascension (J2000)") { ... } else { throw(AipsError("Doing nothing because axisname Attribute unsuitable")); }
The following example uses the Attribute equality operator to determine some state.
/* "itsAxisName" is some private String */ Attribute att("axisname", itsAxisName); ... Attribute currentAtt("axisname", "Stokes"); if (currentAtt == att) { ... } else { ... }
A more complete example, exhibiting the Attribute interface to a
specific display class, the
Copy constructor.
Constructors that take a single value. The value stored in an
Attribute can be made fuzzy by giving some tolerance
tol, and when the values can be compared to see if
they match, the tolerance is taken into account where it makes
sense. The parameter strict determines how the
matching is done for the values. If strict == True,
the values have to match elementwise (a single value is
considered a Vector of length 1). If strict == False,
the values match if any one element in one value matches any one
elemnt in the other value.
Contructors that take a Vector of the various
types. Once again, the value stored in an Attribute can be made
fuzzy by specifying tol or strict by putting
strict = True.
Constructors that take a pointer to a variable. This makes the
Attribute an alias for the variable, changing the variable
changes the value of the Attribute and vice versa. Other
functionality the same as for the other constructors.
Constructors that take a pointer to a Vector. This again makes
the Attribute an alias for the Vector: changing the Vector
changes the value of the Attribute, and vice versa. Other
functionality is the same as for the non-aliasing constructors.
Destructor.
Create a new copy of the Attribute and return a pointer to the
copy (virtual constructor).
Attribute matching: returns True if *this
and other match, otherwise returns False.
The opposite of the Attribute matching.
Attribute addition ... add the value of other to
the value of *this.
Set the value of this Attribute to that of the other
Attribute, if, and only if, they have the same value type.
Returns a pointer to the AttributeValue base class object. You must cast
it to AttributeValue
Return the name of the Attribute.
Return the DataType of the value of the Attribute.
(Required) default constructor.
Copy assignment.
/* assume we are working on a WorldCanvas "wcanvas" */
/* at some point, an Attribute has been set elsewhere like this:
wcanvas.setAttribute("ColorModel", "RGB");
*/
...
/* somewhere later in the program ... */
if (wcanvas.existsAttribute("ColorModel")) {
String colormodel;
wcanvas.getAttribute("ColorModel", colormodel);
if (colormodel == "RGB") {
...
} else {
...
}
} else {
...
}
Motivation
The main motivation for introducing Attributes is to be able to
attach arbitrary name-value pairs to various objects in the display
classes. This allows the storage, retrieval and comparison of
arbitrary information from the various display objects.
To Do
Member Description
Attribute(const String &name, const AttributeValueBase& value)
Constructor taking an AttributeValueBase. By inheriting from
AttributeValueBase, additional types of Attributes can be
supported.
Attribute(const Attribute& other)
Attribute(const String &name, const uInt value, const uInt tolerance = 0, const Bool strict = False)
Attribute(const String &name, const Int value, const Int tolerance = 0, const Bool strict = False)
Attribute(const String &name, const Float value, const Float tolerance = 0.0, const Bool strict = False)
Attribute(const String &name, const Double value, const Double tolerance = 0.0, const Bool strict = False)
Attribute(const String &name, const Quantity value, const Bool strict = False)
Attribute(const String &name, const Quantity value, const Quantity tolerance, Bool strict = False)
Attribute(const String &name, const Bool value, const Bool strict = False)
Attribute(const String &name, const String value, const Bool strict = False)
Attribute(const String &name, const Vector<uInt> value, const uInt tolerance = 0, const Bool strict = False)
Attribute(const String &name, const Vector<Int> value, const Int tolerance = 0, const Bool strict = False)
Attribute(const String &name, const Vector<Float> value, const Float tolerance = 0.0, const Bool strict = False)
Attribute(const String &name, const Vector<Double> value, const Double tolerance = 0.0, const Bool strict = False)
Attribute(const String &name, const Vector<Quantity> value, const Bool strict = False)
Attribute(const String &name, const Vector<Quantity> value, const Quantity tolerance, const Bool strict = False)
Attribute(const String &name, const Vector<Bool> value, const Bool strict = False)
Attribute(const String &name, const Vector<String> value, const Bool strict = False)
Attribute(const String &name, uInt *value, const uInt tolerance = 0, const Bool strict = False)
Attribute(const String &name, Int *value, const Int tolerance = 0, const Bool strict = False)
Attribute(const String &name, Float *value, const Float tolerance = 0.0, const Bool strict = False)
Attribute(const String &name, Double *value, const Double tolerance = 0.0, const Bool strict = False)
Attribute(const String &name, Bool *value, const Bool strict = False)
Attribute(const String &name, String *value, const Bool strict = False)
Attribute(const String &name, Quantity *value, const Bool strict = False)
Attribute(const String &name, Quantity *value, const Quantity tolerance, const Bool strict = False)
Attribute(const String &name, Vector<uInt> *value, const uInt tolerance = 0, const Bool strict = False)
Attribute(const String &name, Vector<Int> *value, const Int tolerance = 0, const Bool strict = False)
Attribute(const String &name, Vector<Float> *value, const Float tolerance = 0.0, const Bool strict = False)
Attribute(const String &name, Vector<Double> *value, const Double tolerance = 0.0, const Bool strict = False)
Attribute(const String &name, Vector<Quantity> *value, const Bool strict = False)
Attribute(const String &name, Vector<Quantity> *value, const Quantity tolerance, const Bool strict = False)
Attribute(const String &name, Vector<Bool> *value, const Bool strict = False)
Attribute(const String &name, Vector<String> *value, const Bool strict = False)
virtual ~Attribute()
virtual Attribute* clone() const
virtual Bool operator==(const Attribute &other) const
Two Attributes match if their names are
different. If two Attributes have the same name, but the values
stored in the Attributes have different types, they do not match.
An Attribute of a single value and an Attribute of a Vector of
values of the same type are considered to have the same type, so
under certain circumstances (based on the strictness of the
Attributes) two such Attributes may match.
Bool operator!=(const Attribute &other) const
virtual void operator+=(const Attribute &other)
virtual void setValue(const Attribute &other)
AttributeValueBase* getAttributeValue() const
String getName() const
AttValue::ValueType getType() const
Attribute()
virtual const Attribute &operator=(const Attribute &other)
This allows the type of the
AttributeValue to change, so it is private.