casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TVec.h
Go to the documentation of this file.
1 //# TVec.h: Templated base class for table vectors
2 //# Copyright (C) 1994,1995,1999
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 TABLES_TVEC_H
29 #define TABLES_TVEC_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
34 
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 // <summary>
39 // Enumeration of possible table vectors
40 // </summary>
41 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
42 // </reviewed>
43 // <use visibility=local>
44 // <synopsis>
45 // Define the type of table vectors.
46 // Alas, this enum has to be defined outside the class, because
47 // some compilers do not support an enum in a templated class.
48 // </synopsis>
49 // <group name=enum>
50 enum TabVecTag {
51  // Table Vector is a scalar column
52  TagScaCol = 1,
53  // Table Vector is a temporary vector (i.e. a regular vector).
54  TagTemp = 2
55 };
56 // </group>
57 
58 
59 
60 // <summary>
61 // Templated base class for table vectors
62 // </summary>
63 
64 // <use visibility=local>
65 
66 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
67 // </reviewed>
68 
69 // <prerequisite>
70 //# Classes you should understand before using this one.
71 // <li> TableVector
72 // </prerequisite>
73 
74 // <etymology>
75 // TabVecRep is the representation of a table vector.
76 // </etymology>
77 
78 // <synopsis>
79 // TabVecRep is the counted referenced letter class for the envelope
80 // class TableVector. It is an abstract base class for the actual
81 // table vector classes TabVecScaCol and TabVecTemp.
82 //
83 // All operations defined for TableVector are immediately passed to
84 // the corresponding virtual TabVecRep function.
85 // The header files TVecMath.h and TVecLogic.h declare all the
86 // mathematical and logical functions for TabVecRep.
87 // </synopsis>
88 
89 // <motivation>
90 // A virtual function call only works when used with an object
91 // pointer or reference. To allow the use of virtual functions
92 // in value objects, an extra level of indirection is used.
93 // This is called the letter/envelope idiom and is described in
94 // "Advanced C++" by J. Coplien.
95 // Class TableVector is the envelope to the letters TabVecRep and
96 // its derivations.
97 // </motivation>
98 
99 // <todo asof="$DATE:$">
100 //# A List of bugs, limitations, extensions or planned refinements.
101 // <li> put the TabVecTag enum inside the class definition
102 // <li> support array columns
103 // </todo>
104 
105 
106 template<class T>
108 {
109 public:
110 
111  // Create empty table vector.
112  // TabVecRep cannot be contructed by the user, because it is an
113  // abstract base class (it contains pure virtual functions).
114  TabVecRep();
115 
116  // Destruct the object.
117  virtual ~TabVecRep();
118 
119  // Get nr of dimensions.
120  inline uInt ndim() const;
121 
122  // Get nr of elements (ie. vector length).
123  inline rownr_t nelements() const;
124 
125  // Test if vector shape conforms another table vector.
126  inline Bool conform(const TabVecRep<T>&) const;
127 
128  // Test if vector shape conforms another vector.
129  inline Bool conform(const Vector<T>&) const;
130 
131  // Check internal consistency.
132  Bool ok() const;
133 
134  // Increments the reference count.
135  inline TabVecRep<T>* link();
136 
137  // Decrements the reference count and returns the resulting count.
138  inline uInt unlink();
139 
140  // Get the tag (the type of vector).
141  inline TabVecTag getTag() const;
142 
143  // Get a value.
144  virtual T value (rownr_t index) const = 0;
145 
146  // Get a value.
147  virtual void getVal (rownr_t index, T&) const = 0;
148 
149  // Put a value.
150  virtual void putVal (rownr_t index, const T&) = 0;
151 
152  // Set entire vector to a value.
153  virtual void set (const T&) = 0;
154 
155  // Set to another table vector.
156  virtual void assign (const TabVecRep<T>&);
157 
158 protected:
159  uInt count_p; //# reference count
160  TabVecTag tag_p;
161  Int64 nrel_p; //# #elements (<0 = ask derived class)
162 
163  // Get nr of elements.
164  virtual rownr_t nelem() const;
165 
166 public:
167  // Check if vectors are comformant.
168  void validateConformance (rownr_t) const;
169 
170  // Create a new temporary vector (for result of math operations).
171  // TabVecTemp<T>& cannot be used, because the template instantiation
172  // mechanism instantiates TabVecTemp, which depends on TabVecRep and
173  // therefore gives errors.
174  void* newVec() const;
175 };
176 
177 
178 
179 template<class T>
180 inline uInt TabVecRep<T>::ndim() const
181  { return 1; }
182 
183 template<class T>
185  { return (nrel_p<0 ? nelem() : nrel_p); }
186 
187 //# Check if 2 table vectors are conformant.
188 template<class T>
189 inline Bool TabVecRep<T>::conform (const TabVecRep<T>& vec) const
190  { return (nelements() == vec.nelements() ? True : False); }
191 template<class T>
192 inline Bool TabVecRep<T>::conform (const Vector<T>& vec) const
193  { return (nelements() == vec.nelements() ? True : False); }
194 
195 //# Maintain reference count.
196 template<class T>
198 {
199  count_p++;
200  return this;
201 }
202 template<class T>
204  { return --count_p; }
205 
206 //# Return the tag.
207 template<class T>
208 inline TabVecTag TabVecRep<T>::getTag() const
209  { return tag_p; }
210 
211 
212 
213 
214 } //# NAMESPACE CASACORE - END
215 
216 #ifndef CASACORE_NO_AUTO_TEMPLATES
217 #include <casacore/tables/Tables/TVec.tcc>
218 #endif //# CASACORE_NO_AUTO_TEMPLATES
219 #endif
uInt unlink()
Decrements the reference count and returns the resulting count.
Definition: TVec.h:203
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
TabVecRep< T > * link()
Increments the reference count.
Definition: TVec.h:197
virtual void putVal(rownr_t index, const T &)=0
Put a value.
size_t nelements() const
How many elements does this array have? Product of all axis lengths.
Definition: ArrayBase.h:103
virtual void getVal(rownr_t index, T &) const =0
Get a value.
virtual void assign(const TabVecRep< T > &)
Set to another table vector.
void * newVec() const
Create a new temporary vector (for result of math operations).
virtual T value(rownr_t index) const =0
Get a value.
Templated base class for table vectors.
Definition: TVec.h:107
TabVecTag tag_p
Definition: TVec.h:160
LatticeExprNode nelements(const LatticeExprNode &expr)
1-argument function to get the number of elements in a lattice.
void validateConformance(rownr_t) const
Check if vectors are comformant.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual ~TabVecRep()
Destruct the object.
const Bool False
Definition: aipstype.h:44
TabVecTag getTag() const
Get the tag (the type of vector).
Definition: TVec.h:208
uInt64 rownr_t
Define the type of a row number in a table.
Definition: aipsxtype.h:46
rownr_t nelements() const
Get nr of elements (ie.
Definition: TVec.h:184
virtual rownr_t nelem() const
Get nr of elements.
Bool conform(const TabVecRep< T > &) const
Test if vector shape conforms another table vector.
Definition: TVec.h:189
virtual void set(const T &)=0
Set entire vector to a value.
const Bool True
Definition: aipstype.h:43
uInt ndim() const
Get nr of dimensions.
Definition: TVec.h:180
TabVecRep()
Create empty table vector.
Bool ok() const
Check internal consistency.
unsigned int uInt
Definition: aipstype.h:51