casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AttValPoi.h
Go to the documentation of this file.
1 //# AttValPoi.h: templated class for aliased 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_ATTVALPOI_H
29 #define TRIALDISPLAY_ATTVALPOI_H
30 
31 #include <casa/aips.h>
33 #include <display/Display/AttVal.h>
35 
36 namespace casa { //# NAMESPACE CASA - BEGIN
37 
38 // <summary>
39 // Templated class for storing a pointer to the value of an Attribute.
40 // </summary>
41 
42 // <use visibility=local>
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 // "AttributeValuePoi" is a contraction of "Attribute Value" and
53 // "Pointer", and stores a pointer to the value of an Attribute.
54 // </etymology>
55 
56 // <synopsis>
57 // An AttributeValuePoi differs from a <linkto class="AttributeValue">
58 // AttributeValue</linkto> in that instead of using its own variable
59 // to store the actual value like AttributeValue does, it stores a
60 // pointer to the variable used in the constructor. This means that
61 // the AttributeValuePoi is just an alias to this variable, and then
62 // the user can modify the value of an AttributeValuePoi without using
63 // its interface. Alternatively, and perhaps more importantly, the
64 // Attribute interface can be used to modify members of a class.
65 // </synopsis>
66 
67 // <example>
68 // A simple example will help illustrate the utility of the AttributeValuePoi
69 // class:
70 //
71 // <srcBlock>
72 // casacore::Int varInt = 1;
73 // AttributeValuePoi<casacore::Int> intAtt(&varInt, false);
74 //
75 // casacore::Vector<casacore::Int> bla = intAtt.getValue();
76 // // bla(0) is 1;
77 //
78 // // This wil change also the AttributeValue:
79 // varInt = 2;
80 // bla = intAtt.getValue();
81 // // bla(0) is now 2
82 //
83 // intAtt.setValue(5);
84 // // now also varInt == 5
85 //
86 // </srcBlock>
87 // </example>
88 
89 // <motivation>
90 // The motivation for this class is to be able to provide an Attribute
91 // interface for modifying private members of some classes. For
92 // example, this interface is used to control the linear coordinate
93 // system of the <linkto class="WorldCanvas">WorldCanvas</linkto>.
94 // </motivation>
95 
96 // <todo asof="2000/01/17">
97 // Nothing known.
98 // </todo>
99 
100  template <class T> class AttributeValuePoi : public AttributeValue<T> {
101 
102  public:
103 
104  // Constructor for a pointer to a scalar.
105  AttributeValuePoi(T* value, const casacore::Bool strict);
106 
107  // Constructor for a pointer to a <src>casacore::Vector</src>.
109 
110  // Copy constructor.
112 
113  // Destructor.
114  virtual ~AttributeValuePoi();
115 
116  // Assignment operator.
118 
119  // Return a new copy of the AttributeValuePoi (virtual constructor).
120  virtual AttributeValueBase *clone() const;
121 
122  // Add <src>other</src> to <src>*this</src>. Needs to over-ride
123  // base class definition because the pointers need to be
124  // dereferenced prior to addition.
125  virtual void operator+=(const AttributeValueBase& other);
126 
127  // Change the value of the AttributeValue.
128  // <group>
129  virtual void setValue(const T &value);
130  virtual void setValue(const casacore::Vector<T> &value);
131  // </group>
132 
133  // Get the DataType of aliased variable.
134  virtual casacore::DataType getPointerType() const;
135 
136  // Return class name
137  virtual casacore::String className() const {
138  return casacore::String("AttributeValuePoi");
139  };
140 
141 
142  private:
143 
144  // Update the variable that is aliased to the AttributeValuePoi.
145  void updatePointerValue() const;
146 
147  // Pointer to the aliased variable. Only one is ever active depending
148  // upon how the object was constructed. The memory allocated to these pointers
149  // does not belong to this object.
150  // <group>
153  // </group>
154 
155  // The pointer DataType
156  casacore::DataType itsPointerType;
157 
158  // Cast from base class
159  const AttributeValuePoi<T>& myCast (const AttributeValueBase& other) const;
160 
161  // Default constructor
163 
164  //# Make parent members known.
165  public:
168  };
169 
170 
171 } //# NAMESPACE CASA - END
172 #ifndef AIPS_NO_TEMPLATE_SRC
173 #include <display/Display/AttValPoi.tcc>
174 #endif //# AIPS_NO_TEMPLATE_SRC
175 
176 #endif
A 1-D Specialization of the Array class.
virtual casacore::DataType getPointerType() const
Get the DataType of aliased variable.
AttributeValuePoi()
Default constructor.
virtual AttributeValueBase * clone() const
Return a new copy of the AttributeValuePoi (virtual constructor).
Type-dependent interface for values of Attributes.
Definition: AttVal.h:119
virtual casacore::String className() const
Return class name.
Definition: AttValPoi.h:137
const AttributeValuePoi< T > & operator=(const AttributeValuePoi< T > &other)
Assignment operator.
virtual void setValue(const T &value)
Change the value of the AttributeValue.
void updatePointerValue() const
Update the variable that is aliased to the AttributeValuePoi.
casacore::Vector< T > * itsVectorPointerPtr
Pointer to the aliased variable.
Definition: AttValPoi.h:151
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
virtual void operator+=(const AttributeValueBase &other)
Add other to *this.
const AttributeValuePoi< T > & myCast(const AttributeValueBase &other) const
Cast from base class.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
casacore::DataType itsPointerType
The pointer DataType.
Definition: AttValPoi.h:156
virtual ~AttributeValuePoi()
Destructor.
Templated class for storing a pointer to the value of an Attribute.
Definition: AttValPoi.h:100
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.