casacore
TableExprId.h
Go to the documentation of this file.
1 //# TableExprId.h: The identification of a TaQL selection subject
2 //# Copyright (C) 2000
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 //#
27 //# $Id$
28 
29 
30 #ifndef TABLES_TABLEEXPRID_H
31 #define TABLES_TABLEEXPRID_H
32 
33 //# Includes
34 #include <casacore/casa/aips.h>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 //# Forward Declarations
39 class RecordInterface;
40 class TableExprData;
41 
42 // <summary>
43 // The identification of a TaQL selection subject.
44 // </summary>
45 
46 // <use visibility=export>
47 
48 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
49 // </reviewed>
50 
51 // <prerequisite>
52 // <li> <linkto class="TableExprNode">TableExprNode</linkto>.
53 // </prerequisite>
54 
55 // <synopsis>
56 // This class provides the user the ability to identify the data objects
57 // to test in a TaQL expression. In this way a TaQL expression is not
58 // limited to tables, but can be used for any set of data.
59 // Three types are available:
60 // <ol>
61 // <li> A row number giving the row to test in a table.
62 // It also contains a sequence number (0..n) which is used to get the
63 // result calculated by aggregate functions.
64 // <li> A <linkto class=RecordInterface>RecordInterface</linkto>
65 // object giving the record to test.
66 // <li> A <linkto class=TableExprData>TableExprData</linkto>
67 // object giving the abstract base class of an object holding
68 // the data to test. In this way any data can be used.
69 // </ol>
70 // The TaQL expression must be setup with this in mind by constructing
71 // the appropriate <linkto class=TableExprNode>TableExprNode</linkto>
72 // leaf objects.
73 // <br>
74 // When used for tables, the function <linkto class=Table>Table::col</linkto>
75 // should be used to create the <src>TableExprNode</src> objects for the
76 // table columns to be used in the expression.
77 // <br>
78 // For the other cases class
79 // <linkto class=TableExprNodeRecordField>TableExprNodeRecordField</linkto>
80 // has to be used to know the index of the fields in the expression.
81 // It uses a record (description) for this purpose.
82 // </synopsis>
83 
84 // <example>
85 // <srcblock>
86 // </srcBlock>
87 // </example>
88 
89 // <motivation>
90 // This class makes it possible that TaQL can be used in a very versatile way.
91 // </motivation>
92 
93 //# <todo asof="1996/03/12">
94 //# </todo>
95 
96 
98 {
99 public:
100  // Default constructor sets rownr to -1.
101  TableExprId();
102 
103  // Construct it from a row number.
104  TableExprId (rownr_t rowNumber);
105 
106  // Construct it from a Record object.
107  TableExprId (const RecordInterface&);
108 
109  // Construct it from pointers to data.
110  TableExprId (const TableExprData& data);
111 
113  {}
114 
115  // Is the id given by row number?
116  Bool byRow() const;
117 
118  // Is the id given as a RecordInterface?
119  Bool byRecord() const;
120 
121  // Is the id given as a TableExprData?
122  Bool byData() const;
123 
124  // Get the row number.
125  Int64 rownr() const;
126 
127  // Get the Record reference.
128  const RecordInterface& record() const;
129 
130  // Get the data reference.
131  const TableExprData& data() const;
132  // Set the row number.
133 
134  void setRownr (rownr_t rownr);
135 
136  // Set the record.
137  void setRecord (const RecordInterface&);
138 
139 private:
141  union {
145  };
146 };
147 
148 
149 
151  : type_p (0),
152  row_p (-1)
153 {}
154 
156  : type_p (0),
157  row_p (rowNumber)
158 {}
159 
161  : type_p (-1),
162  record_p (&record)
163 {}
164 
166  : type_p (-2),
167  data_p (&data)
168 {}
169 
170 inline Int64 TableExprId::rownr() const
171 {
172  return row_p;
173 }
174 
176 {
177  return *record_p;
178 }
179 
180 inline const TableExprData& TableExprId::data() const
181 {
182  return *data_p;
183 }
184 
185 inline void TableExprId::setRownr (rownr_t rownr)
186 {
187  row_p = rownr;
188 }
189 
190 inline void TableExprId::setRecord (const RecordInterface& record)
191 {
192  record_p = &record;
193 }
194 
195 inline Bool TableExprId::byRow() const
196 {
197  return type_p >= 0;
198 }
199 
201 {
202  return type_p == -1;
203 }
204 
205 inline Bool TableExprId::byData() const
206 {
207  return type_p == -2;
208 }
209 
210 
211 } //# NAMESPACE CASACORE - END
212 
213 #endif
Bool byRecord() const
Is the id given as a RecordInterface?
Definition: TableExprId.h:200
TableExprId()
Default constructor sets rownr to -1.
Definition: TableExprId.h:150
void setRownr(rownr_t rownr)
Set the row number.
Definition: TableExprId.h:185
void setRecord(const RecordInterface &)
Set the record.
Definition: TableExprId.h:190
const TableExprData * data_p
Definition: TableExprId.h:144
Int64 rownr() const
Get the row number.
Definition: TableExprId.h:170
Bool byRow() const
Is the id given by row number?
Definition: TableExprId.h:195
const TableExprData & data() const
Get the data reference.
Definition: TableExprId.h:180
Bool byData() const
Is the id given as a TableExprData?
Definition: TableExprId.h:205
const RecordInterface * record_p
Definition: TableExprId.h:143
const RecordInterface & record() const
Get the Record reference.
Definition: TableExprId.h:175
this file contains all the compiler specific defines
Definition: mainpage.dox:28
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
int Int
Definition: aipstype.h:50
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
uInt64 rownr_t
Define the type of a row number in a table.
Definition: aipsxtype.h:46