casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TableMeasDescBase.h
Go to the documentation of this file.
1 //# TableMeasDescBase.h: Definition of a Measure in a Table.
2 //# Copyright (C) 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 MEASURES_TABLEMEASDESCBASE_H
29 #define MEASURES_TABLEMEASDESCBASE_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
38 
39 namespace casacore { //# NAMESPACE CASACORE - BEGIN
40 
41 //# Forward Declarations
42 class String;
43 class Table;
44 class TableDesc;
45 class TableRecord;
46 class TableColumn;
47 class Measure;
48 template<class T> class Quantum;
49 
50 
51 // <summary>
52 // Definition of a Measure in a Table.
53 // </summary>
54 
55 // <use visibility=local>
56 
57 // <reviewed reviewer="Bob Garwood" date="1999/12/23" tests="tTableMeasures.cc">
58 // </reviewed>
59 
60 // <prerequisite>
61 //# Classes you should understand before using this one.
62 // <li> <linkto module=Measures>Measures</linkto>
63 // <li> <linkto module=Tables>Tables</linkto>
64 // <li> <linkto class=TableMeasDesc>TableMeasDesc</linkto>
65 // </prerequisite>
66 
67 // <synopsis>
68 // Abstract base class for TableMeasDesc.
69 // </synopsis>
70 
71 // <example>
72 // See class <linkto class="TableMeasDesc">TableMeasDesc</linkto>.
73 // </example>
74 
75 // <motivation>
76 // Creating the required keyword for the definition of a Measure
77 // in a Table is somewhat complicated. This class assists in that
78 // process.
79 // </motivation>
80 //
81 // <thrown>
82 // <li>AipsError during reconstruction if the column doesn't contain
83 // a MEASINFO record.
84 // <li>AipsError during reconstruction if the column has a MEASINFO
85 // but it Measure type is invalid.
86 // </thrown>
87 //
88 
89 //# <todo asof="$DATE:$">
90 //# A List of bugs, limitations, extensions or planned refinements.
91 //# </todo>
92 
94 {
95 public:
96  // Null constructor.
98 
99  // Constructor with value and reference descriptors.
100  // Note that setMeasType is always called by the derived class.
102 
103  // Copy constructor.
104  TableMeasDescBase (const TableMeasDescBase& that);
105 
106  virtual ~TableMeasDescBase();
107 
108  // Clone the object.
109  virtual TableMeasDescBase* clone() const;
110 
111  // Assignment operator.
113 
114  // Makes the descriptor persistent.
115  // <group>
116  void write (TableDesc&);
117  void write (Table&);
118  // </group>
119 
120  // Make the descriptor persistent if there was no refcode vector.
121  // This is only needed for old tables without such vectors.
122  void writeIfOld (const Table&);
123 
124  // Get the name of the underlying column.
125  const String& columnName() const
126  { return itsValue.columnName(); }
127 
128  // Return the reference code.
129  uInt getRefCode() const
130  { return itsRef.getRefCode(); }
131 
132  // Returns True if the reference varies per row.
134  { return itsRef.isRefCodeVariable(); }
135 
136  // Returns the name of the ref code column when the ref code is variable.
137  // The null string is returned if the ref code is not variable.
138  const String& refColumnName() const
139  { return itsRef.columnName(); }
140 
141  // Returns a reference to its measure reference descriptor.
143  { return itsRef; }
144 
145  // Get the name of the offset column. Empty string is returned if no
146  // offset.
147  const String& offsetColumnName() const
148  { return itsRef.offsetColumnName(); }
149 
150  // Returns True if an offset has been defined.
151  Bool hasOffset() const
152  { return itsRef.hasOffset(); }
153 
154  // Returns True if the offset is variable.
156  { return itsRef.isOffsetVariable(); }
157 
158  // Returns True if the offset is variable and is stored in an
159  // ArrayMeasColumn, i.e., offsets are stored per element.
161  { return itsRef.isOffsetArray(); }
162 
163  // Returns a reference to the offset.
164  const Measure& getOffset() const
165  { return itsRef.getOffset(); }
166 
167  // Returns the descriptors measure type as a String.
168  const String& type() const
169  { return itsMeasType.type(); }
170 
171  // Returns the reference code for this object given a string. Throws
172  // an exception if the refString is invalid for this object.
173  uInt refCode (const String& refString) const
174  { return itsMeasType.refCode(refString); }
175 
176  // Translates the refCode for the descriptors measure type.
177  const String& refType (uInt refCode) const
178  { return itsMeasType.refType(refCode); }
179 
180  // Return the Units of the Measure values
181  const Vector<Unit>& getUnits() const
182  { return itsUnits; }
183 
184  // Reset the refCode, offset, or units.
185  // It overwrites the value used when defining the TableMeasDesc.
186  // It is only possible if it was defined as fixed for the entire column.
187  // <group>
189  { itsRef.resetRefCode (refCode); }
190  void resetOffset (const Measure& offset)
191  { itsRef.resetOffset (offset); }
192  void resetUnits (const Vector<Unit>& units);
193  // </group>
194 
195  // Reconstructs the object for the given table and column name.
196  static TableMeasDescBase* reconstruct (const Table& tab,
197  const String& columnName);
198 
199  // Does this column contain table measures?
200  static Bool hasMeasures (const TableColumn& column);
201 
202 protected:
203  // Set the initial reference codes and types in the table.
204  void initTabRef (const MeasureHolder& measHolder);
205 
206  // Set the measure and possible units.
207  void setMeasUnits (const Measure& meas,
208  const Vector<Quantum<Double> >& val,
209  const Vector<Unit>& units);
210 
211 private:
212  TableMeasValueDesc itsValue; //# The measure value column.
213  TableMeasRefDesc itsRef; //# The reference.
214  //# this gives access to the columns Measure type etc
217 };
218 
219 
220 
221 } //# NAMESPACE CASACORE - END
222 
223 #endif
Bool isOffsetArray() const
Returns True if the offset is variable and is stored in an ArrayMeasColumn, i.e., offsets are stored ...
void resetRefCode(uInt refCode)
Reset the refCode, offset, or units.
A 1-D Specialization of the Array class.
Definition: ArrayFwd.h:9
Bool isOffsetArray() const
Returns True is the offset is variable and it is an ArrayMeasColumn.
const String & refColumnName() const
Returns the name of the ref code column when the ref code is variable.
Bool isOffsetVariable() const
Returns True if the offset is variable.
virtual TableMeasDescBase * clone() const
Clone the object.
Main interface class to a read/write table.
Definition: Table.h:157
const String & refType(uInt refCode) const
Translates the refCode for the descriptors measure type.
Definition of a Measure in a Table.
const Measure & getOffset() const
Returns a reference to the offset.
void resetOffset(const Measure &offset)
const String & type() const
Returns the descriptors measure type as a String.
void initTabRef(const MeasureHolder &measHolder)
Set the initial reference codes and types in the table.
void resetUnits(const Vector< Unit > &units)
const String & columnName() const
Return the name of its variable reference code column.
const String & type() const
Returns the descriptor&#39;s measure type as a String.
const TableMeasRefDesc & getRefDesc() const
Returns a reference to its measure reference descriptor.
uInt refCode(const String &refString) const
Returns the reference code for this object given a string.
Physical quantities within reference frame.
Definition: Measure.h:235
const Measure & getOffset() const
Return the fixed Measure offset.
static TableMeasDescBase * reconstruct(const Table &tab, const String &columnName)
Reconstructs the object for the given table and column name.
const String & columnName() const
Get the name of the underlying column.
Definition of a Measure Reference in a Table.
Bool hasOffset() const
Returns True if the reference has an offset.
static Bool hasMeasures(const TableColumn &column)
Does this column contain table measures?
TableMeasDescBase()
Null constructor.
TableMeasDescBase & operator=(const TableMeasDescBase &that)
Assignment operator.
A holder for Measures to enable record conversions.
Bool isOffsetVariable() const
Returns True if the offset is variable.
uInt getRefCode() const
Return the reference code.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Read/write access to a table column.
Definition: TableColumn.h:98
uInt getRefCode() const
Return the reference code.
const String & offsetColumnName() const
Get the name of the offset column.
void writeIfOld(const Table &)
Make the descriptor persistent if there was no refcode vector.
Definition of a Measure column in a Table.
Definition: TableMeasType.h:85
void setMeasUnits(const Measure &meas, const Vector< Quantum< Double > > &val, const Vector< Unit > &units)
Set the measure and possible units.
void resetOffset(const Measure &offset)
void resetRefCode(uInt refCode)
Reset the refCode or offset.
const String & offsetColumnName() const
Return the name of the Measure offset column.
const String & columnName() const
Get the name of the underlying column.
Definition of a Measure Value in a Table.
Bool isRefCodeVariable() const
Returns True if the reference varies per row.
Bool isRefCodeVariable() const
Is the reference variable?
String: the storage and methods of handling collections of characters.
Definition: String.h:225
const Vector< Unit > & getUnits() const
Return the Units of the Measure values.
Define the structure of a Casacore table.
Definition: TableDesc.h:190
uInt refCode(const String &refString) const
Returns the reference code for this object given a string.
unsigned int uInt
Definition: aipstype.h:51
const String & refType(uInt refCode) const
Translates the refCode for the descriptors measure type.
void write(TableDesc &)
Makes the descriptor persistent.
Bool hasOffset() const
Returns True if an offset has been defined.