casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
RecordFieldWriter.h
Go to the documentation of this file.
00001 //# RecordFieldWriter.h: Various copiers to move fields between records.
00002 //# Copyright (C) 1996,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 //#
00027 //# $Id: RecordFieldWriter.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00028 
00029 #ifndef CASA_RECORDFIELDWRITER_H
00030 #define CASA_RECORDFIELDWRITER_H
00031 
00032 #include <casa/aips.h>
00033 #include <casa/Containers/RecordField.h>
00034 #include <casa/Arrays/Array.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 // <summary> Record field writer.  Base class for the copiers.
00039 // </summary>
00040 
00041 // <use visibility=local>
00042 
00043 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00044 // </reviewed>
00045 
00046 // <etymology>
00047 // These classes write values to a field or fields in a record.
00048 // </etymology>
00049 //
00050 // <synopsis>
00051 // These classes are used in the ms2sdfits conversion code.
00052 // It might be better if they were moved there.
00053 // </synopsis>
00054 //
00055 // <motivation>
00056 // It was useful to set up a number of copiers and invoke them as appropriate
00057 // via a single function call.  Some copiers may be more complicate than a
00058 // direct field to field copy.
00059 // </motivation>
00060 //
00061 // <todo asof="2001/07/10">
00062 //   <li> Either make this generally useful here or move them out of containers
00063 //   <li> fully document this
00064 // </todo>
00065 
00066 class RecordFieldWriter
00067 {
00068 public:
00069     virtual ~RecordFieldWriter();
00070     virtual void writeField() = 0;
00071 };
00072 
00073 // <summary> Record field copier.  Copies field to field as is.
00074 // </summary>
00075 
00076 // <use visibility=local>
00077 
00078 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00079 // </reviewed>
00080 
00081 // <etymology>
00082 // Copies a field from a record to another record with a field
00083 // of the same type.
00084 // </etymology>
00085 
00086 // <motivation>
00087 // This type of copy can be inlined.
00088 // </motivation>
00089 
00090 template<class outType, class inType> 
00091 class RecordFieldCopier : public RecordFieldWriter
00092 {
00093 public:
00094     RecordFieldCopier(RecordInterface &outRecord, 
00095                       RecordFieldId whichOutField,
00096                       const RecordInterface &inRecord, 
00097                       RecordFieldId whichInField);
00098     void copy() {*out_p = outType(*in_p);}
00099     virtual void writeField();
00100 private:
00101     RecordFieldPtr<outType>   out_p;
00102     RORecordFieldPtr<inType> in_p;
00103 };
00104 
00105 // <summary> Unequal shape copier.
00106 // </summary>
00107 
00108 // <use visibility=local>
00109 
00110 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00111 // </reviewed>
00112 
00113 // <etymology>
00114 // Copy fields where the two fields fields do not have the same shape,
00115 // however, the number of elements must match.  Copying is done element
00116 // by element in vector order.
00117 // </etymology>
00118 //
00119 // <motivation>
00120 // Sometimes the shapes need to change even though the number of elements
00121 // stays the same.
00122 // </motivation>
00123 //
00124 
00125 template<class T> class UnequalShapeCopier : public RecordFieldWriter
00126 {
00127 public:
00128     UnequalShapeCopier(RecordInterface &outRecord, 
00129                        RecordFieldId whichOutField,
00130                        const RecordInterface &inRecord, 
00131                        RecordFieldId whichInField);
00132     virtual void writeField();
00133 private:
00134     RecordFieldPtr<Array<T> >   out_p;
00135     RORecordFieldPtr<Array<T> > in_p;
00136 };
00137 
00138 // <summary> Multi field writer.  Copy many fields with a single call.
00139 // </summary>
00140 
00141 // <use visibility=local>
00142 
00143 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00144 // </reviewed>
00145 
00146 // <etymology>
00147 // This class contains other copiers and copies multiple fields at a time.
00148 // </etymology>
00149 //
00150 // <motivation>
00151 // It was useful to set up a number of copiers and invoke them as appropriate
00152 // via a single function call.
00153 // </motivation>
00154 //
00155 
00156 class MultiRecordFieldWriter
00157 {
00158 public:
00159   void addWriter(RecordFieldWriter *fromNew);
00160   void copy();
00161   ~MultiRecordFieldWriter();
00162 private:
00163   // Make faster by having the RecordFieldCopiers split out so straight copying
00164   // is inline.
00165   PtrBlock<RecordFieldWriter *> writers_p;
00166 };
00167 
00168 
00169 } //# NAMESPACE CASA - END
00170 
00171 #ifndef CASACORE_NO_AUTO_TEMPLATES
00172 #include <casa/Containers/RecordFieldWriter.tcc>
00173 #endif //# CASACORE_NO_AUTO_TEMPLATES
00174 #endif