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
38class TableParseQuery;
39
40// <summary>
41// Class binding a shorthand to a table name.
42// </summary>
43
44// <use visibility=local>
45
46// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
47// </reviewed>
48
49// <synopsis>
50// This class is used by TableParse to associate a Table object and its
51// shorthand name (as used in TaQL).
52// </synopsis>
53
55 public:
57
58 // Associate the table and the shorthand.
59 // The full name and the table number (from $i) can also be given.
61 Int joinIndex = -1);
62
63 // Test if shorthand matches. If also matches if the given shorthand is empty.
64 Bool test(const String& str) const { return (str.empty() || shorthand_p == str); }
65
66 // Get the given table number (of $i tables in TempTables)
67 Int tabnr() const { return tabnr_p; }
68
69 // Get the given table name.
70 const String& name() const { return name_p; }
71
72 // Get the shorthand.
73 const String& shorthand() const { return shorthand_p; }
74
75 // Get table object.
76 const Table& table() const { return table_p; }
77 Table& table() { return table_p; }
78
79 // Get it as a TableExprInfo object.
81
82 // Get the index of the table in the list of join objects.
83 // <0 means that it is no join table.
84 Int joinIndex() const { return joinIndex_p; }
85
86 // Replace the Table object.
87 void replaceTable(const Table& table) { table_p = table; }
88
89 private:
95};
96
97// <summary>
98// Class containing two lists of TableParsePair objects.
99// </summary>
100
101// <use visibility=local>
102
103// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
104// </reviewed>
105
106// <synopsis>
107// This class is used by TableParse to hold two lists of TableParsePair objects.
108// One list is for the tables given in the WITH clause, the other list is for
109// the other tables given in e.g. FROM or UPDATE.
110// It has functions to operate on the lists, usually by means of the
111// shorthand name.
112// </synopsis>
113
115 public:
116 // Is the FROM table list empty?
117 Bool empty() const { return itsFromTables.empty(); }
118
119 // Get the FROM tables.
120 const std::vector<TableParsePair>& fromTables() const { return itsFromTables; }
121 std::vector<TableParsePair>& fromTablesNC() { return itsFromTables; }
122
123 // Return the first FROM table (which is usually the table to operate on).
124 TableExprInfo first() const { return itsFromTables.at(0).getTableInfo(); }
125
126 // Return the first FROM table (which is usually the table to operate on).
127 const Table& firstTable() const { return itsFromTables.at(0).table(); }
128
129 // Add a table to the list of tables with the given shorthand name.
130 // The table can be given in a few ways:
131 // <br>- As a sequence number to be taken from tempTables.
132 // <br>- As a string giving the table name path.
133 // <br>- As a subtable name (starting with ::) which will be looked up in
134 // the stack of query objects.
135 // <br>- As a temporary table (from a nested query) given in ttab.
136 // <br>- As the shorthand name of another table which will be looked up in
137 // the stack of query objects.
138 Table addTable(Int tabnr, const String& name, const Table& ttab, const String& shorthand,
139 Bool addToFromList, const std::vector<const Table*>& tempTables,
140 const std::vector<TableParseQuery*>& stack, Int joinsIndex = -1);
141
142 // Replace the first Table object in the FROM list with the given one.
143 void replaceTable(const Table& table);
144
145 // Find a table for the given shorthand.
146 // Optionally the WITH tables are searched as well.
147 // If no shorthand is given, the first FROM table is returned (if there).
148 // If not found, a TableParsePair with a null Table object is returned.
149 static TableParsePair findTable(const String& shorthand, Bool doWith,
150 const std::vector<TableParseQuery*>& stack);
151
152 // Try to find the Table for the given shorthand in the table list.
153 TableParsePair findTable(const String& shorthand, Bool doWith) const;
154
155 // Find the keyword given in the <src>name</src> parameter which is
156 // split into its shorthand, column and/or keyword parts.
157 // It fills parameter <src>keyName</src> with the last keyword part
158 // and returns the TableRecord containing that keyword.
159 // It is a helper function for handleSetKey, etc.
160 // If update=True, rwKeywordSet() is used to ensure the table is updated.
161 // An exception is thrown in case a name is not found.
162 TableRecord& findKeyword(const String& name, String& keyName, Bool update = True);
163
164 private:
165 // # Data members
166 std::vector<TableParsePair> itsFromTables;
167 std::vector<TableParsePair> itsWithTables;
168};
169
170} // namespace casacore
171
172#endif
String: the storage and methods of handling collections of characters.
Definition String.h:355
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).
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
String name() const
Return the name of the field.
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