AttValBase.h

Go to the documentation of this file.
00001 //# AttValBase.h: abstract base class and support class for AttributeValues
00002 //# Copyright (C) 1996,1997,1999,2000,2001,2002
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 
00028 #ifndef TRIALDISPLAY_ATTVALBASE_H
00029 #define TRIALDISPLAY_ATTVALBASE_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/Utilities/DataType.h>
00033 #include <casa/Arrays/Vector.h>
00034 #include <casa/Quanta/Quantum.h>
00035 #include <casa/iostream.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 // <summary>
00040 // Provision of type identification services for Attribute classes.
00041 // </summary>
00042 //
00043 // <use visibility=local>
00044 //
00045 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tAttribute" demos="">
00046 // </reviewed>
00047 //
00048 // <etymology>
00049 // "AttValue" is a contraction of "Attribute Value"
00050 // </etymology>
00051 //
00052 // <synopsis>
00053 // AttValue provides type identification services for use in the
00054 // Attribute classes.
00055 // </synopsis>
00056 //
00057 // <example>
00058 // AttValue can be used to provide an enumeration which identifies
00059 // the type of a variable, for example:
00060 // <srcblock>
00061 // Int i;
00062 // if (AttValue::whatType(&i) != AttValue::AtInt) {
00063 //   throw(AipsError(String("Incorrect type identification in AttValue")));
00064 // }
00065 // </srcblock>
00066 // </example>
00067 //
00068 // <motivation>
00069 // This is a support class to unify type identification for the
00070 // various Attribute classes.
00071 // </motivation>
00072 //
00073 // <todo asof="2000/01/17">
00074 // <li> Consider using global whatType function instead of this class.
00075 // </todo>
00076 
00077         class AttValue {
00078 
00079         public:
00080 
00081                 // The possible value types.
00082                 enum ValueType {
00083                     AtuInt,
00084                     AtInt,
00085                     AtFloat,
00086                     AtDouble,
00087                     AtBool,
00088                     AtString,
00089                     AtQuantity,
00090                     AtInvalid
00091                 };
00092 
00093                 // Determine the type of a scalar or Array variable.
00094                 // <group>
00095                 static AttValue::ValueType whatType(uInt *) {
00096                         return AttValue::AtuInt;
00097                 };
00098                 static AttValue::ValueType whatType(Vector<uInt> *) {
00099                         return AttValue::AtuInt;
00100                 };
00101                 static AttValue::ValueType whatType(Int *) {
00102                         return AttValue::AtInt;
00103                 };
00104                 static AttValue::ValueType whatType(Vector<Int> *) {
00105                         return AttValue::AtInt;
00106                 };
00107                 static AttValue::ValueType whatType(Float *) {
00108                         return AttValue::AtFloat;
00109                 };
00110                 static AttValue::ValueType whatType(Vector<Float> *) {
00111                         return AttValue::AtFloat;
00112                 };
00113                 static AttValue::ValueType whatType(Double *) {
00114                         return AttValue::AtDouble;
00115                 };
00116                 static AttValue::ValueType whatType(Vector<Double> *) {
00117                         return AttValue::AtDouble;
00118                 };
00119                 static AttValue::ValueType whatType(Bool *) {
00120                         return AttValue::AtBool;
00121                 };
00122                 static AttValue::ValueType whatType(Vector<Bool> *) {
00123                         return AttValue::AtBool;
00124                 };
00125                 static AttValue::ValueType whatType(String *) {
00126                         return AttValue::AtString;
00127                 };
00128                 static AttValue::ValueType whatType(Vector<String> *) {
00129                         return AttValue::AtString;
00130                 };
00131                 static AttValue::ValueType whatType(Quantity *) {
00132                         return AttValue::AtQuantity;
00133                 };
00134                 static AttValue::ValueType whatType(Vector<Quantity> *) {
00135                         return AttValue::AtQuantity;
00136                 };
00137                 static AttValue::ValueType whatType(void *) {
00138                         return AttValue::AtInvalid;
00139                 };
00140                 // </group>
00141 
00142         };
00143 
00144 // <summary>
00145 // Base class for values of Attributes used in the display classes.
00146 // </summary>
00147 //
00148 // <use visibility=export>
00149 //
00150 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tAttribute" demos="">
00151 // </reviewed>
00152 //
00153 // <etymology>
00154 // "AttributeValueBase" is a concatenation, representing a "Base"
00155 // class for "Attribute Values."
00156 // </etymology>
00157 //
00158 // <synopsis>
00159 // This class is the base for storing Attribute values.  <linkto
00160 // class=Attribute> Attributes </linkto> are simple name-value pairs,
00161 // where the name is a String, and the value can be a scalar or Array.
00162 //
00163 // This class defines the type-independent interface for Attribute
00164 // values, and the type-dependent interface and implementation is
00165 // provided in <linkto class=AttributeValue> AttributeValue </linkto>.
00166 // This type independent interface allows comparison of Attributes
00167 // of different types.
00168 // </synopsis>
00169 //
00170 // <motivation>
00171 // To provide the non-templated (ie. type-independent) interface of
00172 // AttributeValues in a single place, thus enabling the hiding of
00173 // the templated aspect of Attributes from the end-user.  In particular
00174 // it allows implementation of the comparison operators in the base
00175 // class, regardless of type.
00176 // </motivation>
00177 //
00178 // <todo asof="1999/12/09">
00179 // Nothing known.
00180 // </todo>
00181 
00182         class AttributeValueBase  {
00183 
00184         public:
00185 
00186                 // Constructor.
00187                 AttributeValueBase(AttValue::ValueType type, Bool strict);
00188 
00189                 // Copy constructor.
00190                 AttributeValueBase(const AttributeValueBase &other);
00191 
00192                 // Destructor.
00193                 virtual ~AttributeValueBase();
00194 
00195                 // Copy assignment.
00196                 const AttributeValueBase& operator=(const AttributeValueBase &other);
00197 
00198                 // Get the type of the value stored.
00199                 AttValue::ValueType getType() const;
00200 
00201                 // Check for equality (and inequality) of two objects derived from
00202                 // AttributeValueBase.  It is implemented in terms of the pure
00203                 // virtual method <src>matches</src>, which must be implemented in
00204                 // derived classes.  The <src>operator==</src> only returns
00205                 // <src>True</src> if <src>this->matches(other)</src> and
00206                 // <src>other.matches(*this)</src> are both <src>True</src>.  This
00207                 // guarantees that if <src> a == b </src> it follows that <src> b ==
00208                 // a </src> (this is enforced this way because <src>a</src> and
00209                 // <src>b</src> can be classes derived differently from
00210                 // AttributeValueBase which can therefore have a different
00211                 // implementation of <src>match()</src>).
00212                 // <group>
00213                 Bool operator==(const AttributeValueBase &other) const;
00214                 Bool operator!=(const AttributeValueBase &other) const;
00215                 // </group>
00216 
00217                 // Return a new copy of the AttributeValueBase
00218                 virtual AttributeValueBase* clone() const = 0;
00219 
00220                 // Set/get the strictness state of this AttributeValue.
00221                 // <group>
00222                 virtual void setStrictness(const Bool &newStrict);
00223                 virtual Bool getStrictness() const;
00224                 // </group>
00225 
00226                 // Add <src>other</src> to <src>*this</src>.
00227                 virtual void operator+=(const AttributeValueBase& other) = 0;
00228 
00229                 // Return class name
00230                 virtual String className() const {
00231                         return String("AttributeValueBase");
00232                 };
00233 
00234                 virtual void print(ostream& os) = 0;
00235 
00236         protected:
00237 
00238                 // The type of what is stored.
00239                 AttValue::ValueType itsValueType;
00240 
00241                 // Whether the match is strict or not.
00242                 Bool itsStrictness;
00243 
00244                 // Calculate whether <src>*this</src> matches <src>other</src>.
00245                 // Since the meaning of "match" can be different for different
00246                 // types, it is left to the derived class to define this method.
00247                 virtual Bool matches(const AttributeValueBase &other) const = 0;
00248 
00249                 // Set the type of the value stored.
00250                 virtual void setType(const AttValue::ValueType &newType);
00251 
00252                 // Check that private data match
00253                 Bool myMatch(const AttributeValueBase &other) const;
00254         };
00255 
00256         ostream &operator<<(ostream &os, AttributeValueBase &av);
00257 
00258 
00259 } //# NAMESPACE CASA - END
00260 
00261 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1