casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AttVal.h
Go to the documentation of this file.
1 //# AttVal.h: type-dependent interface for values of Attributes
2 //# Copyright (C) 1996,1997,1999,2000,2001,2002
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef TRIALDISPLAY_ATTVAL_H
29 #define TRIALDISPLAY_ATTVAL_H
30 
31 #include <casa/aips.h>
32 #include <casa/Arrays/Vector.h>
34 
35 namespace casa { //# NAMESPACE CASA - BEGIN
36 
37 // <summary>
38 // Type-dependent interface for values of Attributes.
39 // </summary>
40 
41 // <use visibility=export>
42 
43 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tAttribute" demos="">
44 // </reviewed>
45 
46 // <prerequisite>
47 // <li> AttributeValueBase
48 // </prerequisite>
49 
50 // <etymology>
51 // An <em>AttributeValue</em> stores the value of an Attribute
52 // </etymology>
53 
54 // <synopsis>
55 // An Attribute in the Display Library has a name and a value. In
56 // order to facilite easy use of Attributes in user code, the value of
57 // an Attribute has to be wrapped in a templated class, the
58 // AttributeValue, which itself is derived from a non-templated base
59 // class, <linkto class=AttributeValueBase> AttributeValueBase
60 // </linkto>. What is stored in the AttributeValue is a value and the
61 // type of that value. Only some types are supported; see
62 // AttributeValueBase for a list. The value is always stored as a
63 // casacore::Vector, even if the value used in the constructor is a single
64 // value. The operation needed for the AttributeValue is to be able
65 // to check whether it matches another AttributeValue. For two
66 // AttributeValues to match they must have the same value and be of
67 // the same type (with some tolerance, see below). AttributeValues of
68 // different types (through the base class AttributeValueBase), never
69 // match.
70 //
71 // The parameter <src>strict</src> in some constructors defines
72 // whether matching has to be done for each element (<src> strict ==
73 // true </src>), or whether AttributeValues match if any one element
74 // of one casacore::Vector is equal to any other element of the other Vector.
75 // An AttributeValue created with a scalar type can match an
76 // AttributeValue created with a casacore::Vector of that scalar type.
77 // </synopsis>
78 //
79 // <example>
80 // A few simple examples of the use of the AttributeValue class follow.
81 // <srcblock>
82 // AttributeValue<casacore::Int> intAtt1(3, false);
83 // AttributeValue<casacore::Int> intAtt2(3, false);
84 // AttributeValue<casacore::Int> intAtt3(2, false);
85 // </srcblock>
86 //
87 // At this point, <src>intAtt1==intAtt2</src> will return
88 // <src>true</src>, and <src>intAtt1==intAtt3</src> will return
89 // <src>false</src>.
90 //
91 // <srcblock>
92 // casacore::Vector<casacore::Int> vec(2);
93 // vec(0) = 1;
94 // vec(1) = 3;
95 // AttributeValue<casacore::Vector<casacore::Int> > vecAtt1(vec, false);
96 // </srcblock>
97 //
98 // and now <src>vecAtt1==intAtt1</src> is <src>true</src>, and
99 // <src>vecAtt1==intAtt3</src> returns <src>false</src>.
100 //
101 // Finally,
102 // <srcblock>
103 // AttributeValue<casacore::Vector<casacore::Int> > vecAtt2(vec, true);
104 // </srcblock>
105 
106 // gives <src>false</src> for <src>vecAtt2==intAtt1</src>, since
107 // they cannot match element wise because they have different lengths,
108 // and similarly <src>vecAtt2==intAtt2</src> is also <src>false</src>.
109 // </example>
110 
111 // <motivation>
112 // and <linkto class=Attribute> Attribute </linkto>.
113 // </motivation>
114 //
115 // <todo asof="1999/12/09">
116 // Nothing known.
117 // </todo>
118 
119  template <class T> class AttributeValue : public AttributeValueBase {
120 
121  public:
122 
123  // Construct from a scalar value. The parameter <src>strict</src>
124  // defines whether whether matching has to be done for each element
125  // (<src>strict == true</src>) (a scalar value AttributeValue is
126  // considered a casacore::Vector of length one), or whether AttributeValues
127  // match if any one element of one casacore::Vector is equal to any other
128  // element of the other casacore::Vector (<src>strict == false</src>).
129  AttributeValue(const T &value, const casacore::Bool strict);
130 
131  // Construct from a <src>casacore::Vector</src>. The parameter
132  // <src>strict</src> defines whether whether matching has to be done
133  // for each element (<src>strict == true</src>), or whether
134  // AttributeValues match if any one element of one casacore::Vector is equal
135  // to any other element of the other casacore::Vector (<src>strict == false</src>).
136  AttributeValue(const casacore::Vector<T> &value, const casacore::Bool strict);
137 
138  // Destructor.
139  virtual ~AttributeValue();
140 
141  // Copy constructor.
142  AttributeValue(const AttributeValue<T> &other);
143 
144  // Assignment (copy semantics)
145  const AttributeValue<T>& operator=(const AttributeValue<T> &other);
146 
147  // Set/get the value of the AttributeValue.
148  // <group>
149  virtual void setValue(const T &value);
150  virtual void setValue(const casacore::Vector<T> &value);
151  virtual casacore::Vector<T> getValue() const {
152  return itsValue;
153  };
154  // </group>
155 
156  // Returns a new copy of the AttributeValue
157  virtual AttributeValueBase* clone() const;
158 
159  // Add <src>other</src> to <src>*this</src>.
160  virtual void operator+=(const AttributeValueBase& other);
161 
162  // Return class name
163  virtual casacore::String className() const {
164  return casacore::String("AttributeValue");
165  };
166 
167  virtual void print(std::ostream& os) {
168  os<<itsValue;
169  }
170 
171  protected:
172  // Implements when the values of two Attributes match or not. The
173  // state of <src>strict</src> determines whether whether matching
174  // has to be done for each element (<src> strict == true </src>), or
175  // whether AttributeValues match if any one element of one casacore::Vector is
176  // equal to any other element of the other Vector.
177  virtual casacore::Bool matches(const AttributeValueBase& other) const;
178 
179  // Cast from Base class
180  const AttributeValue<T>& myCast (const AttributeValueBase& other) const;
181 
182 
183  private:
184  // The attribute value
186 
187  // Sett T type in base class
188  void setType();
189 
190  // Do actual matching
191  casacore::Bool myMatch(const AttributeValue<T>& other) const;
192 
193  // Default constructor
194  AttributeValue();
195  };
196 
197 } //# NAMESPACE CASA - END
198 
199 #ifndef AIPS_NO_TEMPLATE_SRC
200 #include <display/Display/AttVal.tcc>
201 #endif
202 
203 #endif
A 1-D Specialization of the Array class.
const AttributeValue< T > & myCast(const AttributeValueBase &other) const
Cast from Base class.
virtual void setValue(const T &value)
Set/get the value of the AttributeValue.
virtual casacore::String className() const
Return class name.
Definition: AttVal.h:163
Type-dependent interface for values of Attributes.
Definition: AttVal.h:119
virtual ~AttributeValue()
Destructor.
virtual AttributeValueBase * clone() const
Returns a new copy of the AttributeValue.
virtual casacore::Bool matches(const AttributeValueBase &other) const
Implements when the values of two Attributes match or not.
void setType()
Sett T type in base class.
casacore::Bool myMatch(const AttributeValue< T > &other) const
Do actual matching.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Base class for values of Attributes used in the display classes.
Definition: AttValBase.h:182
casacore::Vector< T > itsValue
The attribute value.
Definition: AttVal.h:185
AttributeValue()
Default constructor.
virtual casacore::Vector< T > getValue() const
Definition: AttVal.h:151
virtual void operator+=(const AttributeValueBase &other)
Add other to *this.
const AttributeValue< T > & operator=(const AttributeValue< T > &other)
Assignment (copy semantics)
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual void print(std::ostream &os)
Definition: AttVal.h:167
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.