SerialHelper.h

Go to the documentation of this file.
00001 //# SerialHelper: a helper class for (un)serializing a Function object
00002 //# Copyright (C) 2002
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$
00028 
00029 #ifndef SCIMATH_SERIALHELPER_H
00030 #define SCIMATH_SERIALHELPER_H
00031 
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/scimath/Functionals/FunctionFactoryErrors.h>
00034 #include <casacore/casa/Containers/Record.h>
00035 
00036 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00037 
00038 template<class T> class Array;
00039 
00040 template <class V>
00041 void getArrayVal(V &val, int type, const Record& gr, 
00042                  const String& name, uInt index=0);
00043 
00044 template <class V>
00045 void getArray(Array<V> &val, int type, const Record& gr, 
00046               const String& name);
00047 
00048 // <summary>
00049 //
00050 //
00051 //
00052 //
00053 //
00054 // </summary>
00055 
00056 // <use visibility=export>
00057 
00058 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00059 // </reviewed>
00060 
00061 // <prerequisite>
00062 //   <li> FunctionFactory
00063 // </prerequisite>
00064 //
00065 // <etymology>
00066 // 
00067 // 
00068 // </etymology>
00069 //
00070 // <synopsis>
00071 //
00072 //
00073 //
00074 //
00075 // </synopsis>
00076 //
00077 // <example>
00078 //
00079 //
00080 //
00081 // </example>
00082 //
00083 // <motivation>
00084 //
00085 //
00086 //
00087 // </motivation>
00088 //
00089 // <thrown>
00090 //    <li> InvalidSerializationError by getFuncType() if Record 
00091 //         does not contain a "functype" field containing a string.
00092 //    <li> InvalidSerializationError
00093 // </thrown>
00094 //
00095 // <todo asof="yyyy/mm/dd">
00096 //   <li> 
00097 //   <li> 
00098 //   <li> 
00099 // </todo>
00100 
00101 class SerialHelper {
00102 public: 
00103     static const String FUNCTYPE;
00104     static const String gtype[]; 
00105     enum shType { shtBOOL=0, shtBYTE, shtSHORT, shtINT, shtFLOAT,
00106                   shtDOUBLE, shtCOMPLEX, shtDCOMPLEX, shtSTRING};
00107 
00108     SerialHelper(const Record& record) : gr(record) { }
00109     SerialHelper(const SerialHelper& other) { gr = other.gr; }
00110     virtual ~SerialHelper() { }
00111 
00112     // load the function type name as given in the record's "functype" 
00113     // field into the given String <em>ftype</em>.  <em>gr</em> is the 
00114     //  record to extract from.  False is returned if the record 
00115     // does not contain this field.
00116     // <thrown>
00117     //   <li> InvalidSerializationError if "functype" exists but is 
00118     //          empty or the incorrect type
00119     // </thrown>
00120     Bool getFuncType(String& ftype) const;
00121 
00122     // ensure that the Function type stored in the given record, <em>gr</em>,
00123     // matches <em>ftype</em>.  If it does not, an 
00124     // InvalidSerializationError is thrown.
00125     void checkFuncType(const String& ftype) const;
00126 
00127     // return True if a field with the given <em>name</em> exists
00128     Bool exists(const String &name) const { return gr.isDefined(name); }
00129 
00130     // Get the <em>index</em>th element of the <em>name</em> field 
00131     // This should be 
00132     // particularly useful for Array objects with only one element,
00133     // i.e. a <em>scalar</em>.
00134     // Note that unlike the native  classes, indexing is zero-relative.
00135     // 
00136     // InvalidSerializationError is thrown if:
00137     // <ul>
00138     //  <li> if the given record does not contain a field called <em>name</em>
00139     //  <li> if the field is not a vector of the correct type.
00140     //  <li> if the index is out of range.
00141     // </ul>
00142     // <group>
00143     void get(Bool &val, const String& name, uInt index = 0) const;
00144 //      void get(uChar &val, const String& name, uInt index = 0) const;
00145     void get(Short &val, const String& name, uInt index = 0) const;
00146     void get(Int &val, const String& name, uInt index = 0) const;
00147     void get(Float &val, const String& name, uInt index = 0) const;
00148     void get(Double &val, const String& name, uInt index = 0) const;
00149     void get(Complex &val, const String& name, uInt index = 0) const;
00150     void get(DComplex &val, const String& name, uInt index = 0) const;
00151     void get(String &val, const String& name, uInt index = 0) const;
00152     void get(Record &val, const String& name) const;
00153     // </group>
00154 
00155     // Get the <em>index</em>th element of the <em>name</em> field 
00156     // This should be 
00157     // particularly useful for Array objects with only one element,
00158     // i.e. a <em>scalar</em>.
00159     // Note that unlike the native  classes, indexing is zero-relative.
00160     // 
00161     // InvalidSerializationError is thrown if:
00162     // <ul>
00163     //  <li> if the given record does not contain a field called <em>name</em>
00164     //  <li> if the field is not a vector of the correct type.
00165     //  <li> if the index is out of range.
00166     // </ul>
00167     // <group>
00168     void get(Array<Bool> &val, const String& name) const;
00169 //      void get(Array<uChar &val, const String& name) const;
00170     void get(Array<Short> &val, const String& name) const;
00171     void get(Array<Int> &val, const String& name) const;
00172     void get(Array<Float> &val, const String& name) const;
00173     void get(Array<Double> &val, const String& name) const;
00174     void get(Array<Complex> &val, const String& name) const;
00175     void get(Array<DComplex> &val, const String& name) const;
00176     void get(Array<String> &val, const String& name) const;
00177     // </group>
00178 
00179     SerialHelper& operator=(const SerialHelper& other) { 
00180         gr = other.gr;
00181         return *this;
00182     }
00183 
00184 protected:
00185     SerialHelper() { }
00186 
00187 private:
00188 
00189     Record gr;
00190 };
00191 
00192 
00193 } //# NAMESPACE CASACORE - END
00194 
00195 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1