casacore
ColDescSet.h
Go to the documentation of this file.
1 //# ColDescSet.h: This class defines a set of column descriptions
2 //# Copyright (C) 1994,1995,1996,1997,1999,2000,2001
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 //# $Id$
27 
28 #ifndef TABLES_COLDESCSET_H
29 #define TABLES_COLDESCSET_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
33 #include <casacore/tables/Tables/ColumnDesc.h>
34 #include <casacore/casa/Containers/SimOrdMap.h>
35 #include <casacore/casa/BasicSL/String.h>
36 #include <casacore/casa/iosfwd.h>
37 
38 namespace casacore { //# NAMESPACE CASACORE - BEGIN
39 
40 // <summary>
41 // Set of table column descriptions
42 // </summary>
43 
44 // <use visibility=local>
45 
46 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
47 // </reviewed>
48 
49 // <prerequisite>
50 //# Classes you should understand before using this one.
51 // <li> TableDesc
52 // <li> BaseColumnDesc
53 // <li> Keyword module
54 // </prerequisite>
55 
56 // <etymology>
57 // ColumnDescSet is the set of column descriptions in a table description.
58 // </etymology>
59 
60 // <synopsis>
61 // ColumnDescSet is used by
62 // <linkto class="TableDesc:description">TableDesc</linkto>
63 // to store all column descriptions.
64 //
65 // In principle this class is only used internally by the table system.
66 // However, there is a function in TableDesc which gives const access
67 // to this class. This can be used by the user to call functions
68 // like isDisjoint.
69 // </synopsis>
70 
71 //# <todo asof="$DATE:$">
72 //# A List of bugs, limitations, extensions or planned refinements.
73 //# </todo>
74 
75 
77 {
78 friend class TableDesc;
79 
80 public:
81  // Construct an empty column set.
82  ColumnDescSet();
83 
84  // Copy constructor (copy semantics).
86 
88 
89  // Assignment (copy semantics).
91 
92  // Get a column by its name.
93  // <group>
94  ColumnDesc& operator[] (const String& name);
95  const ColumnDesc& operator[] (const String& name) const
96  { return (*(ColumnDescSet*)this)[name]; }
97  // </group>
98 
99  // Get a column by its index.
100  // <group>
102  { return *(ColumnDesc*)(colSeq_p[index]); }
103  const ColumnDesc& operator[] (uInt index) const
104  { return *(ColumnDesc*)(colSeq_p[index]); }
105  // </group>
106 
107  // Get nr of columns in this set.
108  uInt ncolumn() const
109  { return cols_p.ndefined(); }
110 
111  // Test if a column is defined in this set.
112  Bool isDefined (const String& name) const
113  { return (cols_p.isDefined (name)); }
114 
115  // Test if this set equals another one.
116  // It is equal if the number of columns is equal and all field names in
117  // this set occur in the other too. The order of the columns
118  // is not important.
119  // <br>The flag equalDataTypes is set to True if the data types
120  // of all columns match.
121  Bool isEqual (const ColumnDescSet& other, Bool& equalDataTypes) const;
122 
123  // Test if this set is a subset of another one.
124  // It is similar to isEqual above.
125  Bool isSubset (const ColumnDescSet& other, Bool& equalDataTypes) const;
126 
127  // Test if this set is a strict subset of another one, thus
128  // if it is a subset and not equal.
129  Bool isStrictSubset (const ColumnDescSet& other,
130  Bool& equalDataTypes) const;
131 
132  // Test if this set is a superset of another one.
133  Bool isSuperset (const ColumnDescSet& other, Bool& equalDataTypes) const
134  { return other.isSubset (*this, equalDataTypes); }
135 
136  // Test if this set is a strict superset of another one, thus
137  // if it is a superset and not equal.
139  Bool& equalDataTypes) const
140  { return other.isStrictSubset (*this, equalDataTypes); }
141 
142  // Test if this and the other column set are disjoint.
143  Bool isDisjoint (const ColumnDescSet& other) const;
144 
145  // Get const access to the column descriptions.
146 //#// const TypedKeywords<ColumnDesc>& columns() const
147 //#// { return cols_p; }
148 
149  // Show the columns in the set.
150  void show (ostream& os) const;
151 
152  // Check recursevily if the descriptions of all subtables are known.
153  void checkSubTableDesc() const;
154 
155 private:
156  // Add a column.
157  // An exception is thrown if a column with this name already exists.
158  ColumnDesc& addColumn (const ColumnDesc&);
159 
160  // Add a column with another name.
161  // An exception is thrown if a column with this name already exists.
162  ColumnDesc& addColumn (const ColumnDesc&, const String& newname);
163 
164  // Remove a column.
165  // An exception is thrown if the column with this name does not exist.
166  void remove (const String& name);
167 
168  // Rename a column in the set.
169  // An exception is thrown if the new name already exists or if
170  // the old name does not exist.
171  void rename (const String& newname, const String& oldname);
172 
173  // Test if all columns are part of the other set.
174  // The flag equalDataTypes is set to True if the data types of the
175  // columns in both sets are the same.
176  Bool allExist (const ColumnDescSet&, Bool& equalDataTypes) const;
177 
178  // Add another (disjoint) column set.
179  // If the sets are not disjoint (i.e. the other set contains a column
180  // with an already existing name, an exception is thrown and nothing
181  // of the other set is added.
182  void add (const ColumnDescSet& set);
183 
184  // Put the object.
185  void putFile (AipsIO& ios, const TableAttr&) const;
186 
187  // Get the object
188  void getFile (AipsIO&, const TableAttr&);
189 
190 
191  // The set of all columns.
193  // The order of addition of column descriptions.
194  //# This is in fact a Block<ColumnDesc*>, but a void* is used
195  //# to reduce the number of template instantiations.
197 };
198 
199 
200 
201 
202 } //# NAMESPACE CASACORE - END
203 
204 #endif
ColumnDescSet & operator=(const ColumnDescSet &)
Assignment (copy semantics).
AipsIO is the object persistency mechanism of Casacore.
Definition: AipsIO.h:168
Envelope class for the description of a table column.
Definition: ColumnDesc.h:131
Bool isSuperset(const ColumnDescSet &other, Bool &equalDataTypes) const
Test if this set is a superset of another one.
Definition: ColDescSet.h:133
uInt ncolumn() const
Get nr of columns in this set.
Definition: ColDescSet.h:108
Simple map with keys ordered.
Definition: SimOrdMap.h:69
Block< void * > colSeq_p
The order of addition of column descriptions.
Definition: ColDescSet.h:196
ColumnDesc & operator[](const String &name)
Get a column by its name.
void getFile(AipsIO &, const TableAttr &)
Get the object.
Set of table column descriptions.
Definition: ColDescSet.h:76
Bool isDefined(const String &name) const
Test if a column is defined in this set.
Definition: ColDescSet.h:112
void add(const ColumnDescSet &set)
Add another (disjoint) column set.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:39
Bool isSubset(const ColumnDescSet &other, Bool &equalDataTypes) const
Test if this set is a subset of another one.
void putFile(AipsIO &ios, const TableAttr &) const
Put the object.
Bool isStrictSuperset(const ColumnDescSet &other, Bool &equalDataTypes) const
Test if this set is a strict superset of another one, thus if it is a superset and not equal...
Definition: ColDescSet.h:138
Bool isStrictSubset(const ColumnDescSet &other, Bool &equalDataTypes) const
Test if this set is a strict subset of another one, thus if it is a subset and not equal...
ColumnDesc & addColumn(const ColumnDesc &)
Add a column.
void checkSubTableDesc() const
Check recursevily if the descriptions of all subtables are known.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void rename(const String &newname, const String &oldname)
Rename a column in the set.
Define the structure of a Casacore table.
Definition: TableDesc.h:186
Bool allExist(const ColumnDescSet &, Bool &equalDataTypes) const
Test if all columns are part of the other set.
Bool isEqual(const ColumnDescSet &other, Bool &equalDataTypes) const
Test if this set equals another one.
void show(ostream &os) const
Get const access to the column descriptions.
Bool isDisjoint(const ColumnDescSet &other) const
Test if this and the other column set are disjoint.
Some attributes of a table.
Definition: TableAttr.h:77
ColumnDescSet()
Construct an empty column set.
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:48
SimpleOrderedMap< String, ColumnDesc > cols_p
The set of all columns.
Definition: ColDescSet.h:192