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