casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 template<class T> class Array;
39 
40 template <class V>
41 void getArrayVal(V &val, int type, const Record& gr,
42  const String& name, uInt index=0);
43 
44 template <class V>
45 void getArray(Array<V> &val, int type, const Record& gr,
46  const String& name);
47 
48 // <summary>
49 //
50 //
51 //
52 //
53 //
54 // </summary>
55 
56 // <use visibility=export>
57 
58 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
59 // </reviewed>
60 
61 // <prerequisite>
62 // <li> FunctionFactory
63 // </prerequisite>
64 //
65 // <etymology>
66 //
67 //
68 // </etymology>
69 //
70 // <synopsis>
71 //
72 //
73 //
74 //
75 // </synopsis>
76 //
77 // <example>
78 //
79 //
80 //
81 // </example>
82 //
83 // <motivation>
84 //
85 //
86 //
87 // </motivation>
88 //
89 // <thrown>
90 // <li> InvalidSerializationError by getFuncType() if Record
91 // does not contain a "functype" field containing a string.
92 // <li> InvalidSerializationError
93 // </thrown>
94 //
95 // <todo asof="yyyy/mm/dd">
96 // <li>
97 // <li>
98 // <li>
99 // </todo>
100 
102 public:
103  static const String FUNCTYPE;
104  static const String gtype[];
107 
108  SerialHelper(const Record& record) : gr(record) { }
109  SerialHelper(const SerialHelper& other) { gr = other.gr; }
110  virtual ~SerialHelper() { }
111 
112  // load the function type name as given in the record's "functype"
113  // field into the given String <em>ftype</em>. <em>gr</em> is the
114  // record to extract from. False is returned if the record
115  // does not contain this field.
116  // <thrown>
117  // <li> InvalidSerializationError if "functype" exists but is
118  // empty or the incorrect type
119  // </thrown>
120  Bool getFuncType(String& ftype) const;
121 
122  // ensure that the Function type stored in the given record, <em>gr</em>,
123  // matches <em>ftype</em>. If it does not, an
124  // InvalidSerializationError is thrown.
125  void checkFuncType(const String& ftype) const;
126 
127  // return True if a field with the given <em>name</em> exists
128  Bool exists(const String &name) const { return gr.isDefined(name); }
129 
130  // Get the <em>index</em>th element of the <em>name</em> field
131  // This should be
132  // particularly useful for Array objects with only one element,
133  // i.e. a <em>scalar</em>.
134  // Note that unlike the native classes, indexing is zero-relative.
135  //
136  // InvalidSerializationError is thrown if:
137  // <ul>
138  // <li> if the given record does not contain a field called <em>name</em>
139  // <li> if the field is not a vector of the correct type.
140  // <li> if the index is out of range.
141  // </ul>
142  // <group>
143  void get(Bool &val, const String& name, uInt index = 0) const;
144 // void get(uChar &val, const String& name, uInt index = 0) const;
145  void get(Short &val, const String& name, uInt index = 0) const;
146  void get(Int &val, const String& name, uInt index = 0) const;
147  void get(Float &val, const String& name, uInt index = 0) const;
148  void get(Double &val, const String& name, uInt index = 0) const;
149  void get(Complex &val, const String& name, uInt index = 0) const;
150  void get(DComplex &val, const String& name, uInt index = 0) const;
151  void get(String &val, const String& name, uInt index = 0) const;
152  void get(Record &val, const String& name) const;
153  // </group>
154 
155  // Get the <em>index</em>th element of the <em>name</em> field
156  // This should be
157  // particularly useful for Array objects with only one element,
158  // i.e. a <em>scalar</em>.
159  // Note that unlike the native classes, indexing is zero-relative.
160  //
161  // InvalidSerializationError is thrown if:
162  // <ul>
163  // <li> if the given record does not contain a field called <em>name</em>
164  // <li> if the field is not a vector of the correct type.
165  // <li> if the index is out of range.
166  // </ul>
167  // <group>
168  void get(Array<Bool> &val, const String& name) const;
169 // void get(Array<uChar &val, const String& name) const;
170  void get(Array<Short> &val, const String& name) const;
171  void get(Array<Int> &val, const String& name) const;
172  void get(Array<Float> &val, const String& name) const;
173  void get(Array<Double> &val, const String& name) const;
174  void get(Array<Complex> &val, const String& name) const;
175  void get(Array<DComplex> &val, const String& name) const;
176  void get(Array<String> &val, const String& name) const;
177  // </group>
178 
180  gr = other.gr;
181  return *this;
182  }
183 
184 protected:
186 
187 private:
188 
190 };
191 
192 
193 } //# NAMESPACE CASACORE - END
194 
195 #endif
int Int
Definition: aipstype.h:50
static const String gtype[]
Definition: SerialHelper.h:104
SerialHelper(const Record &record)
Definition: SerialHelper.h:108
virtual casacore::String type() const
Implements RegionShape::type.
Definition: RegionShapes.h:548
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
void checkFuncType(const String &ftype) const
ensure that the Function type stored in the given record, gr, matches ftype.
SerialHelper(const SerialHelper &other)
Definition: SerialHelper.h:109
short Short
Definition: aipstype.h:48
SerialHelper & operator=(const SerialHelper &other)
Definition: SerialHelper.h:179
Bool exists(const String &name) const
return True if a field with the given name exists
Definition: SerialHelper.h:128
double Double
Definition: aipstype.h:55
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Bool isDefined(const String &fieldName) const
Test if a field name exists.
float Float
Definition: aipstype.h:54
void getArrayVal(V &val, int type, const Record &gr, const String &name, uInt index=0)
static const String FUNCTYPE
Definition: SerialHelper.h:103
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void getArray(Array< V > &val, int type, const Record &gr, const String &name)
Bool getFuncType(String &ftype) const
load the function type name as given in the record&#39;s &quot;functype&quot; field into the given String ftype...
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42