casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ColDescSet.h
Go to the documentation of this file.
00001 //# ColDescSet.h: This class defines a set of column descriptions
00002 //# Copyright (C) 1994,1995,1996,1997,1999,2000,2001
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: ColDescSet.h 21051 2011-04-20 11:46:29Z gervandiepen $
00027 
00028 #ifndef TABLES_COLDESCSET_H
00029 #define TABLES_COLDESCSET_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <tables/Tables/ColumnDesc.h>
00034 #include <casa/Containers/SimOrdMap.h>
00035 #include <casa/BasicSL/String.h>
00036 #include <casa/iosfwd.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 // <summary>
00041 // Set of table column descriptions
00042 // </summary>
00043 
00044 // <use visibility=local>
00045 
00046 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00047 // </reviewed>
00048 
00049 // <prerequisite>
00050 //# Classes you should understand before using this one.
00051 //   <li> TableDesc
00052 //   <li> BaseColumnDesc
00053 //   <li> Keyword module
00054 // </prerequisite>
00055 
00056 // <etymology>
00057 // ColumnDescSet is the set of column descriptions in a table description.
00058 // </etymology>
00059 
00060 // <synopsis> 
00061 // ColumnDescSet is used by
00062 // <linkto class="TableDesc:description">TableDesc</linkto>
00063 // to store all column descriptions.
00064 //
00065 // In principle this class is only used internally by the table system.
00066 // However, there is a function in TableDesc which gives const access
00067 // to this class. This can be used by the user to call functions
00068 // like isDisjoint.
00069 // </synopsis> 
00070 
00071 //# <todo asof="$DATE:$">
00072 //# A List of bugs, limitations, extensions or planned refinements.
00073 //# </todo>
00074 
00075 
00076 class ColumnDescSet
00077 {
00078 friend class TableDesc;
00079 
00080 public:
00081     // Construct an empty column set.
00082     ColumnDescSet();
00083 
00084     // Copy constructor (copy semantics).
00085     ColumnDescSet (const ColumnDescSet&);
00086 
00087     ~ColumnDescSet();
00088 
00089     // Assignment (copy semantics).
00090     ColumnDescSet& operator= (const ColumnDescSet&);
00091 
00092     // Get a column by its name.
00093     // <group>
00094     ColumnDesc& operator[] (const String& name);
00095     const ColumnDesc& operator[] (const String& name) const
00096         { return (*(ColumnDescSet*)this)[name]; }
00097     // </group>
00098 
00099     // Get a column by its index.
00100     // <group>
00101     ColumnDesc& operator[] (uInt index)
00102         { return *(ColumnDesc*)(colSeq_p[index]); }
00103     const ColumnDesc& operator[] (uInt index) const
00104         { return *(ColumnDesc*)(colSeq_p[index]); }
00105     // </group>
00106 
00107     // Get nr of columns in this set.
00108     uInt ncolumn() const
00109         { return cols_p.ndefined(); }
00110 
00111     // Test if a column is defined in this set.
00112     Bool isDefined (const String& name) const
00113         { return  (cols_p.isDefined (name)); }
00114 
00115     // Test if this set equals another one.
00116     // It is equal if the number of columns is equal and all field names in
00117     // this set occur in the other too. The order of the columns
00118     // is not important.
00119     // <br>The flag equalDataTypes is set to True if the data types
00120     // of all columns match.
00121     Bool isEqual (const ColumnDescSet& other, Bool& equalDataTypes) const;
00122 
00123     // Test if this set is a subset of another one.
00124     // It is similar to isEqual above.
00125     Bool isSubset (const ColumnDescSet& other, Bool& equalDataTypes) const;
00126 
00127     // Test if this set is a strict subset of another one, thus
00128     // if it is a subset and not equal.
00129     Bool isStrictSubset (const ColumnDescSet& other,
00130                          Bool& equalDataTypes) const;
00131 
00132     // Test if this set is a superset of another one.
00133     Bool isSuperset (const ColumnDescSet& other, Bool& equalDataTypes) const
00134         { return other.isSubset (*this, equalDataTypes); }
00135 
00136     // Test if this set is a strict superset of another one, thus
00137     // if it is a superset and not equal.
00138     Bool isStrictSuperset (const ColumnDescSet& other,
00139                            Bool& equalDataTypes) const
00140         { return other.isStrictSubset (*this, equalDataTypes); }
00141 
00142     // Test if this and the other column set are disjoint.
00143     Bool isDisjoint (const ColumnDescSet& other) const;
00144 
00145     // Get const access to the column descriptions.
00146 //#//    const TypedKeywords<ColumnDesc>& columns() const
00147 //#//   { return cols_p; }
00148 
00149     // Show the columns in the set.
00150     void show (ostream& os) const;
00151 
00152     // Check recursevily if the descriptions of all subtables are known.
00153     void checkSubTableDesc() const;
00154 
00155 private:
00156     // Add a column.
00157     // An exception is thrown if a column with this name already exists.
00158     ColumnDesc& addColumn (const ColumnDesc&);
00159 
00160     // Add a column with another name.
00161     // An exception is thrown if a column with this name already exists.
00162     ColumnDesc& addColumn (const ColumnDesc&, const String& newname);
00163 
00164     // Remove a column.
00165     // An exception is thrown if the column with this name does not exist.
00166     void remove (const String& name);
00167 
00168     // Rename a column in the set.
00169     // An exception is thrown if the new name already exists or if
00170     // the old name does not exist.
00171     void rename (const String& newname, const String& oldname);
00172 
00173     // Test if all columns are part of the other set.
00174     // The flag equalDataTypes is set to True if the data types of the
00175     // columns in both sets are the same.
00176     Bool allExist (const ColumnDescSet&, Bool& equalDataTypes) const;
00177 
00178     // Add another (disjoint) column set.
00179     // If the sets are not disjoint (i.e. the other set contains a column
00180     // with an already existing name, an exception is thrown and nothing
00181     // of the other set is added.
00182     void add (const ColumnDescSet& set);
00183 
00184     // Put the object.
00185     void putFile (AipsIO& ios, const TableAttr&) const;
00186 
00187     // Get the object
00188     void getFile (AipsIO&, const TableAttr&);
00189 
00190 
00191     // The set of all columns.
00192     SimpleOrderedMap<String,ColumnDesc> cols_p;
00193     // The order of addition of column descriptions.
00194     //# This is in fact a Block<ColumnDesc*>, but a void* is used
00195     //# to reduce the number of template instantiations.
00196     Block<void*> colSeq_p;
00197 };
00198 
00199 
00200 
00201 
00202 } //# NAMESPACE CASA - END
00203 
00204 #endif