casa
$Rev:20696$
|
Arbitrary name-value pairs used in the display classes. More...
#include <Attribute.h>
Public Member Functions | |
Attribute (const String &name, const AttributeValueBase &value) | |
Constructor taking an AttributeValueBase. | |
Attribute (const Attribute &other) | |
Copy constructor. | |
Attribute (const String &name, const uInt value, const uInt tolerance=0, const Bool strict=False) | |
Constructors that take a single value. | |
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) | |
Contructors that take a Vector of the various types. | |
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) | |
Constructors that take a pointer to a variable. | |
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) | |
Constructors that take a pointer to a Vector. | |
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 () |
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 . | |
Bool | operator!= (const Attribute &other) const |
The opposite of the Attribute matching. | |
virtual void | operator+= (const Attribute &other) |
Attribute addition ... | |
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; <note role="caution"> 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. | |
String | getName () const |
Return the name of the Attribute. | |
AttValue::ValueType | getType () const |
Return the DataType of the value of the Attribute. | |
Private Member Functions | |
Attribute () | |
(Required) default constructor. | |
virtual const Attribute & | operator= (const Attribute &other) |
Copy assignment; Caution: This allows the type of the AttributeValue to change, so it is private; | |
Private Attributes | |
String | itsAttributeName |
The name of the Attribute. | |
AttributeValueBase * | itsAttributeValue |
Pointer to the attribute base class. |
Arbitrary name-value pairs used in the display classes.
Public interface
An Attribute characterises something by associating a value with a name.
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.
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 { ..\. }
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.
setValue
function. Definition at line 140 of file Attribute.h.
casa::Attribute::Attribute | ( | const String & | name, |
const AttributeValueBase & | value | ||
) |
Constructor taking an AttributeValueBase.
By inheriting from AttributeValueBase, additional types of Attributes can be supported.
casa::Attribute::Attribute | ( | const Attribute & | other | ) |
Copy constructor.
casa::Attribute::Attribute | ( | const String & | name, |
const uInt | value, | ||
const uInt | tolerance = 0 , |
||
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.
casa::Attribute::Attribute | ( | const String & | name, |
const Int | value, | ||
const Int | tolerance = 0 , |
||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
const Float | value, | ||
const Float | tolerance = 0.0 , |
||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
const Double | value, | ||
const Double | tolerance = 0.0 , |
||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
const Quantity | value, | ||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
const Quantity | value, | ||
const Quantity | tolerance, | ||
Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
const Bool | value, | ||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
const String | value, | ||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
const Vector< Int > | value, | ||
const Int | tolerance = 0 , |
||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
const Vector< Float > | value, | ||
const Float | tolerance = 0.0 , |
||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
const Vector< Double > | value, | ||
const Double | tolerance = 0.0 , |
||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
const Vector< Quantity > | value, | ||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
const Vector< Quantity > | value, | ||
const Quantity | tolerance, | ||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
const Vector< Bool > | value, | ||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
const Vector< String > | value, | ||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
Int * | value, | ||
const Int | tolerance = 0 , |
||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
Float * | value, | ||
const Float | tolerance = 0.0 , |
||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
Double * | value, | ||
const Double | tolerance = 0.0 , |
||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
Bool * | value, | ||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
String * | value, | ||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
Quantity * | value, | ||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
Quantity * | value, | ||
const Quantity | tolerance, | ||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
Vector< Int > * | value, | ||
const Int | tolerance = 0 , |
||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
Vector< Float > * | value, | ||
const Float | tolerance = 0.0 , |
||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
Vector< Double > * | value, | ||
const Double | tolerance = 0.0 , |
||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
Vector< Quantity > * | value, | ||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
Vector< Quantity > * | value, | ||
const Quantity | tolerance, | ||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
Vector< Bool > * | value, | ||
const Bool | strict = False |
||
) |
casa::Attribute::Attribute | ( | const String & | name, |
Vector< String > * | value, | ||
const Bool | strict = False |
||
) |
virtual casa::Attribute::~Attribute | ( | ) | [virtual] |
Destructor.
casa::Attribute::Attribute | ( | ) | [private] |
(Required) default constructor.
virtual Attribute* casa::Attribute::clone | ( | ) | const [virtual] |
Create a new copy of the Attribute and return a pointer to the copy (virtual constructor).
Returns a pointer to the AttributeValue base class object.
You must cast it to AttributeValue<T> and invoke function getValue
to get the value of the attribute
String casa::Attribute::getName | ( | ) | const |
Return the name of the Attribute.
AttValue::ValueType casa::Attribute::getType | ( | ) | const |
Return the DataType of the value of the Attribute.
The opposite of the Attribute matching.
virtual void casa::Attribute::operator+= | ( | const Attribute & | other | ) | [virtual] |
Attribute addition ...
add the value of other
to the value of *this
.
Copy assignment;
Caution: This allows the type of the AttributeValue to change, so it is private;
Attribute matching: returns True
if *this
and other
match, otherwise returns False
.
Caution: 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;
virtual void casa::Attribute::setValue | ( | const Attribute & | other | ) | [virtual] |
Set the value of this Attribute to that of the other
Attribute, if, and only if, they have the same value type; <note role="caution"> 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;
String casa::Attribute::itsAttributeName [private] |
The name of the Attribute.
Definition at line 306 of file Attribute.h.
Pointer to the attribute base class.
Definition at line 309 of file Attribute.h.