casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AttValBase.h
Go to the documentation of this file.
1 //# AttValBase.h: abstract base class and support class for AttributeValues
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_ATTVALBASE_H
29 #define TRIALDISPLAY_ATTVALBASE_H
30 
31 #include <casa/aips.h>
33 #include <casa/Arrays/Vector.h>
34 #include <casa/Quanta/Quantum.h>
35 #include <casa/iostream.h>
36 
37 namespace casa { //# NAMESPACE CASA - BEGIN
38 
39 // <summary>
40 // Provision of type identification services for Attribute classes.
41 // </summary>
42 //
43 // <use visibility=local>
44 //
45 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tAttribute" demos="">
46 // </reviewed>
47 //
48 // <etymology>
49 // "AttValue" is a contraction of "Attribute Value"
50 // </etymology>
51 //
52 // <synopsis>
53 // AttValue provides type identification services for use in the
54 // Attribute classes.
55 // </synopsis>
56 //
57 // <example>
58 // AttValue can be used to provide an enumeration which identifies
59 // the type of a variable, for example:
60 // <srcblock>
61 // casacore::Int i;
62 // if (AttValue::whatType(&i) != AttValue::AtInt) {
63 // throw(casacore::AipsError(casacore::String("Incorrect type identification in AttValue")));
64 // }
65 // </srcblock>
66 // </example>
67 //
68 // <motivation>
69 // This is a support class to unify type identification for the
70 // various Attribute classes.
71 // </motivation>
72 //
73 // <todo asof="2000/01/17">
74 // <li> Consider using global whatType function instead of this class.
75 // </todo>
76 
77  class AttValue {
78 
79  public:
80 
81  // The possible value types.
82  enum ValueType {
91  };
92 
93  // Determine the type of a scalar or casacore::Array variable.
94  // <group>
96  return AttValue::AtuInt;
97  };
99  return AttValue::AtuInt;
100  };
102  return AttValue::AtInt;
103  };
105  return AttValue::AtInt;
106  };
108  return AttValue::AtFloat;
109  };
111  return AttValue::AtFloat;
112  };
114  return AttValue::AtDouble;
115  };
117  return AttValue::AtDouble;
118  };
120  return AttValue::AtBool;
121  };
123  return AttValue::AtBool;
124  };
126  return AttValue::AtString;
127  };
129  return AttValue::AtString;
130  };
132  return AttValue::AtQuantity;
133  };
135  return AttValue::AtQuantity;
136  };
137  static AttValue::ValueType whatType(void *) {
138  return AttValue::AtInvalid;
139  };
140  // </group>
141 
142  };
143 
144 // <summary>
145 // Base class for values of Attributes used in the display classes.
146 // </summary>
147 //
148 // <use visibility=export>
149 //
150 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tAttribute" demos="">
151 // </reviewed>
152 //
153 // <etymology>
154 // "AttributeValueBase" is a concatenation, representing a "Base"
155 // class for "Attribute Values."
156 // </etymology>
157 //
158 // <synopsis>
159 // This class is the base for storing Attribute values. <linkto
160 // class=Attribute> Attributes </linkto> are simple name-value pairs,
161 // where the name is a casacore::String, and the value can be a scalar or Array.
162 //
163 // This class defines the type-independent interface for Attribute
164 // values, and the type-dependent interface and implementation is
165 // provided in <linkto class=AttributeValue> AttributeValue </linkto>.
166 // This type independent interface allows comparison of Attributes
167 // of different types.
168 // </synopsis>
169 //
170 // <motivation>
171 // To provide the non-templated (ie. type-independent) interface of
172 // AttributeValues in a single place, thus enabling the hiding of
173 // the templated aspect of Attributes from the end-user. In particular
174 // it allows implementation of the comparison operators in the base
175 // class, regardless of type.
176 // </motivation>
177 //
178 // <todo asof="1999/12/09">
179 // Nothing known.
180 // </todo>
181 
183 
184  public:
185 
186  // Constructor.
188 
189  // Copy constructor.
191 
192  // Destructor.
193  virtual ~AttributeValueBase();
194 
195  // Copy assignment.
196  const AttributeValueBase& operator=(const AttributeValueBase &other);
197 
198  // Get the type of the value stored.
200 
201  // Check for equality (and inequality) of two objects derived from
202  // AttributeValueBase. It is implemented in terms of the pure
203  // virtual method <src>matches</src>, which must be implemented in
204  // derived classes. The <src>operator==</src> only returns
205  // <src>true</src> if <src>this->matches(other)</src> and
206  // <src>other.matches(*this)</src> are both <src>true</src>. This
207  // guarantees that if <src> a == b </src> it follows that <src> b ==
208  // a </src> (this is enforced this way because <src>a</src> and
209  // <src>b</src> can be classes derived differently from
210  // AttributeValueBase which can therefore have a different
211  // implementation of <src>match()</src>).
212  // <group>
213  casacore::Bool operator==(const AttributeValueBase &other) const;
214  casacore::Bool operator!=(const AttributeValueBase &other) const;
215  // </group>
216 
217  // Return a new copy of the AttributeValueBase
218  virtual AttributeValueBase* clone() const = 0;
219 
220  // Set/get the strictness state of this AttributeValue.
221  // <group>
222  virtual void setStrictness(const casacore::Bool &newStrict);
223  virtual casacore::Bool getStrictness() const;
224  // </group>
225 
226  // Add <src>other</src> to <src>*this</src>.
227  virtual void operator+=(const AttributeValueBase& other) = 0;
228 
229  // Return class name
230  virtual casacore::String className() const {
231  return casacore::String("AttributeValueBase");
232  };
233 
234  virtual void print(std::ostream& os) = 0;
235 
236  protected:
237 
238  // The type of what is stored.
240 
241  // Whether the match is strict or not.
243 
244  // Calculate whether <src>*this</src> matches <src>other</src>.
245  // Since the meaning of "match" can be different for different
246  // types, it is left to the derived class to define this method.
247  virtual casacore::Bool matches(const AttributeValueBase &other) const = 0;
248 
249  // Set the type of the value stored.
250  virtual void setType(const AttValue::ValueType &newType);
251 
252  // Check that private data match
253  casacore::Bool myMatch(const AttributeValueBase &other) const;
254  };
255 
256  std::ostream &operator<<(std::ostream &os, AttributeValueBase &av);
257 
258 
259 } //# NAMESPACE CASA - END
260 
261 #endif
casacore::Bool myMatch(const AttributeValueBase &other) const
Check that private data match.
int Int
Definition: aipstype.h:50
static AttValue::ValueType whatType(casacore::Vector< casacore::Quantity > *)
Definition: AttValBase.h:134
static AttValue::ValueType whatType(casacore::Vector< casacore::Float > *)
Definition: AttValBase.h:110
virtual AttributeValueBase * clone() const =0
Return a new copy of the AttributeValueBase.
static AttValue::ValueType whatType(casacore::Vector< casacore::uInt > *)
Definition: AttValBase.h:98
ostream & operator<<(ostream &os, const PageHeaderCache &cache)
casacore::Bool operator==(const AttributeValueBase &other) const
Check for equality (and inequality) of two objects derived from AttributeValueBase.
virtual void print(std::ostream &os)=0
Provision of type identification services for Attribute classes.
Definition: AttValBase.h:77
virtual Type type()
Return the type enum.
virtual casacore::Bool getStrictness() const
virtual ~AttributeValueBase()
Destructor.
casacore::Bool itsStrictness
Whether the match is strict or not.
Definition: AttValBase.h:242
virtual casacore::String className() const
Return class name.
Definition: AttValBase.h:230
ValueType
The possible value types.
Definition: AttValBase.h:82
virtual casacore::Bool matches(const AttributeValueBase &other) const =0
Calculate whether *this matches other.
static AttValue::ValueType whatType(casacore::Vector< casacore::Bool > *)
Definition: AttValBase.h:122
static AttValue::ValueType whatType(casacore::Double *)
Definition: AttValBase.h:113
static AttValue::ValueType whatType(casacore::Quantity *)
Definition: AttValBase.h:131
virtual void setType(const AttValue::ValueType &newType)
Set the type of the value stored.
double Double
Definition: aipstype.h:55
static AttValue::ValueType whatType(casacore::String *)
Definition: AttValBase.h:125
static AttValue::ValueType whatType(casacore::Float *)
Definition: AttValBase.h:107
AttributeValueBase(AttValue::ValueType type, casacore::Bool strict)
Constructor.
static AttValue::ValueType whatType(void *)
Definition: AttValBase.h:137
virtual void operator+=(const AttributeValueBase &other)=0
Add other to *this.
static AttValue::ValueType whatType(casacore::Vector< casacore::Int > *)
Definition: AttValBase.h:104
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
static AttValue::ValueType whatType(casacore::Int *)
Definition: AttValBase.h:101
float Float
Definition: aipstype.h:54
static AttValue::ValueType whatType(casacore::uInt *)
Determine the type of a scalar or casacore::Array variable.
Definition: AttValBase.h:95
AttValue::ValueType getType() const
Get the type of the value stored.
static AttValue::ValueType whatType(casacore::Vector< casacore::String > *)
Definition: AttValBase.h:128
casacore::Bool operator!=(const AttributeValueBase &other) const
static AttValue::ValueType whatType(casacore::Bool *)
Definition: AttValBase.h:119
String: the storage and methods of handling collections of characters.
Definition: String.h:223
static AttValue::ValueType whatType(casacore::Vector< casacore::Double > *)
Definition: AttValBase.h:116
const AttributeValueBase & operator=(const AttributeValueBase &other)
Copy assignment.
virtual void setStrictness(const casacore::Bool &newStrict)
Set/get the strictness state of this AttributeValue.
unsigned int uInt
Definition: aipstype.h:51
AttValue::ValueType itsValueType
The type of what is stored.
Definition: AttValBase.h:239