casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Attribute.h
Go to the documentation of this file.
1 //# Attribute.h: arbitrary name-value pairs used in the display classes
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_ATTRIBUTE_H
29 #define TRIALDISPLAY_ATTRIBUTE_H
30 
31 #include <casa/aips.h>
33 
34 namespace casacore{
35 
36  class String;
37 }
38 
39 namespace casa { //# NAMESPACE CASA - BEGIN
40 
41 
42 // <summary>
43 // Arbitrary name-value pairs used in the display classes.
44 // </summary>
45 
46 // <use visibility=export>
47 
48 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tAttribute" demos="">
49 // </reviewed>
50 
51 // <prerequisite>
52 // <li> <linkto class="AttributeValueBase">AttributeValueBase</linkto>
53 // <li> <linkto class="AttributeValue">AttributeValue</linkto>
54 // <li> <linkto class="AttributeValueTol">AttributeValueTol</linkto>
55 // </prerequisite>
56 
57 // <etymology>
58 // An Attribute characterises something by associating a value with a
59 // name.
60 // </etymology>
61 
62 // <synopsis>
63 // An Attribute is the combination of a name and a value. The name is
64 // a casacore::String, while the value can be of any of the types casacore::Int, casacore::Float,
65 // casacore::Double, casacore::Bool, casacore::String or <linkto class=casacore::Quantum>Quantum</linkto>,
66 // or a <linkto class=casacore::Vector>Vector</linkto> of any of these types.
67 //
68 // Attributes can be compared to see if they match. They can also be
69 // made "fuzzy" by providing a user-specified tolerance, and then
70 // matching means <src>abs(val1-val2) <= tol</src>. An Attribute can
71 // also be "strict" if required: if so, then Attributes with Vector
72 // values are deemed to match if their values match element-wise.
73 // Otherwise, the Attributes match if any one element in one
74 // Attribute's value matches any one element in the other Attribute's
75 // value. In the latter case, the Attribute casacore::Vector values do not have
76 // to be conformant.
77 // </synopsis>
78 //
79 // <example>
80 // The following example shows the construction and retrieval of an
81 // Attribute.
82 // <srcblock>
83 // Attribute att("axisname", "Right ascension (J2000)");
84 // ...
85 //
86 // AttributeValue<casacore::String>* pAv = dynamic_cast<AttributeValue<casacore::String>*>(att.getAttributeValue());
87 // casacore::String axisname = pAv->getValue()(0);
88 // if (axisname == "Right ascension (J2000)") {
89 // ...
90 // } else {
91 // throw(casacore::AipsError("Doing nothing because axisname Attribute unsuitable"));
92 // }
93 // </srcblock>
94 //
95 // The following example uses the Attribute equality operator to
96 // determine some state.
97 // <srcblock>
98 // /* "itsAxisName" is some private casacore::String */
99 // Attribute att("axisname", itsAxisName);
100 // ...
101 // Attribute currentAtt("axisname", "casacore::Stokes");
102 // if (currentAtt == att) {
103 // ...
104 // } else {
105 // ...
106 // }
107 // </srcblock>
108 //
109 // A more complete example, exhibiting the Attribute interface to a
110 // specific display class, the <linkto
111 // class=WorldCanvas>WorldCanvas</linkto>, follows.
112 // <srcblock>
113 // /* assume we are working on a WorldCanvas "wcanvas" */
114 // /* at some point, an Attribute has been set elsewhere like this:
115 // wcanvas.setAttribute("ColorModel", "RGB");
116 // */
117 // ...
118 // /* somewhere later in the program ... */
119 // if (wcanvas.existsAttribute("ColorModel")) {
120 // casacore::String colormodel;
121 // wcanvas.getAttribute("ColorModel", colormodel);
122 // if (colormodel == "RGB") {
123 // ...
124 // } else {
125 // ...
126 // }
127 // } else {
128 // ...
129 // }
130 // </srcblock>
131 // </example>
132 
133 // <motivation>
134 // The main motivation for introducing Attributes is to be able to
135 // attach arbitrary name-value pairs to various objects in the display
136 // classes. This allows the storage, retrieval and comparison of
137 // arbitrary information from the various display objects.
138 // </motivation>
139 
140 // <todo asof="2000/01/17">
141 // <li> Re-write <src>setValue</src> function.
142 // </todo>
143 
144  class Attribute {
145 
146  public:
147 
148  // Constructor taking an AttributeValueBase. By inheriting from
149  // AttributeValueBase, additional types of Attributes can be
150  // supported.
152 
153  // Copy constructor.
154  Attribute(const Attribute& other);
155 
156  // Constructors that take a single value. The value stored in an
157  // Attribute can be made fuzzy by giving some tolerance
158  // <src>tol</src>, and when the values can be compared to see if
159  // they match, the tolerance is taken into account where it makes
160  // sense. The parameter <src>strict</src> determines how the
161  // matching is done for the values. If <src>strict == true</src>,
162  // the values have to match elementwise (a single value is
163  // considered a casacore::Vector of length 1). If <src>strict == false</src>,
164  // the values match if any one element in one value matches any one
165  // elemnt in the other value.
166  // <group>
167  Attribute(const casacore::String &name, const casacore::uInt value,
168  const casacore::uInt tolerance = 0, const casacore::Bool strict = false);
169  Attribute(const casacore::String &name, const casacore::Int value,
170  const casacore::Int tolerance = 0, const casacore::Bool strict = false);
171  Attribute(const casacore::String &name, const casacore::Float value,
172  const casacore::Float tolerance = 0.0, const casacore::Bool strict = false);
173  Attribute(const casacore::String &name, const casacore::Double value,
174  const casacore::Double tolerance = 0.0, const casacore::Bool strict = false);
175  Attribute(const casacore::String &name, const casacore::Quantity value,
176  const casacore::Bool strict = false);
177  Attribute(const casacore::String &name, const casacore::Quantity value,
178  const casacore::Quantity tolerance, casacore::Bool strict = false);
179  Attribute(const casacore::String &name, const casacore::Bool value,
180  const casacore::Bool strict = false);
181  Attribute(const casacore::String &name, const casacore::String value,
182  const casacore::Bool strict = false);
183  // </group>
184 
185  // Contructors that take a <src>casacore::Vector</src> of the various
186  // types. Once again, the value stored in an Attribute can be made
187  // fuzzy by specifying <src>tol</src> or strict by putting
188  // <src>strict = true</src>.
189  // <group>
191  const casacore::uInt tolerance = 0, const casacore::Bool strict = false);
193  const casacore::Int tolerance = 0, const casacore::Bool strict = false);
195  const casacore::Float tolerance = 0.0, const casacore::Bool strict = false);
197  const casacore::Double tolerance = 0.0, const casacore::Bool strict = false);
199  const casacore::Bool strict = false);
201  const casacore::Quantity tolerance, const casacore::Bool strict = false);
203  const casacore::Bool strict = false);
205  const casacore::Bool strict = false);
206  //</group>
207 
208  // Constructors that take a pointer to a variable. This makes the
209  // Attribute an alias for the variable, changing the variable
210  // changes the value of the Attribute and vice versa. Other
211  // functionality the same as for the other constructors.
212 // <group>
213  Attribute(const casacore::String &name, casacore::uInt *value,
214  const casacore::uInt tolerance = 0, const casacore::Bool strict = false);
215  Attribute(const casacore::String &name, casacore::Int *value,
216  const casacore::Int tolerance = 0, const casacore::Bool strict = false);
217  Attribute(const casacore::String &name, casacore::Float *value,
218  const casacore::Float tolerance = 0.0, const casacore::Bool strict = false);
219  Attribute(const casacore::String &name, casacore::Double *value,
220  const casacore::Double tolerance = 0.0, const casacore::Bool strict = false);
221  Attribute(const casacore::String &name, casacore::Bool *value,
222  const casacore::Bool strict = false);
223  Attribute(const casacore::String &name, casacore::String *value,
224  const casacore::Bool strict = false);
225  Attribute(const casacore::String &name, casacore::Quantity *value,
226  const casacore::Bool strict = false);
227  Attribute(const casacore::String &name, casacore::Quantity *value,
228  const casacore::Quantity tolerance, const casacore::Bool strict = false);
229  // </group>
230 
231  // Constructors that take a pointer to a Vector. This again makes
232  // the Attribute an alias for the casacore::Vector: changing the Vector
233  // changes the value of the Attribute, and vice versa. Other
234  // functionality is the same as for the non-aliasing constructors.
235  // <group>
237  const casacore::uInt tolerance = 0, const casacore::Bool strict = false);
239  const casacore::Int tolerance = 0, const casacore::Bool strict = false);
241  const casacore::Float tolerance = 0.0, const casacore::Bool strict = false);
243  const casacore::Double tolerance = 0.0, const casacore::Bool strict = false);
245  const casacore::Bool strict = false);
247  const casacore::Quantity tolerance, const casacore::Bool strict = false);
249  const casacore::Bool strict = false);
251  const casacore::Bool strict = false);
252  //</group>
253 
254  // Destructor.
255  virtual ~Attribute();
256 
257  // Create a new copy of the Attribute and return a pointer to the
258  // copy (virtual constructor).
259  virtual Attribute* clone() const;
260 
261  // Attribute matching: returns <src>true</src> if <src>*this</src>
262  // and <src>other</src> match, otherwise returns <src>false</src>.
263  // <note role=caution>Two Attributes match if their names are
264  // different. If two Attributes have the same name, but the values
265  // stored in the Attributes have different types, they do not match.
266  // An Attribute of a single value and an Attribute of a casacore::Vector of
267  // values of the same type are considered to have the same type, so
268  // under certain circumstances (based on the strictness of the
269  // Attributes) two such Attributes may match.</note>
270  virtual casacore::Bool operator==(const Attribute &other) const;
271 
272  // The opposite of the Attribute matching.
273  casacore::Bool operator!=(const Attribute &other) const;
274 
275  // Attribute addition ... add the value of <src>other</src> to
276  // the value of <src>*this</src>.
277  virtual void operator+=(const Attribute &other);
278 
279  // Set the value of this Attribute to that of the <src>other</src>
280  // Attribute, if, and only if, they have the same value type. <note
281  // role=caution> This method makes an important assumption, namely
282  // that all AttributeValues that return AttValue::AtInt,
283  // AttValue::AtFloat or AttValue::AtDouble are derived from
284  // AttributeValueTol and that return AttValue::AtBool,
285  // AttValue::AtString or AttValue::AtQuantity are derived from
286  // AttributeValue (ie they are like they are created by
287  // Attribute). This is ok for <src>*this</src>, but there is no
288  // guarantee that it is correct for <src>other</src>. This
289  // assumption was not needed until the AttributeValuePoi class was
290  // written. AttributeValues were not supposed to change but were
291  // supposed to be replaced. Now this is very ugly and should be
292  // rewritten. Indeed, it fails now for Quantities, since both with
293  // and without tols are used at the moment. </note>
294  virtual void setValue(const Attribute &other);
295 
296  // Returns a pointer to the AttributeValue base class object. You must cast
297  // it to AttributeValue<T> and invoke function <src>getValue</src> to
298  // get the value of the attribute
300 
301  // Return the name of the Attribute.
302  casacore::String getName() const;
303 
304  // Return the DataType of the value of the Attribute.
306 
307  private:
308 
309  // The name of the Attribute.
311 
312  // Pointer to the attribute base class
314 
315  // (Required) default constructor.
316  Attribute();
317 
318  // Copy assignment. <note role=caution>This allows the type of the
319  // AttributeValue to change, so it is private.</note>
320  virtual const Attribute &operator=(const Attribute &other);
321 
322  };
323 
324  std::ostream &operator<<(std::ostream &os, Attribute &a);
325 
326 
327 } //# NAMESPACE CASA - END
328 
329 #endif
330 
AttValue::ValueType getType() const
Return the DataType of the value of the Attribute.
virtual casacore::Bool operator==(const Attribute &other) const
Attribute matching: returns true if *this and other match, otherwise returns false.
int Int
Definition: aipstype.h:50
casacore::Bool operator!=(const Attribute &other) const
The opposite of the Attribute matching.
virtual ~Attribute()
Destructor.
ostream & operator<<(ostream &os, const PageHeaderCache &cache)
virtual void operator+=(const Attribute &other)
Attribute addition...
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
Arbitrary name-value pairs used in the display classes.
Definition: Attribute.h:144
AttributeValueBase * itsAttributeValue
Pointer to the attribute base class.
Definition: Attribute.h:313
ValueType
The possible value types.
Definition: AttValBase.h:82
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 v...
double Double
Definition: aipstype.h:55
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::String getName() const
Return the name of the Attribute.
float Float
Definition: aipstype.h:54
casacore::String itsAttributeName
The name of the Attribute.
Definition: Attribute.h:310
virtual Attribute * clone() const
Create a new copy of the Attribute and return a pointer to the copy (virtual constructor).
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual const Attribute & operator=(const Attribute &other)
Copy assignment; Caution: This allows the type of the AttributeValue to change, so it is private; ...
Attribute()
(Required) default constructor.
AttributeValueBase * getAttributeValue() const
Returns a pointer to the AttributeValue base class object.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42