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