casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef SCIMATH_SERIALHELPER_H
27#define SCIMATH_SERIALHELPER_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Arrays/ArrayFwd.h>
31#include <casacore/scimath/Functionals/FunctionFactoryErrors.h>
32#include <casacore/casa/Containers/Record.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36template <class V>
37void getArrayVal(V& val, int type, const Record& gr, const String& name, uInt index = 0);
38
39template <class V>
40void getArray(Array<V>& val, int type, const Record& gr, const String& name);
41
42// <summary>
43//
44//
45//
46//
47//
48// </summary>
49
50// <use visibility=export>
51
52// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
53// </reviewed>
54
55// <prerequisite>
56// <li> FunctionFactory
57// </prerequisite>
58//
59// <etymology>
60//
61//
62// </etymology>
63//
64// <synopsis>
65//
66//
67//
68//
69// </synopsis>
70//
71// <example>
72//
73//
74//
75// </example>
76//
77// <motivation>
78//
79//
80//
81// </motivation>
82//
83// <thrown>
84// <li> InvalidSerializationError by getFuncType() if Record
85// does not contain a "functype" field containing a string.
86// <li> InvalidSerializationError
87// </thrown>
88//
89// <todo asof="yyyy/mm/dd">
90// <li>
91// <li>
92// <li>
93// </todo>
94
96 public:
97 static const String FUNCTYPE;
98 static const String gtype[];
110
111 SerialHelper(const Record& record) : gr(record) {}
112 SerialHelper(const SerialHelper& other) { gr = other.gr; }
113 virtual ~SerialHelper() {}
114
115 // load the function type name as given in the record's "functype"
116 // field into the given String <em>ftype</em>. <em>gr</em> is the
117 // record to extract from. False is returned if the record
118 // does not contain this field.
119 // <thrown>
120 // <li> InvalidSerializationError if "functype" exists but is
121 // empty or the incorrect type
122 // </thrown>
123 Bool getFuncType(String& ftype) const;
124
125 // ensure that the Function type stored in the given record, <em>gr</em>,
126 // matches <em>ftype</em>. If it does not, an
127 // InvalidSerializationError is thrown.
128 void checkFuncType(const String& ftype) const;
129
130 // return True if a field with the given <em>name</em> exists
131 Bool exists(const String& name) const { return gr.isDefined(name); }
132
133 // Get the <em>index</em>th element of the <em>name</em> field
134 // This should be
135 // particularly useful for Array objects with only one element,
136 // i.e. a <em>scalar</em>.
137 // Note that unlike the native classes, indexing is zero-relative.
138 //
139 // InvalidSerializationError is thrown if:
140 // <ul>
141 // <li> if the given record does not contain a field called <em>name</em>
142 // <li> if the field is not a vector of the correct type.
143 // <li> if the index is out of range.
144 // </ul>
145 // <group>
146 void get(Bool& val, const String& name, uInt index = 0) const;
147 // void get(uChar &val, const String& name, uInt index = 0) const;
148 void get(Short& val, const String& name, uInt index = 0) const;
149 void get(Int& val, const String& name, uInt index = 0) const;
150 void get(Float& val, const String& name, uInt index = 0) const;
151 void get(Double& val, const String& name, uInt index = 0) const;
152 void get(Complex& val, const String& name, uInt index = 0) const;
153 void get(DComplex& val, const String& name, uInt index = 0) const;
154 void get(String& val, const String& name, uInt index = 0) const;
155 void get(Record& val, const String& name) const;
156 // </group>
157
158 // Get the <em>index</em>th element of the <em>name</em> field
159 // This should be
160 // particularly useful for Array objects with only one element,
161 // i.e. a <em>scalar</em>.
162 // Note that unlike the native classes, indexing is zero-relative.
163 //
164 // InvalidSerializationError is thrown if:
165 // <ul>
166 // <li> if the given record does not contain a field called <em>name</em>
167 // <li> if the field is not a vector of the correct type.
168 // <li> if the index is out of range.
169 // </ul>
170 // <group>
171 void get(Array<Bool>& val, const String& name) const;
172 // void get(Array<uChar &val, const String& name) const;
173 void get(Array<Short>& val, const String& name) const;
174 void get(Array<Int>& val, const String& name) const;
175 void get(Array<Float>& val, const String& name) const;
176 void get(Array<Double>& val, const String& name) const;
177 void get(Array<Complex>& val, const String& name) const;
178 void get(Array<DComplex>& val, const String& name) const;
179 void get(Array<String>& val, const String& name) const;
180 // </group>
181
183 gr = other.gr;
184 return *this;
185 }
186
187 protected:
189
190 private:
192};
193
194} // namespace casacore
195
196#endif
Bool exists(const String &name) const
return True if a field with the given name exists
void get(Float &val, const String &name, uInt index=0) const
static const String gtype[]
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 & operator=(const SerialHelper &other)
SerialHelper(const Record &record)
SerialHelper(const SerialHelper &other)
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
void get(DComplex &val, const String &name, uInt index=0) const
void get(Array< DComplex > &val, const String &name) const
void get(Array< Complex > &val, const String &name) const
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
void getArray(Array< V > &val, int type, const Record &gr, const String &name)
short Short
Definition aipstype.h:46
unsigned int uInt
Definition aipstype.h:49
float Float
Definition aipstype.h:52
String name() const
Return the name of the field.
void getArrayVal(V &val, int type, const Record &gr, const String &name, uInt index=0)
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
double Double
Definition aipstype.h:53