casacore
Loading...
Searching...
No Matches
TableKeyword.h
Go to the documentation of this file.
1// # TableKeyword.h: A keyword value representing a table
2// # Copyright (C) 1996,1997,1999,2000,2001,2002
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_TABLEKEYWORD_H
27#define TABLES_TABLEKEYWORD_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/Tables/TableAttr.h>
32#include <casacore/casa/BasicSL/String.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// # Forward Declarations
37class Table;
38
39// <summary>
40// Keyword value representing a table
41// </summary>
42
43// <use visibility=local>
44
45// <reviewed reviewer="Mark Wieringa" date="1996/04/15" tests="tTableRecord">
46// </reviewed>
47
48// <prerequisite>
49// # Classes you should understand before using this one.
50// <li> <linkto class=TableRecord>TableRecord</linkto>
51// <li> <linkto class=Table>Table</linkto>
52// </prerequisite>
53
54// <synopsis>
55// TableKeyword represents a record keyword field containing a table.
56// It is used by class TableRecord, which in its turn is meant to be
57// used by the Table class.
58// It serves the following purposes:
59// <ul>
60// <li> A table is only opened on demand, i.e. when the keyword
61// is accessed for the first time. When opened, the function
62// closeTable makes it possible to close a table when not
63// needed anymore (provided the table is not used elsewhere).
64// It will automatically be reopened when used again.
65// <li> A switch is maintained which indicates if the table
66// should be opened as readonly or read/write.
67// A table is opened as read/write when the switch is read/write and
68// when the table is writable. Otherwise it is opened as readonly.
69// When a parent table is read back, its TableKeyword's will be
70// read back and the switch will be set to the access-mode
71// (readonly or read/write) of the parent table.
72// When a new table is inserted, the access-mode is taken from the table.
73// <li> When the parent table is reopened as read/write, the table in
74// this object will also be reopened as read/write (if the table is
75// writable).
76// <li> When a TableKeyword gets written, only the table name will be
77// written. Reading it back will set the correct access-mode, while
78// the table will not be opened until necessary.
79// However, when reading a parent table back it is possible that it
80// is done from a different directory than where it was created.
81// Therefore the directory of the parent table is prepended to the
82// TableKeyword subtable name. Similarly, when written it is stripped off.
83// <br>E.g. parent table XX and subtable SUB are created in the working
84// directory WD. Reading back is done from another directory by
85// specifying WD/XX. WD will be prepended to SUB.
86// </ul>
87// </synopsis>
88
89// <motivation>
90// This class provides the extra functionality for keywords containing
91// tables. This is needed because tables are much more complex entities
92// than scalars or arrays.
93// </motivation>
94
95// <example>
96// <srcblock>
97// // Store a table in the keyword set.
98// void someFunc (const Table& subTable)
99// {
100// // Open the table and get access to the table keyword set.
101// Table table("table.data", Table::Update);
102// TableRecord& keyset = table.rwKeywordSet();
103// keyset.defineTable ("KeyTab", subTable);
104// }
105//
106// // Open the table and get the table from keyword KeyTab.
107// // It shows that this can be done in one statement.
108// Table table("table.data");
109// Table subTab = table.keywordSet().asTable ("KeyTab");
110// </srcblock>
111// </example>
112
113// # <todo asof="$DATE:$">
114// # A List of bugs, limitations, extensions or planned refinements.
115// # </todo>
116
118 public:
119 // Construct a TableKeyword with the given tableDescName.
120 // When the tableDescName is empty the keyword is variable structured.
121 // Otherwise it is fixed structured, meaning that only tables with a
122 // description of that name can be assigned to this keyword.
123 TableKeyword(const String& tableDescName);
124
125 // Construct a TableKeyword from a Table.
126 // <br>
127 // When the tableDescName is empty the keyword is variable structured.
128 // Otherwise it is fixed structured, meaning that only tables with a
129 // description of that name can be assigned to this keyword.
130 TableKeyword(const Table& table, const String& tableDescName);
131
132 // Copy constructor (full copy semantics).
134
135 // Assignment (leaves tableDescName_p untouched).
136 // This is only possible when both objects conform.
137 // <group>
140 // </group>
141
143
144 // Set the name of the table and the writable switch.
145 // This is used when reading back a keyword.
146 void set(const String& name, const TableAttr& parentAttr);
147
148 // Set the keyword to read/write access.
149 // If the table is already open, it will be reopened with read/write
150 // access if the table is writable.
151 void setRW();
152
153 // Is the table in use in another process?
154 // If <src>checkSubTables</src> is set, it is also checked if
155 // a subtable is used in another process.
156 Bool isMultiUsed(Bool checkSubTables) const;
157
158 // Get the name of the table.
159 const String& tableName() const;
160
161 // Get the name of the table relative to parent table.
162 // <group>
163 String tableName(const String& parentName) const;
164 String tableName(const TableAttr& parentAttr) const { return tableName(parentAttr.name()); }
165 // </group>
166
167 // Get the table.
168 // It will be opened when necessary.
169 // If given, the lockOptions will be used instead of the ones in
170 // the table attributes.
171 Table table(const TableLock* lockOptions = 0) const;
172
173 // Get the table attributes.
174 const TableAttr& tableAttributes() const { return attr_p; }
175
176 // Set the table attributes.
177 void setTableAttributes(const TableAttr& attr) { attr_p = attr; }
178
179 // Close the table.
180 void close() const;
181
182 // Flush and optionally fsync the table.
183 void flush(Bool fsync) const;
184
185 // Rename the table if its path contains the old parent table name.
186 void renameTable(const String& newParentName, const String& oldParentName);
187
188 // Test if the table in other conforms this table keyword.
189 // It conforms when this description name is blank or matches the
190 // table description name of the other.
191 // <group>
192 Bool conform(const TableKeyword& that) const;
193 Bool conform(const Table& that) const;
194 // </group>
195
196 // Has the table a fixed description name?
197 // It has when its description name is not empty.
198 Bool isFixed() const;
199
200 private:
204};
205
206inline const String& TableKeyword::tableName() const { return attr_p.name(); }
207
208inline Bool TableKeyword::isFixed() const { return (!tableDescName_p.empty()); }
209
210} // namespace casacore
211
212#endif
String: the storage and methods of handling collections of characters.
Definition String.h:355
const String & name() const
Get info.
Definition TableAttr.h:108
Bool conform(const Table &that) const
const String & tableName() const
Get the name of the table.
TableKeyword & operator=(const TableKeyword &that)
Assignment (leaves tableDescName_p untouched).
void close() const
Close the table.
const TableAttr & tableAttributes() const
Get the table attributes.
TableKeyword & operator=(const Table &table)
TableKeyword(const String &tableDescName)
Construct a TableKeyword with the given tableDescName.
String tableName(const TableAttr &parentAttr) const
void setTableAttributes(const TableAttr &attr)
Set the table attributes.
Bool isMultiUsed(Bool checkSubTables) const
Is the table in use in another process?
Bool conform(const TableKeyword &that) const
Test if the table in other conforms this table keyword.
void renameTable(const String &newParentName, const String &oldParentName)
Rename the table if its path contains the old parent table name.
String tableName(const String &parentName) const
Get the name of the table relative to parent table.
void setRW()
Set the keyword to read/write access.
void set(const String &name, const TableAttr &parentAttr)
Set the name of the table and the writable switch.
TableKeyword(const Table &table, const String &tableDescName)
Construct a TableKeyword from a Table.
Table table(const TableLock *lockOptions=0) const
Get the table.
void flush(Bool fsync) const
Flush and optionally fsync the table.
Bool isFixed() const
Has the table a fixed description name?
TableKeyword(const TableKeyword &that)
Copy constructor (full copy semantics).
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
String name() const
Return the name of the field.
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40