Attribute.h

Classes

Attribute -- Arbitrary name-value pairs used in the display classes. (full description)

class Attribute

Interface

Public Members
Attribute(const String &name, const AttributeValueBase& value)
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
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
Private Members
Attribute()
virtual const Attribute &operator=(const Attribute &other)

Description

Review Status

Date Reviewed:
yyyy/mm/dd
Programs:
Tests:

Prerequisite

Etymology

An Attribute characterises something by associating a value with a name.

Synopsis

An Attribute is the combination of a name and a value. The name is a String, while the value can be of any of the types Int, Float, Double, Bool, String or Quantum, or a Vector of any of these types.

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.

Example

The following example shows the construction and retrieval of an Attribute.
    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 WorldCanvas, follows.

    /* 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)

Copy constructor.

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)

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.

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)

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.

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)

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.

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)

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.

virtual ~Attribute()

Destructor.

virtual Attribute* clone() const

Create a new copy of the Attribute and return a pointer to the copy (virtual constructor).

virtual Bool operator==(const Attribute &other) const

Attribute matching: returns True if *this and other match, otherwise returns False.

CautionTwo 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

The opposite of the Attribute matching.

virtual void operator+=(const Attribute &other)

Attribute addition ... add the value of other to the value of *this.

virtual void setValue(const Attribute &other)

Set the value of this Attribute to that of the other Attribute, if, and only if, they have the same value type. This method makes an important assumption, namely that all AttributeValues that return AttValue::AtInt, AttValue::AtFloat or AttValue::AtDouble are derived from AttributeValueTol and that return AttValue::AtBool, AttValue::AtString or AttValue::AtQuantity are derived from AttributeValue (ie they are like they are created by Attribute). This is ok for *this, but there is no guarantee that it is correct for other. This assumption was not needed until the AttributeValuePoi class was written. AttributeValues were not supposed to change but were supposed to be replaced. Now this is very ugly and should be rewritten. Indeed, it fails now for Quantities, since both with and without tols are used at the moment.

AttributeValueBase* getAttributeValue() const

Returns a pointer to the AttributeValue base class object. You must cast it to AttributeValue and invoke function getValue to get the value of the attribute

String getName() const

Return the name of the Attribute.

AttValue::ValueType getType() const

Return the DataType of the value of the Attribute.

Attribute()

(Required) default constructor.

virtual const Attribute &operator=(const Attribute &other)

Copy assignment.

CautionThis allows the type of the AttributeValue to change, so it is private.