casacore
Loading...
Searching...
No Matches
TableParseTableList.h
Go to the documentation of this file.
1//# TableParseTableList.h: Lists of tables used in a TaQL query
2//# Copyright (C) 1994-2022
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_TABLEPARSETABLELIST_H
27#define TABLES_TABLEPARSETABLELIST_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/TaQL/ExprNodeRep.h>
32#include <casacore/tables/Tables/Table.h>
33#include <vector>
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37 //# Forward declarations
38 class TableParseQuery;
39
40
41 // <summary>
42 // Class binding a shorthand to a table name.
43 // </summary>
44
45 // <use visibility=local>
46
47 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
48 // </reviewed>
49
50 // <synopsis>
51 // This class is used by TableParse to associate a Table object and its
52 // shorthand name (as used in TaQL).
53 // </synopsis>
54
56 {
57
58 public:
61
62 // Associate the table and the shorthand.
63 // The full name and the table number (from $i) can also be given.
65 const String& name, const String& shorthand,
66 Int joinIndex=-1);
67
68 // Test if shorthand matches. If also matches if the given shorthand is empty.
69 Bool test (const String& str) const
70 { return (str.empty() || shorthand_p == str); }
71
72 // Get the given table number (of $i tables in TempTables)
73 Int tabnr() const
74 { return tabnr_p; }
75
76 // Get the given table name.
77 const String& name() const
78 { return name_p; }
79
80 // Get the shorthand.
81 const String& shorthand() const
82 { return shorthand_p; }
83
84 // Get table object.
85 const Table& table() const
86 { return table_p; }
88 { return table_p; }
89
90 // Get it as a TableExprInfo object.
92
93 // Get the index of the table in the list of join objects.
94 // <0 means that it is no join table.
95 Int joinIndex() const
96 { return joinIndex_p; }
97
98 // Replace the Table object.
99 void replaceTable (const Table& table)
100 { table_p = table; }
101
102 private:
108 };
109
110
111
112 // <summary>
113 // Class containing two lists of TableParsePair objects.
114 // </summary>
115
116 // <use visibility=local>
117
118 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
119 // </reviewed>
120
121 // <synopsis>
122 // This class is used by TableParse to hold two lists of TableParsePair objects.
123 // One list is for the tables given in the WITH clause, the other list is for
124 // the other tables given in e.g. FROM or UPDATE.
125 // It has functions to operate on the lists, usually by means of the
126 // shorthand name.
127 // </synopsis>
128
130 {
131 public:
132 // Is the FROM table list empty?
133 Bool empty() const
134 { return itsFromTables.empty(); }
135
136 // Get the FROM tables.
137 const std::vector<TableParsePair>& fromTables() const
138 { return itsFromTables; }
139 std::vector<TableParsePair>& fromTablesNC()
140 { return itsFromTables; }
141
142 // Return the first FROM table (which is usually the table to operate on).
144 { return itsFromTables.at(0).getTableInfo(); }
145
146 // Return the first FROM table (which is usually the table to operate on).
147 const Table& firstTable() const
148 { return itsFromTables.at(0).table(); }
149
150 // Add a table to the list of tables with the given shorthand name.
151 // The table can be given in a few ways:
152 // <br>- As a sequence number to be taken from tempTables.
153 // <br>- As a string giving the table name path.
154 // <br>- As a subtable name (starting with ::) which will be looked up in
155 // the stack of query objects.
156 // <br>- As a temporary table (from a nested query) given in ttab.
157 // <br>- As the shorthand name of another table which will be looked up in
158 // the stack of query objects.
159 Table addTable (Int tabnr, const String& name,
160 const Table& ttab,
161 const String& shorthand,
162 Bool addToFromList,
163 const std::vector<const Table*>& tempTables,
164 const std::vector<TableParseQuery*>& stack,
165 Int joinsIndex = -1);
166
167
168 // Replace the first Table object in the FROM list with the given one.
169 void replaceTable (const Table& table);
170
171 // Find a table for the given shorthand.
172 // Optionally the WITH tables are searched as well.
173 // If no shorthand is given, the first FROM table is returned (if there).
174 // If not found, a TableParsePair with a null Table object is returned.
175 static TableParsePair findTable (const String& shorthand, Bool doWith,
176 const std::vector<TableParseQuery*>& stack);
177
178 // Try to find the Table for the given shorthand in the table list.
179 TableParsePair findTable (const String& shorthand, Bool doWith) const;
180
181 // Find the keyword given in the <src>name</src> parameter which is
182 // split into its shorthand, column and/or keyword parts.
183 // It fills parameter <src>keyName</src> with the last keyword part
184 // and returns the TableRecord containing that keyword.
185 // It is a helper function for handleSetKey, etc.
186 // If update=True, rwKeywordSet() is used to ensure the table is updated.
187 // An exception is thrown in case a name is not found.
188 TableRecord& findKeyword (const String& name, String& keyName,
189 Bool update=True);
190
191 private:
192 //# Data members
193 std::vector<TableParsePair> itsFromTables;
194 std::vector<TableParsePair> itsWithTables;
195 };
196
197
198} //# NAMESPACE CASACORE - END
199
200#endif
String: the storage and methods of handling collections of characters.
Definition String.h:223
Bool empty() const
Test for empty.
Definition String.h:375
Class to connect a Table and its alias name.
TableExprInfo getTableInfo() const
Get it as a TableExprInfo object.
void replaceTable(const Table &table)
Replace the Table object.
Int joinIndex() const
Get the index of the table in the list of join objects.
const String & name() const
Get the given table name.
const String & shorthand() const
Get the shorthand.
Bool test(const String &str) const
Test if shorthand matches.
Int tabnr() const
Get the given table number (of $i tables in TempTables)
const Table & table() const
Get table object.
TableParsePair(const Table &table, Int tabnr, const String &name, const String &shorthand, Int joinIndex=-1)
Associate the table and the shorthand.
Class containing two lists of TableParsePair objects.
Table addTable(Int tabnr, const String &name, const Table &ttab, const String &shorthand, Bool addToFromList, const std::vector< const Table * > &tempTables, const std::vector< TableParseQuery * > &stack, Int joinsIndex=-1)
Add a table to the list of tables with the given shorthand name.
const std::vector< TableParsePair > & fromTables() const
Get the FROM tables.
std::vector< TableParsePair > & fromTablesNC()
Bool empty() const
Is the FROM table list empty?
TableExprInfo first() const
Return the first FROM table (which is usually the table to operate on).
TableRecord & findKeyword(const String &name, String &keyName, Bool update=True)
Find the keyword given in the name parameter which is split into its shorthand, column and/or keyword...
TableParsePair findTable(const String &shorthand, Bool doWith) const
Try to find the Table for the given shorthand in the table list.
void replaceTable(const Table &table)
Replace the first Table object in the FROM list with the given one.
std::vector< TableParsePair > itsFromTables
std::vector< TableParsePair > itsWithTables
static TableParsePair findTable(const String &shorthand, Bool doWith, const std::vector< TableParseQuery * > &stack)
Find a table for the given shorthand.
const Table & firstTable() const
Return the first FROM table (which is usually the table to operate on).
this file contains all the compiler specific defines
Definition mainpage.dox:28
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41