casacore
SerialHelper.h
Go to the documentation of this file.
1 //# SerialHelper: a helper class for (un)serializing a Function object
2 //# Copyright (C) 2002
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //#
27 //# $Id$
28 
29 #ifndef SCIMATH_SERIALHELPER_H
30 #define SCIMATH_SERIALHELPER_H
31 
32 #include <casacore/casa/aips.h>
33 #include <casacore/casa/Arrays/ArrayFwd.h>
34 #include <casacore/scimath/Functionals/FunctionFactoryErrors.h>
35 #include <casacore/casa/Containers/Record.h>
36 
37 namespace casacore { //# NAMESPACE CASACORE - BEGIN
38 
39 template <class V>
40 void getArrayVal(V &val, int type, const Record& gr,
41  const String& name, uInt index=0);
42 
43 template <class V>
44 void getArray(Array<V> &val, int type, const Record& gr,
45  const String& name);
46 
47 // <summary>
48 //
49 //
50 //
51 //
52 //
53 // </summary>
54 
55 // <use visibility=export>
56 
57 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
58 // </reviewed>
59 
60 // <prerequisite>
61 // <li> FunctionFactory
62 // </prerequisite>
63 //
64 // <etymology>
65 //
66 //
67 // </etymology>
68 //
69 // <synopsis>
70 //
71 //
72 //
73 //
74 // </synopsis>
75 //
76 // <example>
77 //
78 //
79 //
80 // </example>
81 //
82 // <motivation>
83 //
84 //
85 //
86 // </motivation>
87 //
88 // <thrown>
89 // <li> InvalidSerializationError by getFuncType() if Record
90 // does not contain a "functype" field containing a string.
91 // <li> InvalidSerializationError
92 // </thrown>
93 //
94 // <todo asof="yyyy/mm/dd">
95 // <li>
96 // <li>
97 // <li>
98 // </todo>
99 
101 public:
102  static const String FUNCTYPE;
103  static const String gtype[];
106 
107  SerialHelper(const Record& record) : gr(record) { }
108  SerialHelper(const SerialHelper& other) { gr = other.gr; }
109  virtual ~SerialHelper() { }
110 
111  // load the function type name as given in the record's "functype"
112  // field into the given String <em>ftype</em>. <em>gr</em> is the
113  // record to extract from. False is returned if the record
114  // does not contain this field.
115  // <thrown>
116  // <li> InvalidSerializationError if "functype" exists but is
117  // empty or the incorrect type
118  // </thrown>
119  Bool getFuncType(String& ftype) const;
120 
121  // ensure that the Function type stored in the given record, <em>gr</em>,
122  // matches <em>ftype</em>. If it does not, an
123  // InvalidSerializationError is thrown.
124  void checkFuncType(const String& ftype) const;
125 
126  // return True if a field with the given <em>name</em> exists
127  Bool exists(const String &name) const { return gr.isDefined(name); }
128 
129  // Get the <em>index</em>th element of the <em>name</em> field
130  // This should be
131  // particularly useful for Array objects with only one element,
132  // i.e. a <em>scalar</em>.
133  // Note that unlike the native classes, indexing is zero-relative.
134  //
135  // InvalidSerializationError is thrown if:
136  // <ul>
137  // <li> if the given record does not contain a field called <em>name</em>
138  // <li> if the field is not a vector of the correct type.
139  // <li> if the index is out of range.
140  // </ul>
141  // <group>
142  void get(Bool &val, const String& name, uInt index = 0) const;
143 // void get(uChar &val, const String& name, uInt index = 0) const;
144  void get(Short &val, const String& name, uInt index = 0) const;
145  void get(Int &val, const String& name, uInt index = 0) const;
146  void get(Float &val, const String& name, uInt index = 0) const;
147  void get(Double &val, const String& name, uInt index = 0) const;
148  void get(Complex &val, const String& name, uInt index = 0) const;
149  void get(DComplex &val, const String& name, uInt index = 0) const;
150  void get(String &val, const String& name, uInt index = 0) const;
151  void get(Record &val, const String& name) const;
152  // </group>
153 
154  // Get the <em>index</em>th element of the <em>name</em> field
155  // This should be
156  // particularly useful for Array objects with only one element,
157  // i.e. a <em>scalar</em>.
158  // Note that unlike the native classes, indexing is zero-relative.
159  //
160  // InvalidSerializationError is thrown if:
161  // <ul>
162  // <li> if the given record does not contain a field called <em>name</em>
163  // <li> if the field is not a vector of the correct type.
164  // <li> if the index is out of range.
165  // </ul>
166  // <group>
167  void get(Array<Bool> &val, const String& name) const;
168 // void get(Array<uChar &val, const String& name) const;
169  void get(Array<Short> &val, const String& name) const;
170  void get(Array<Int> &val, const String& name) const;
171  void get(Array<Float> &val, const String& name) const;
172  void get(Array<Double> &val, const String& name) const;
173  void get(Array<Complex> &val, const String& name) const;
174  void get(Array<DComplex> &val, const String& name) const;
175  void get(Array<String> &val, const String& name) const;
176  // </group>
177 
179  gr = other.gr;
180  return *this;
181  }
182 
183 protected:
185 
186 private:
187 
189 };
190 
191 
192 } //# NAMESPACE CASACORE - END
193 
194 #endif
Bool isDefined(const String &fieldName) const
Test if a field name exists.
Bool exists(const String &name) const
return True if a field with the given name exists
Definition: SerialHelper.h:127
void get(Float &val, const String &name, uInt index=0) const
static const String gtype[]
Definition: SerialHelper.h:103
void get(Array< Bool > &val, const String &name) const
Get the indexth element of the name field This should be particularly useful for Array objects with o...
void get(Array< String > &val, const String &name) const
void get(Array< Float > &val, const String &name) const
void get(Array< Int > &val, const String &name) const
SerialHelper(const Record &record)
Definition: SerialHelper.h:107
SerialHelper(const SerialHelper &other)
Definition: SerialHelper.h:108
void get(Short &val, const String &name, uInt index=0) const
void get(uChar &val, const String& name, uInt index = 0) const;
void checkFuncType(const String &ftype) const
ensure that the Function type stored in the given record, gr, matches ftype.
void get(String &val, const String &name, uInt index=0) const
void get(Array< Short > &val, const String &name) const
void get(Array<uChar &val, const String& name) const;
void get(Int &val, const String &name, uInt index=0) const
void get(Record &val, const String &name) const
void get(Array< Double > &val, const String &name) const
void get(Double &val, const String &name, uInt index=0) const
Bool getFuncType(String &ftype) const
load the function type name as given in the record's "functype" field into the given String ftype.
void get(Bool &val, const String &name, uInt index=0) const
Get the indexth element of the name field This should be particularly useful for Array objects with o...
void get(Complex &val, const String &name, uInt index=0) const
static const String FUNCTYPE
Definition: SerialHelper.h:102
void get(DComplex &val, const String &name, uInt index=0) const
void get(Array< DComplex > &val, const String &name) const
SerialHelper & operator=(const SerialHelper &other)
Definition: SerialHelper.h:178
void get(Array< Complex > &val, const String &name) const
String: the storage and methods of handling collections of characters.
Definition: String.h:225
this file contains all the compiler specific defines
Definition: mainpage.dox:28
void getArray(Array< V > &val, int type, const Record &gr, const String &name)
short Short
Definition: aipstype.h:48
unsigned int uInt
Definition: aipstype.h:51
float Float
Definition: aipstype.h:54
void getArrayVal(V &val, int type, const Record &gr, const String &name, uInt index=0)
int Int
Definition: aipstype.h:50
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
double Double
Definition: aipstype.h:55