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