casacore
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>
33#include <casacore/casa/Arrays/Vector.h>
34
35
36namespace 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>
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
106template<class T>
108{
109public:
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).
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
158protected:
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
166public:
167 // Check if vectors are comformant.
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
179template<class T>
181 { return 1; }
182
183template<class T>
185 { return (nrel_p<0 ? nelem() : nrel_p); }
186
187//# Check if 2 table vectors are conformant.
188template<class T>
189inline Bool TabVecRep<T>::conform (const TabVecRep<T>& vec) const
190 { return (nelements() == vec.nelements() ? True : False); }
191template<class T>
192inline Bool TabVecRep<T>::conform (const Vector<T>& vec) const
193 { return (nelements() == vec.nelements() ? True : False); }
194
195//# Maintain reference count.
196template<class T>
198{
199 count_p++;
200 return this;
201}
202template<class T>
204 { return --count_p; }
205
206//# Return the tag.
207template<class T>
208inline 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
size_t nelements() const
How many elements does this array have? Product of all axis lengths.
Definition: ArrayBase.h:103
Templated base class for table vectors.
Definition: TVec.h:108
uInt ndim() const
Get nr of dimensions.
Definition: TVec.h:180
rownr_t nelements() const
Get nr of elements (ie.
Definition: TVec.h:184
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:197
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:208
TabVecTag tag_p
Definition: TVec.h:160
Bool conform(const TabVecRep< T > &) const
Test if vector shape conforms another table vector.
Definition: TVec.h:189
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:203
this file contains all the compiler specific defines
Definition: mainpage.dox:28
const Bool False
Definition: aipstype.h:44
unsigned int uInt
Definition: aipstype.h:51
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
const Bool True
Definition: aipstype.h:43
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:46
@ TagScaCol
Table Vector is a scalar column.
Definition: TVec.h:53
@ TagTemp
Table Vector is a temporary vector (i.e.
Definition: TVec.h:55