AttVal.h

Classes

AttributeValue -- Type-dependent interface for values of Attributes. (full description)

template <class T> class AttributeValue : public AttributeValueBase

Interface

Public Members
AttributeValue(const T &value, const Bool strict)
AttributeValue(const Vector<T> &value, const Bool strict)
virtual ~AttributeValue()
AttributeValue(const AttributeValue<T> &other)
const AttributeValue<T>& operator=(const AttributeValue<T> &other)
virtual void setValue(const T &value)
virtual void setValue(const Vector<T> &value)
virtual Vector<T> getValue() const
virtual AttributeValueBase* clone() const
virtual void operator+=(const AttributeValueBase& other)
virtual String className() const
virtual void print(ostream& os)
Protected Members
virtual Bool matches(const AttributeValueBase& other) const
const AttributeValue<T>& myCast (const AttributeValueBase& other) const
Private Members
void setType()
Bool myMatch(const AttributeValue<T>& other) const
AttributeValue()

Description

Review Status

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

Prerequisite

Etymology

An AttributeValue stores the value of an Attribute

Synopsis

An Attribute in the Display Library has a name and a value. In order to facilite easy use of Attributes in user code, the value of an Attribute has to be wrapped in a templated class, the AttributeValue, which itself is derived from a non-templated base class, AttributeValueBase . What is stored in the AttributeValue is a value and the type of that value. Only some types are supported; see AttributeValueBase for a list. The value is always stored as a Vector, even if the value used in the constructor is a single value. The operation needed for the AttributeValue is to be able to check whether it matches another AttributeValue. For two AttributeValues to match they must have the same value and be of the same type (with some tolerance, see below). AttributeValues of different types (through the base class AttributeValueBase), never match.

The parameter strict in some constructors defines whether matching has to be done for each element ( strict == True ), or whether AttributeValues match if any one element of one Vector is equal to any other element of the other Vector. An AttributeValue created with a scalar type can match an AttributeValue created with a Vector of that scalar type.

Example

A few simple examples of the use of the AttributeValue class follow.
    AttributeValue<Int> intAtt1(3, False);
    AttributeValue<Int> intAtt2(3, False);
    AttributeValue<Int> intAtt3(2, False);
    

At this point, intAtt1==intAtt2 will return True, and intAtt1==intAtt3 will return False.

    Vector<Int> vec(2);
    vec(0) = 1;
    vec(1) = 3;
    AttributeValue<Vector<Int> > vecAtt1(vec, False);
    

and now vecAtt1==intAtt1 is True, and vecAtt1==intAtt3 returns False.

Finally,

    AttributeValue<Vector<Int> > vecAtt2(vec, True);
    

gives False for vecAtt2==intAtt1, since they cannot match element wise because they have different lengths, and similarly vecAtt2==intAtt2 is also False.

Motivation

and Attribute .

To Do

Member Description

AttributeValue(const T &value, const Bool strict)

Construct from a scalar value. The parameter strict defines whether whether matching has to be done for each element (strict == True) (a scalar value AttributeValue is considered a Vector of length one), or whether AttributeValues match if any one element of one Vector is equal to any other element of the other Vector (strict == False).

AttributeValue(const Vector<T> &value, const Bool strict)

Construct from a Vector. The parameter strict defines whether whether matching has to be done for each element (strict == True), or whether AttributeValues match if any one element of one Vector is equal to any other element of the other Vector (strict == False).

virtual ~AttributeValue()

Destructor.

AttributeValue(const AttributeValue<T> &other)

Copy constructor.

const AttributeValue<T>& operator=(const AttributeValue<T> &other)

Assignment (copy semantics)

virtual void setValue(const T &value)
virtual void setValue(const Vector<T> &value)
virtual Vector<T> getValue() const

Set/get the value of the AttributeValue.

virtual AttributeValueBase* clone() const

Returns a new copy of the AttributeValue

virtual void operator+=(const AttributeValueBase& other)

Add other to *this.

virtual String className() const

Return class name

virtual void print(ostream& os)

virtual Bool matches(const AttributeValueBase& other) const

Implements when the values of two Attributes match or not. The state of strict determines whether whether matching has to be done for each element ( strict == True ), or whether AttributeValues match if any one element of one Vector is equal to any other element of the other Vector.

const AttributeValue<T>& myCast (const AttributeValueBase& other) const

Cast from Base class

void setType()

Sett T type in base class

Bool myMatch(const AttributeValue<T>& other) const

Do actual matching

AttributeValue()

Default constructor