casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AttValTol.h
Go to the documentation of this file.
1 //# AttValTol.h: templated class for tolerant AttributeValues
2 //# Copyright (C) 1996,1997,1999,2000,2001
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_ATTVALTOL_H
29 #define TRIALDISPLAY_ATTVALTOL_H
30 
31 #include <casa/aips.h>
32 #include <display/Display/AttVal.h>
33 
34 namespace casa { //# NAMESPACE CASA - BEGIN
35 
36  class AttValBase;
37 
38 // <summary>
39 // Templated class for storing Attributes which have a tolerance.
40 // </summary>
41 
42 // <use visibility=export>
43 
44 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tAttribute" demos="">
45 // </reviewed>
46 
47 // <prerequisite>
48 // <li> <linkto class="AttributeValue">AttributeValue</linkto>
49 // </prerequisite>
50 
51 // <etymology>
52 // "AttributeValueTol" is a contraction of "Attribute Value" and
53 // "Tolerance", and stores an Attribute which has associated with
54 // it some tolerance to be observed in matching with other
55 // Attributes.
56 // </etymology>
57 
58 // <synopsis>
59 // An AttributeValueTol differs from a <linkto class="AttributeValue">
60 // AttributeValue</linkto> in that it has associated with it a certain
61 // tolerance, which will be observed when matching the value with
62 // other AttributeValues. This means that values do not have to match
63 // exactly in order for the AttributeValueTols to match. Tolerant
64 // matching is defined as <src>abs(val1-val2) <= tolerance1</src>.
65 // Remember though that in general both Attributes must independently
66 // match each other for a match to exist, and so it is normally also a
67 // requirement that <src>abs(val1 - val2) <= tolerance2</src> when the
68 // second Attribute also has tolerance specified.
69 // </synopsis>
70 
71 // <example>
72 // If we have
73 //
74 // <srcBlock>
75 // AttributeValueTol<casacore::Float> Att1(3.0, 1.2, false);
76 // AttributeValueTol<casacore::Float> Att2(2.0, 1.1, false);
77 // AttributeValueTol<casacore::Float> Att3(2.1, 0.5, false);
78 // </srcBlock>
79 //
80 // then:
81 // <li> <src>Att1==Att2</src> returns <src>true</src>,
82 // <li> <src>Att2==Att3</src> returns <src>true</src>,
83 // <li> but <src>Att3==Att1</src> returns <src>false</src>.
84 // </example>
85 //
86 // <motivation>
87 // The motivation for this class is to be able to provide some
88 // in-built tolerance ("fuzziness") to AttributeValues. For example,
89 // this approach might be used in selecting channel maps to display
90 // when matching on radial velocity.
91 // </motivation>
92 // <todo asof="2000/01/17">
93 // </todo>
94 
95 
96  template <class T> class AttributeValueTol : public AttributeValue<T> {
97 
98  public:
99  // Constructor for a scalar, with specified scalar tolerance and
100  // strictness.
101  AttributeValueTol(const T &value, const T &tolerance, const casacore::Bool strict);
102 
103  // Constructor for a <src>casacore::Vector</src> value, with specified scalar
104  // tolerance and strictness.
105  AttributeValueTol(const casacore::Vector<T> &value, const T &tolerance, const casacore::Bool strict);
106 
107  // Copy contructor.
109 
110  // Destructor.
111  virtual ~AttributeValueTol();
112 
113  // Assignment operator.
115 
116  // Return a new copy of the AttributeValueTol (virtual constructor).
117  virtual AttributeValueBase *clone() const;
118 
119  // Change or retrieve the scalar tolerance.
120  // <group>
121  virtual void setTolerance(T value) {
123  };
124  virtual T getTolerance() const {
125  return itsValueTolerance;
126  };
127  // </group>
128 
129  // Return class name
130  virtual casacore::String className() const {
131  return casacore::String("AttributeValueTol");
132  };
133 
134  protected:
135 
136  // Implements when the values of two Attributes match, taking note
137  // of tolerance in this particular implementation.
138  virtual casacore::Bool matches(const AttributeValueBase& other) const;
139 
140  private:
141 
142  // The value of the tolerance
144 
145  // Does the actual matching
146  casacore::Bool myMatch(const AttributeValue<T>& other) const;
147 
148  // Default constructor
150 
151  //# Make parent members known.
152  public:
156  };
157 
158 } //# NAMESPACE CASA - END
159 
160 #ifndef AIPS_NO_TEMPLATE_SRC
161 #include <display/Display/AttValTol.tcc>
162 #endif //# AIPS_NO_TEMPLATE_SRC
163 
164 #endif
A 1-D Specialization of the Array class.
virtual AttributeValueBase * clone() const
Return a new copy of the AttributeValueTol (virtual constructor).
const AttributeValueTol< T > & operator=(const AttributeValueTol< T > &other)
Assignment operator.
virtual ~AttributeValueTol()
Destructor.
Type-dependent interface for values of Attributes.
Definition: AttVal.h:119
virtual T getTolerance() const
Definition: AttValTol.h:124
AttributeValueTol()
Default constructor.
virtual void setTolerance(T value)
Change or retrieve the scalar tolerance.
Definition: AttValTol.h:121
T itsValueTolerance
The value of the tolerance.
Definition: AttValTol.h:143
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::Bool myMatch(const AttributeValue< T > &other) const
Does the actual matching.
Templated class for storing Attributes which have a tolerance.
Definition: AttValTol.h:96
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual casacore::String className() const
Return class name.
Definition: AttValTol.h:130
virtual casacore::Bool matches(const AttributeValueBase &other) const
Implements when the values of two Attributes match, taking note of tolerance in this particular imple...
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.