casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
AttValPoi.h
Go to the documentation of this file.
00001 //# AttValPoi.h: templated class for aliased AttributeValues
00002 //# Copyright (C) 1996,1997,1999,2000,2001
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_ATTVALPOI_H
00029 #define TRIALDISPLAY_ATTVALPOI_H
00030 
00031 #include <casa/aips.h>
00032 #include <display/Display/AttValBase.h>
00033 #include <display/Display/AttVal.h>
00034 #include <casa/Utilities/DataType.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 // <summary> 
00039 // Templated class for storing a pointer to the value of an Attribute.
00040 // </summary>
00041 
00042 // <use visibility=local>
00043  
00044 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tAttribute" demos="">
00045 // </reviewed>
00046  
00047 // <prerequisite>
00048 // <li> <linkto class="AttributeValue">AttributeValue</linkto>
00049 // </prerequisite>
00050 
00051 // <etymology> 
00052 // "AttributeValuePoi" is a contraction of "Attribute Value" and
00053 // "Pointer", and stores a pointer to the value of an Attribute.
00054 // </etymology>
00055 
00056 // <synopsis> 
00057 // An AttributeValuePoi differs from a <linkto class="AttributeValue">
00058 // AttributeValue</linkto> in that instead of using its own variable
00059 // to store the actual value like AttributeValue does, it stores a
00060 // pointer to the variable used in the constructor.  This means that
00061 // the AttributeValuePoi is just an alias to this variable, and then
00062 // the user can modify the value of an AttributeValuePoi without using
00063 // its interface.  Alternatively, and perhaps more importantly, the
00064 // Attribute interface can be used to modify members of a class.
00065 // </synopsis>
00066 
00067 // <example>
00068 // A simple example will help illustrate the utility of the AttributeValuePoi
00069 // class:
00070 //
00071 // <srcBlock>
00072 // Int varInt = 1;
00073 // AttributeValuePoi<Int> intAtt(&varInt, False);
00074 // 
00075 // Vector<Int> bla = intAtt.getValue();
00076 // // bla(0) is 1;
00077 //
00078 // // This wil change also the AttributeValue:
00079 // varInt = 2;
00080 // bla = intAtt.getValue();
00081 // // bla(0) is now 2
00082 // 
00083 // intAtt.setValue(5);
00084 // // now also varInt == 5
00085 //
00086 // </srcBlock>
00087 // </example>
00088 
00089 // <motivation> 
00090 // The motivation for this class is to be able to provide an Attribute
00091 // interface for modifying private members of some classes.  For
00092 // example, this interface is used to control the linear coordinate
00093 // system of the <linkto class="WorldCanvas">WorldCanvas</linkto>.
00094 // </motivation>
00095 
00096 // <todo asof="2000/01/17">
00097 // Nothing known.
00098 // </todo>
00099 
00100 template <class T> class AttributeValuePoi : public AttributeValue<T> {
00101 
00102  public:
00103 
00104   // Constructor for a pointer to a scalar.
00105   AttributeValuePoi(T* value, const Bool strict);
00106 
00107   // Constructor for a pointer to a <src>Vector</src>.
00108   AttributeValuePoi(Vector<T> *value, const Bool strict);
00109   
00110   // Copy constructor.
00111   AttributeValuePoi(const AttributeValuePoi<T> &other);
00112 
00113   // Destructor.
00114   virtual ~AttributeValuePoi();
00115 
00116   // Assignment operator.
00117   const AttributeValuePoi<T>& operator=(const AttributeValuePoi<T> &other);
00118 
00119   // Return a new copy of the AttributeValuePoi (virtual constructor).
00120   virtual AttributeValueBase *clone() const;
00121 
00122   // Add <src>other</src> to <src>*this</src>.  Needs to over-ride
00123   // base class definition because the pointers need to be 
00124   // dereferenced prior to addition.
00125   virtual void operator+=(const AttributeValueBase& other);
00126 
00127   // Change the value of the AttributeValue.
00128   // <group>
00129   virtual void setValue(const T &value);
00130   virtual void setValue(const Vector<T> &value);
00131   // </group>
00132 
00133   // Get the DataType of aliased variable.
00134   virtual DataType getPointerType() const;
00135 
00136   // Return class name
00137   virtual String className() const {return String("AttributeValuePoi");};
00138 
00139 
00140  private:
00141 
00142   // Update the variable that is aliased to the AttributeValuePoi.
00143   void updatePointerValue() const;
00144   
00145   // Pointer to the aliased variable. Only one is ever active depending
00146   // upon how the object was constructed.  The memory allocated to these pointers
00147   // does not belong to this object.  
00148   // <group>
00149   Vector<T>* itsVectorPointerPtr;
00150   T* itsScalarPointerPtr;
00151   // </group>
00152   
00153   // The pointer DataType 
00154   DataType itsPointerType;
00155 
00156   // Cast from base class
00157   const AttributeValuePoi<T>& myCast (const AttributeValueBase& other) const;
00158 
00159   // Default constructor
00160   AttributeValuePoi();
00161 
00162   //# Make parent members known.
00163 public:
00164   using AttributeValue<T>::getType;
00165   using AttributeValue<T>::getValue;
00166 };
00167 
00168 
00169 } //# NAMESPACE CASA - END
00170 #ifndef AIPS_NO_TEMPLATE_SRC
00171 #include <display/Display/AttValPoi.tcc>
00172 #endif //# AIPS_NO_TEMPLATE_SRC
00173 
00174 #endif