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,
38 const String& name, uInt index=0);
39
40template <class V>
41void getArray(Array<V> &val, int type, const Record& gr,
42 const String& name);
43
44// <summary>
45//
46//
47//
48//
49//
50// </summary>
51
52// <use visibility=export>
53
54// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
55// </reviewed>
56
57// <prerequisite>
58// <li> FunctionFactory
59// </prerequisite>
60//
61// <etymology>
62//
63//
64// </etymology>
65//
66// <synopsis>
67//
68//
69//
70//
71// </synopsis>
72//
73// <example>
74//
75//
76//
77// </example>
78//
79// <motivation>
80//
81//
82//
83// </motivation>
84//
85// <thrown>
86// <li> InvalidSerializationError by getFuncType() if Record
87// does not contain a "functype" field containing a string.
88// <li> InvalidSerializationError
89// </thrown>
90//
91// <todo asof="yyyy/mm/dd">
92// <li>
93// <li>
94// <li>
95// </todo>
96
98public:
99 static const String FUNCTYPE;
100 static const String gtype[];
103
104 SerialHelper(const Record& record) : gr(record) { }
105 SerialHelper(const SerialHelper& other) { gr = other.gr; }
106 virtual ~SerialHelper() { }
107
108 // load the function type name as given in the record's "functype"
109 // field into the given String <em>ftype</em>. <em>gr</em> is the
110 // record to extract from. False is returned if the record
111 // does not contain this field.
112 // <thrown>
113 // <li> InvalidSerializationError if "functype" exists but is
114 // empty or the incorrect type
115 // </thrown>
116 Bool getFuncType(String& ftype) const;
117
118 // ensure that the Function type stored in the given record, <em>gr</em>,
119 // matches <em>ftype</em>. If it does not, an
120 // InvalidSerializationError is thrown.
121 void checkFuncType(const String& ftype) const;
122
123 // return True if a field with the given <em>name</em> exists
124 Bool exists(const String &name) const { return gr.isDefined(name); }
125
126 // Get the <em>index</em>th element of the <em>name</em> field
127 // This should be
128 // particularly useful for Array objects with only one element,
129 // i.e. a <em>scalar</em>.
130 // Note that unlike the native classes, indexing is zero-relative.
131 //
132 // InvalidSerializationError is thrown if:
133 // <ul>
134 // <li> if the given record does not contain a field called <em>name</em>
135 // <li> if the field is not a vector of the correct type.
136 // <li> if the index is out of range.
137 // </ul>
138 // <group>
139 void get(Bool &val, const String& name, uInt index = 0) const;
140// void get(uChar &val, const String& name, uInt index = 0) const;
141 void get(Short &val, const String& name, uInt index = 0) const;
142 void get(Int &val, const String& name, uInt index = 0) const;
143 void get(Float &val, const String& name, uInt index = 0) const;
144 void get(Double &val, const String& name, uInt index = 0) const;
145 void get(Complex &val, const String& name, uInt index = 0) const;
146 void get(DComplex &val, const String& name, uInt index = 0) const;
147 void get(String &val, const String& name, uInt index = 0) const;
148 void get(Record &val, const String& name) const;
149 // </group>
150
151 // Get the <em>index</em>th element of the <em>name</em> field
152 // This should be
153 // particularly useful for Array objects with only one element,
154 // i.e. a <em>scalar</em>.
155 // Note that unlike the native classes, indexing is zero-relative.
156 //
157 // InvalidSerializationError is thrown if:
158 // <ul>
159 // <li> if the given record does not contain a field called <em>name</em>
160 // <li> if the field is not a vector of the correct type.
161 // <li> if the index is out of range.
162 // </ul>
163 // <group>
164 void get(Array<Bool> &val, const String& name) const;
165// void get(Array<uChar &val, const String& name) const;
166 void get(Array<Short> &val, const String& name) const;
167 void get(Array<Int> &val, const String& name) const;
168 void get(Array<Float> &val, const String& name) const;
169 void get(Array<Double> &val, const String& name) const;
170 void get(Array<Complex> &val, const String& name) const;
171 void get(Array<DComplex> &val, const String& name) const;
172 void get(Array<String> &val, const String& name) const;
173 // </group>
174
176 gr = other.gr;
177 return *this;
178 }
179
180protected:
182
183private:
184
186};
187
188
189} //# NAMESPACE CASACORE - END
190
191#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
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:223
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:46
unsigned int uInt
Definition aipstype.h:49
float Float
Definition aipstype.h:52
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