casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
AttVal.h
Go to the documentation of this file.
00001 //# AttVal.h: type-dependent interface for values of Attributes
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_ATTVAL_H
00029 #define TRIALDISPLAY_ATTVAL_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/Arrays/Vector.h>
00033 #include <display/Display/AttValBase.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 // <summary> 
00038 // Type-dependent interface for values of Attributes.
00039 // </summary>
00040 
00041 // <use visibility=export>
00042  
00043 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tAttribute" demos="">
00044 // </reviewed>
00045  
00046 // <prerequisite>
00047 // <li> AttributeValueBase
00048 // </prerequisite>
00049 
00050 // <etymology> 
00051 // An <em>AttributeValue</em> stores the value of an Attribute
00052 // </etymology>
00053 
00054 // <synopsis>  
00055 // An Attribute in the Display Library has a name and a value.  In
00056 // order to facilite easy use of Attributes in user code, the value of
00057 // an Attribute has to be wrapped in a templated class, the
00058 // AttributeValue, which itself is derived from a non-templated base
00059 // class, <linkto class=AttributeValueBase> AttributeValueBase
00060 // </linkto>.  What is stored in the AttributeValue is a value and the
00061 // type of that value.  Only some types are supported; see
00062 // AttributeValueBase for a list. The value is always stored as a
00063 // Vector, even if the value used in the constructor is a single
00064 // value.  The operation needed for the AttributeValue is to be able
00065 // to check whether it matches another AttributeValue.  For two
00066 // AttributeValues to match they must have the same value and be of
00067 // the same type (with some tolerance, see below).  AttributeValues of
00068 // different types (through the base class AttributeValueBase), never
00069 // match.
00070 //
00071 // The parameter <src>strict</src> in some constructors defines
00072 // whether matching has to be done for each element (<src> strict ==
00073 // True </src>), or whether AttributeValues match if any one element
00074 // of one Vector is equal to any other element of the other Vector.
00075 // An AttributeValue created with a scalar type can match an
00076 // AttributeValue created with a Vector of that scalar type.
00077 // </synopsis>
00078 //
00079 // <example>
00080 // A few simple examples of the use of the AttributeValue class follow.
00081 // <srcblock>
00082 // AttributeValue<Int> intAtt1(3, False);
00083 // AttributeValue<Int> intAtt2(3, False);
00084 // AttributeValue<Int> intAtt3(2, False);
00085 // </srcblock>
00086 // 
00087 // At this point, <src>intAtt1==intAtt2</src> will return
00088 // <src>True</src>, and <src>intAtt1==intAtt3</src> will return
00089 // <src>False</src>.
00090 //
00091 // <srcblock>
00092 // Vector<Int> vec(2);
00093 // vec(0) = 1;
00094 // vec(1) = 3;
00095 // AttributeValue<Vector<Int> > vecAtt1(vec, False);
00096 // </srcblock>
00097 //
00098 // and now <src>vecAtt1==intAtt1</src> is <src>True</src>, and
00099 // <src>vecAtt1==intAtt3</src> returns <src>False</src>.
00100 //
00101 // Finally,
00102 // <srcblock>
00103 // AttributeValue<Vector<Int> > vecAtt2(vec, True);
00104 // </srcblock>
00105 
00106 // gives <src>False</src> for <src>vecAtt2==intAtt1</src>, since
00107 // they cannot match element wise because they have different lengths,
00108 // and similarly <src>vecAtt2==intAtt2</src> is also <src>False</src>.
00109 // </example>
00110 
00111 // <motivation> 
00112 // and <linkto class=Attribute> Attribute </linkto>.
00113 // </motivation>
00114 //
00115 // <todo asof="1999/12/09">
00116 // Nothing known.
00117 // </todo>
00118 
00119 template <class T> class AttributeValue : public AttributeValueBase {
00120   
00121  public:
00122 
00123   // Construct from a scalar value. The parameter <src>strict</src>
00124   // defines whether whether matching has to be done for each element
00125   // (<src>strict == True</src>) (a scalar value AttributeValue is
00126   // considered a Vector of length one), or whether AttributeValues
00127   // match if any one element of one Vector is equal to any other
00128   // element of the other Vector (<src>strict == False</src>).
00129   AttributeValue(const T &value, const Bool strict);
00130 
00131   // Construct from a <src>Vector</src>.  The parameter
00132   // <src>strict</src> defines whether whether matching has to be done
00133   // for each element (<src>strict == True</src>), or whether
00134   // AttributeValues match if any one element of one Vector is equal
00135   // to any other element of the other Vector (<src>strict == False</src>).
00136   AttributeValue(const Vector<T> &value, const Bool strict);
00137   
00138   // Destructor.
00139   virtual ~AttributeValue();
00140 
00141   // Copy constructor.
00142   AttributeValue(const AttributeValue<T> &other);
00143 
00144   // Assignment (copy semantics)
00145   const AttributeValue<T>& operator=(const AttributeValue<T> &other);
00146 
00147   // Set/get the value of the AttributeValue.
00148   // <group>
00149   virtual void setValue(const T &value);
00150   virtual void setValue(const Vector<T> &value);
00151   virtual Vector<T> getValue() const {return itsValue;};
00152   // </group>
00153 
00154   // Returns a new copy of the AttributeValue
00155   virtual AttributeValueBase* clone() const;
00156 
00157   // Add <src>other</src> to <src>*this</src>.
00158   virtual void operator+=(const AttributeValueBase& other);
00159 
00160   // Return class name
00161   virtual String className() const {return String("AttributeValue");};
00162 
00163   virtual void print(ostream& os) { os<<itsValue;  }
00164 
00165  protected:
00166   // Implements when the values of two Attributes match or not.  The
00167   // state of <src>strict</src> determines whether whether matching
00168   // has to be done for each element (<src> strict == True </src>), or
00169   // whether AttributeValues match if any one element of one Vector is
00170   // equal to any other element of the other Vector.
00171   virtual Bool matches(const AttributeValueBase& other) const;
00172 
00173   // Cast from Base class 
00174   const AttributeValue<T>& myCast (const AttributeValueBase& other) const;
00175 
00176 
00177  private:
00178   // The attribute value
00179   Vector<T> itsValue;
00180 
00181   // Sett T type in base class
00182   void setType();
00183 
00184   // Do actual matching
00185   Bool myMatch(const AttributeValue<T>& other) const;
00186 
00187   // Default constructor
00188   AttributeValue();
00189 };
00190 
00191 } //# NAMESPACE CASA - END
00192 
00193 #ifndef AIPS_NO_TEMPLATE_SRC
00194 #include <display/Display/AttVal.tcc>
00195 #endif
00196 
00197 #endif