casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
CopyRecord.h
Go to the documentation of this file.
00001 //# CopyRecord.h: Copy fields from a Record to a table or other record.
00002 //# Copyright (C) 1995,1996,1997,1999,2000
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 //#
00027 //# $Id: CopyRecord.h 18093 2004-11-30 17:51:10Z ddebonis $
00028 
00029 #ifndef FITS_COPYRECORD_H
00030 #define FITS_COPYRECORD_H
00031 
00032 
00033 #include <casa/aips.h>
00034 #include <casa/Containers/Block.h>
00035 #include <casa/Containers/RecordField.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 //# Forward Declarations
00040 
00041 class Table;
00042 class TableDesc;
00043 class RecordInterface;
00044 class RecordDesc;
00045 class String;
00046 template <class T> class Vector;
00047 template <class T> class ScalarColumn;
00048 template <class T> class ArrayColumn;
00049 
00050 // <summary>
00051 // Copies fields from a Record to columns of a Table.
00052 // </summary>
00053 
00054 // <use visibility=export>
00055 
00056 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00057 // </reviewed>
00058 
00059 // <prerequisite>
00060 //   <li> Record
00061 //   <li> Table
00062 // </prerequisite>
00063 //
00064 // <etymology>
00065 // </etymology>
00066 //
00067 // <synopsis>
00068 // </synopsis>
00069 //
00070 // <example>
00071 // </example>
00072 //
00073 // <motivation>
00074 // This class should be generalized, and made better. It is the analog of
00075 // RowCopier, i.e. it copies all the fields from some Record to certain
00076 // columns of a table. The mapping from fields to columns occurs at
00077 // construction of the CopyRecordToTable object.
00078 // </motivation>
00079 
00080 class CopyRecordToTable
00081 {
00082 public:
00083     // Set the mapping between fields and columns. In particular,
00084     // inputMap(fieldNumber) -> columnNumber.
00085     CopyRecordToTable(Table &outputTable, 
00086                       const RecordInterface &inputBuffer,
00087                       const Vector<Int> inputMap);
00088 
00089     // assignment constructor, reference semantics
00090     CopyRecordToTable(const CopyRecordToTable &other);
00091 
00092     ~CopyRecordToTable();
00093 
00094     // assignment operator, reference semantics
00095     CopyRecordToTable &operator=(const CopyRecordToTable &other);
00096 
00097     // Copy from the record (which must still exist) to the given row number
00098     // of the table (which must also still exist).
00099     void copy(uInt rownr);
00100 
00101 private: 
00102     // We could just have a TableColumn for scalars, but we'd need all of
00103     // the array types anyway.
00104     PtrBlock<ScalarColumn<Bool> *> table_bool;
00105     PtrBlock<ScalarColumn<uChar> *> table_char;
00106     PtrBlock<ScalarColumn<Short> *> table_short;
00107     PtrBlock<ScalarColumn<Int> *> table_int;
00108     PtrBlock<ScalarColumn<Float> *> table_float;
00109     PtrBlock<ScalarColumn<Double> *> table_double;
00110     PtrBlock<ScalarColumn<Complex> *> table_complex;
00111     PtrBlock<ScalarColumn<DComplex> *> table_dcomplex;
00112     PtrBlock<ScalarColumn<String> *> table_string;
00113     PtrBlock<ArrayColumn<Bool> *> table_array_bool;
00114     PtrBlock<ArrayColumn<uChar> *> table_array_char;
00115     PtrBlock<ArrayColumn<Short> *> table_array_short;
00116     PtrBlock<ArrayColumn<Int> *> table_array_int;
00117     PtrBlock<ArrayColumn<Float> *> table_array_float;
00118     PtrBlock<ArrayColumn<Double> *> table_array_double;
00119     PtrBlock<ArrayColumn<Complex> *> table_array_complex;
00120     PtrBlock<ArrayColumn<DComplex> *> table_array_dcomplex;
00121     PtrBlock<ArrayColumn<String> *> table_array_string;
00122  
00123     Block<RORecordFieldPtr<Bool> > record_bool;
00124     Block<RORecordFieldPtr<uChar> > record_char;
00125     Block<RORecordFieldPtr<Short> > record_short;
00126     Block<RORecordFieldPtr<Int> > record_int;
00127     Block<RORecordFieldPtr<Float> > record_float;
00128     Block<RORecordFieldPtr<Double> > record_double;
00129     Block<RORecordFieldPtr<Complex> > record_complex;
00130     Block<RORecordFieldPtr<DComplex> > record_dcomplex;
00131     Block<RORecordFieldPtr<String> > record_string;
00132     Block<RORecordFieldPtr<Array<Bool> > > record_array_bool;
00133     Block<RORecordFieldPtr<Array<uChar> > > record_array_char;
00134     Block<RORecordFieldPtr<Array<Short> > > record_array_short;
00135     Block<RORecordFieldPtr<Array<Int> > > record_array_int;
00136     Block<RORecordFieldPtr<Array<Float> > > record_array_float;
00137     Block<RORecordFieldPtr<Array<Double> > > record_array_double;
00138     Block<RORecordFieldPtr<Array<Complex> > > record_array_complex;
00139     Block<RORecordFieldPtr<Array<DComplex> > > record_array_dcomplex;
00140     Block<RORecordFieldPtr<Array<String> > > record_array_string;
00141 
00142     void clearAll();
00143 
00144     // Undefined and inaccessible
00145     CopyRecordToTable();
00146 };
00147 
00148 //#!                        global functions
00149 
00150 // This function probably doesn't belong here, but I'm not yet sure where it does belong.
00151 // This function adds all the fields in recordDescription to tableDescription, prefixed by "prefix".
00152 // If prefix is empty, nothing is prepended
00153 // otherwise the string prefix + "_" is prepended to each RecordFieldPtr name in
00154 // constructing the TableDesc
00155 void addRecordDesc(TableDesc &tableDescription,
00156                    const RecordDesc &recordDescription,
00157                    const String &prefix);
00158 
00159 
00160 // <summary>
00161 // Copies fields between Records, possibly to fields with another name.
00162 // </summary>
00163 
00164 // <use visibility=export>
00165 
00166 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00167 // </reviewed>
00168 
00169 // <prerequisite>
00170 //   <li> Record
00171 // </prerequisite>
00172 //
00173 // <etymology>
00174 // </etymology>
00175 //
00176 // <synopsis>
00177 // </synopsis>
00178 //
00179 // <example>
00180 // </example>
00181 //
00182 // <motivation>
00183 // </motivation>
00184 
00185 class CopyRecordToRecord
00186 {
00187 public:
00188     // Set the mapping between fields and columns. In particular,
00189     // inputMap(fieldNumber) -> outputFieldNumber.
00190     CopyRecordToRecord(RecordInterface &outputBuffer, 
00191                       const RecordInterface &inputBuffer,
00192                       const Vector<Int> inputMap);
00193 
00194 
00195     ~CopyRecordToRecord();
00196 
00197     // Copy from the record (which must still exist) to the 
00198     // output record (which must also still exist).
00199     void copy();
00200 
00201 private:
00202 
00203     // Undefined and inaccessible
00204     CopyRecordToRecord();
00205     CopyRecordToRecord(const CopyRecordToRecord &);
00206     CopyRecordToRecord &operator=(const CopyRecordToRecord &);
00207  
00208     Block<RORecordFieldPtr<Bool> > in_record_bool;
00209     Block<RORecordFieldPtr<uChar> > in_record_char;
00210     Block<RORecordFieldPtr<Short> > in_record_short;
00211     Block<RORecordFieldPtr<Int> > in_record_int;
00212     Block<RORecordFieldPtr<Float> > in_record_float;
00213     Block<RORecordFieldPtr<Double> > in_record_double;
00214     Block<RORecordFieldPtr<Complex> > in_record_complex;
00215     Block<RORecordFieldPtr<DComplex> > in_record_dcomplex;
00216     Block<RORecordFieldPtr<String> > in_record_string;
00217     Block<RORecordFieldPtr<Array<Bool> > > in_record_array_bool;
00218     Block<RORecordFieldPtr<Array<uChar> > > in_record_array_char;
00219     Block<RORecordFieldPtr<Array<Short> > > in_record_array_short;
00220     Block<RORecordFieldPtr<Array<Int> > > in_record_array_int;
00221     Block<RORecordFieldPtr<Array<Float> > > in_record_array_float;
00222     Block<RORecordFieldPtr<Array<Double> > > in_record_array_double;
00223     Block<RORecordFieldPtr<Array<Complex> > > in_record_array_complex;
00224     Block<RORecordFieldPtr<Array<DComplex> > > in_record_array_dcomplex;
00225     Block<RORecordFieldPtr<Array<String> > > in_record_array_string;
00226 
00227     Block<RecordFieldPtr<Bool> > out_record_bool;
00228     Block<RecordFieldPtr<uChar> > out_record_char;
00229     Block<RecordFieldPtr<Short> > out_record_short;
00230     Block<RecordFieldPtr<Int> > out_record_int;
00231     Block<RecordFieldPtr<Float> > out_record_float;
00232     Block<RecordFieldPtr<Double> > out_record_double;
00233     Block<RecordFieldPtr<Complex> > out_record_complex;
00234     Block<RecordFieldPtr<DComplex> > out_record_dcomplex;
00235     Block<RecordFieldPtr<String> > out_record_string;
00236     Block<RecordFieldPtr<Array<Bool> > > out_record_array_bool;
00237     Block<RecordFieldPtr<Array<uChar> > > out_record_array_char;
00238     Block<RecordFieldPtr<Array<Short> > > out_record_array_short;
00239     Block<RecordFieldPtr<Array<Int> > > out_record_array_int;
00240     Block<RecordFieldPtr<Array<Float> > > out_record_array_float;
00241     Block<RecordFieldPtr<Array<Double> > > out_record_array_double;
00242     Block<RecordFieldPtr<Array<Complex> > > out_record_array_complex;
00243     Block<RecordFieldPtr<Array<DComplex> > > out_record_array_dcomplex;
00244     Block<RecordFieldPtr<Array<String> > > out_record_array_string;
00245 };
00246 
00247 
00248 } //# NAMESPACE CASA - END
00249 
00250 #endif
00251 
00252