casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
BaseColDesc.h
Go to the documentation of this file.
00001 //# BaseColDesc.h: an abstract base class for 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: BaseColDesc.h 21051 2011-04-20 11:46:29Z gervandiepen $
00027 
00028 #ifndef TABLES_BASECOLDESC_H
00029 #define TABLES_BASECOLDESC_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <casa/Utilities/DataType.h>
00035 #include <casa/Arrays/IPosition.h>
00036 #include <casa/BasicSL/String.h>
00037 #include <casa/iosfwd.h>
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 //# Forward Declarations
00042 class AipsIO;
00043 class ColumnDescSet;
00044 class TableRecord;
00045 class TableAttr;
00046 class BaseColumn;
00047 class PlainColumn;
00048 class RefTable;
00049 class RefColumn;
00050 class ConcatTable;
00051 class ConcatColumn;
00052 class TableDesc;
00053 class ColumnSet;
00054 
00055 
00056 // <summary>
00057 // An abstract base class for table column descriptions
00058 // </summary>
00059 
00060 // <use visibility=local>
00061 
00062 // <reviewed reviewer="Paul Shannon" date="1994/08/11" tests="none">
00063 // </reviewed>
00064 
00065 // <prerequisite>
00066 //   <li> Tables module (see especially Tables.h, the module header file)
00067 //   <li> The description of letter/envelope class design, and its 
00068 //          application to the family of classes of which BaseColumnDesc
00069 //          is a part, in ColumnDesc.h
00070 //   <li> TableDesc
00071 // </prerequisite>
00072 
00073 // <etymology>
00074 //    "Base" indicates that this is a base class for the specialized
00075 //    column description classes.
00076 // </etymology>
00077 
00078 // <synopsis> 
00079 // BaseColumnDesc is an abstract class describing a column in a table.
00080 // Various XXXXColumnDesc classes are derived from it to describe
00081 // the various types of columns, among them ArrayColumnDesc<T>
00082 // and ScalarcolumnDesc<T>. These derived classes are used to
00083 // construct a column description which can be added to the TableDesc.
00084 //
00085 // BaseColumnDesc contains functions common to all kinds of column
00086 // descriptions.
00087 // It contains a TableRecord to attach simple keywords to the
00088 // column description (e.g. to define a scale-factor). This keyword set
00089 // serves as the initial keyword set for the column when a table
00090 // gets instantiated from a table description.
00091 //
00092 // The ColumnDesc class is an envelope around BaseColumnDesc, which
00093 // can be used to get information about existing column descriptions.
00094 // </synopsis>
00095 
00096 // <motivation>
00097 // This abstract base class defines the common features required of all 
00098 // concrete column description classes.  It also provides the hook (for 
00099 // letter objects) required by ColumnDesc, the envelope class.
00100 // </motivation>
00101 
00102 // <todo asof="$DATE:$">
00103 //# A List of bugs, limitations, extensions or planned refinements.
00104 // </todo>
00105 
00106 
00107 class BaseColumnDesc
00108 {
00109 //# Allow ColumnDesc to call the private functions checkAdd, etc..
00110 friend class ColumnDesc;   
00111 
00112 public:
00113     // Construct the column base object.
00114     BaseColumnDesc (const String& name, const String& comment,
00115                     const String& dataManagerType,
00116                     const String& dataManagerGroup,
00117                     DataType, const String& dataTypeId,
00118                     Int options, uInt ndim, const IPosition& shape,
00119                     Bool isScalar, Bool isArray, Bool isTable);
00120 
00121     // Copy constructor (copy semantics).
00122     BaseColumnDesc (const BaseColumnDesc&);
00123 
00124     virtual ~BaseColumnDesc ();
00125 
00126     // Get access to the set of keywords.
00127     // <group>
00128     TableRecord& rwKeywordSet()
00129         { return *keySetPtr_p; }
00130     const TableRecord& keywordSet() const
00131         { return *keySetPtr_p; }
00132     // </group>
00133 
00134     // Show the column.
00135     virtual void show (ostream& os) const = 0;
00136 
00137     // Get the name of the column.
00138     const String& name() const
00139         { return colName_p; }
00140 
00141     // Get the data type of the column.
00142     DataType dataType() const
00143         { return dtype_p; }
00144 
00145     // Get the type id for non-standard data types (i.e. for TpOther).
00146     // For standard data types the returned string is empty.
00147     const String& dataTypeId() const
00148         { return dtypeId_p; }
00149 
00150     // Get the type name of the default data manager.
00151     const String& dataManagerType() const
00152         { return dataManType_p; }
00153 
00154     // Get the type name of the default data manager.
00155     // (allowing it to be changed)
00156     String& dataManagerType()
00157         { return dataManType_p; }
00158 
00159     // Get the data manager group.
00160     const String& dataManagerGroup() const
00161         { return dataManGroup_p; }
00162 
00163     // Get the data manager group.
00164     // (allowing it to be changed)
00165     String& dataManagerGroup()
00166         { return dataManGroup_p; }
00167 
00168     // Set the data manager type and group to the default.
00169     // If <src>always==True</src> they are always set, otherwise only if empty.
00170     void setDefaultDataManager (Bool always);
00171 
00172     // Get comment string.
00173     const String& comment() const
00174         { return comment_p; }
00175 
00176     // Get comment string (allowing it to be changed).
00177     String& comment()
00178         { return comment_p; }
00179 
00180     // Get the options.
00181     Int options() const
00182         { return option_p; }
00183 
00184     // Test if column is scalar, array or table.
00185     // <group>
00186     Bool isScalar() const
00187         { return isScalar_p; }
00188     Bool isArray() const
00189         { return isArray_p; }
00190     Bool isTable() const
00191         { return isTable_p; }
00192     // </group>
00193 
00194     // Get the number of dimensions.
00195     Int ndim() const
00196         { return nrdim_p; }
00197 
00198     // Get the predefined shape.
00199     // If not defined, a zero shape will be returned.
00200     const IPosition& shape() const
00201         { return shape_p; }
00202 
00203     // Set the number of dimensions.
00204     // This is only allowed for arrays.
00205     // <src>ndim</src> can be zero to clear the number of dimensions
00206     // and the shape.
00207     // Otherwise it can only be used if the dimensionality has not been
00208     // defined yet.
00209     void setNdim (uInt ndim);
00210 
00211     // Set the predefined shape.
00212     // This is only allowed for arrays, for which the shape
00213     // has not been defined yet.
00214     // If the dimensionality has already been defined, it must match.
00215     // It will set the option FixedShape if not set yet.
00216     // <br> The first version leaves the <src>Direct</src> option as is.
00217     // The second version sets the <src>Direct</src> option as given.
00218     // <group>
00219     void setShape (const IPosition& shape);
00220     void setShape (const IPosition& shape, Bool directOption);
00221     // </group>
00222 
00223     // Set the options to the given value.
00224     // Option <src>ColumnDesc::Direct</src> forces <src>FixedShape</src>.
00225     // If <src>FixedShape</src> is not given (implicitly or explicitly),
00226     // the column can have no shape, so its shape is cleared.
00227     void setOptions (Int options);
00228 
00229     // Get the maximum value length.
00230     uInt maxLength() const
00231         { return maxLength_p; }
00232 
00233     // Set the maximum value length.
00234     // So far, this is only possible for columns containing String values.
00235     // An exception is thrown if the column data type is not TpString.
00236     // Some storage managers support fixed length strings and can store
00237     // them more efficiently than variable length strings.
00238     void setMaxLength (uInt maxLength);
00239 
00240     // Get table description (in case column contains subtables).
00241     // <group>
00242     //# Use the non-const version to implement the const one.
00243     //# The cast is fully safe, because it returns a const object.
00244     const TableDesc* tableDesc() const
00245         { return ((BaseColumnDesc*)this)->tableDesc(); }
00246     virtual TableDesc* tableDesc();
00247     // </group>
00248 
00249 protected:
00250     String         colName_p;            //# column name
00251     String         comment_p;            //# comment
00252     String         dataManType_p;        //# default data manager type
00253     String         dataManGroup_p;       //# data manager group
00254     DataType       dtype_p;              //# datatype
00255     String         dtypeId_p;            //# datatype id for TpOther
00256     Int            option_p;             //# column options
00257     Int            nrdim_p;              //# #dimensions (<0 = unknown)
00258     IPosition      shape_p;              //# table array shape
00259     uInt           maxLength_p;          //# maximum value length (for strings)
00260     TableRecord*   keySetPtr_p;          //# set of keywords
00261     Bool           isScalar_p;           //# True = column contains scalars
00262     Bool           isArray_p;            //# True = column contains arrays
00263     Bool           isTable_p;            //# True = column contains tables
00264 
00265     // Assignment (copy semantics).
00266     BaseColumnDesc& operator= (const BaseColumnDesc&);
00267 
00268     // Put the object.
00269     // It uses putDesc to put the derived object.
00270     void putFile (AipsIO&, const TableAttr&) const;
00271 
00272     // Get the object.
00273     // It uses getDesc to get the derived object.
00274     void getFile (AipsIO&, const TableAttr&);
00275 
00276     // Put the derived object.
00277     virtual void putDesc (AipsIO&) const = 0;
00278 
00279     // Get the derived object.
00280     virtual void getDesc (AipsIO&) = 0;
00281 
00282     // Make a PlainColumn object out of the description.
00283     virtual PlainColumn* makeColumn (ColumnSet*) const = 0;
00284 
00285     // Make a RefColumn object out of the description.
00286     RefColumn* makeRefColumn (RefTable*, BaseColumn*) const;
00287 
00288     // Make a ConcatColumn object out of the description.
00289     // The default makes a ConcatColumn object.
00290     // Derived classes (ScalarColumnDesc) can make more specialized objects.
00291     virtual ConcatColumn* makeConcatColumn (ConcatTable*) const;
00292 
00293 private:
00294     // Check if a column can be handled by ColumnDescSet.
00295     // This gives, for instance, the virtual column class the opportunity
00296     // to check if the used columns exist.
00297     // <group>
00298     virtual void checkAdd (const ColumnDescSet& cds) const;
00299     virtual void checkRename (const ColumnDescSet& cds,
00300                               const String& newName) const;
00301     // </group>
00302 
00303     // Take action after a column has been handled by ColumnDescSet.
00304     // This gives, for instance, the virtual column class the opportunity
00305     // to update the virtual column list.
00306     // <group>
00307     virtual void handleAdd (ColumnDescSet& cds);
00308     virtual void handleRename (ColumnDescSet& cds, const String& oldName);
00309     virtual void handleRemove (ColumnDescSet& cds);
00310     // </group>
00311 
00312     // This function allows each column to act upon a rename of another column.
00313     // If the old name is used internally, the column can update itself.
00314     virtual void renameAction (const String& newName, const String& oldName);
00315 
00316 public:
00317     // Clone a column description (creating a new column description object).
00318     virtual BaseColumnDesc* clone() const = 0;
00319 
00320     // Get the underlying class name.
00321     virtual String className() const = 0;
00322 
00323     // Set the name of the column (for a rename).
00324     void setName (const String& name)
00325         { colName_p = name; }
00326 };
00327 
00328 
00329 
00330 
00331 } //# NAMESPACE CASA - END
00332 
00333 #endif