-
Notifications
You must be signed in to change notification settings - Fork 1
/
KeyData.h
346 lines (280 loc) · 9.2 KB
/
KeyData.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
// Astrophysics Science Division,
// NASA/ Goddard Space Flight Center
// HEASARC
// http://heasarc.gsfc.nasa.gov
// e-mail: [email protected]
//
// Original author: Ben Dorman
#ifndef KEYDATA_H
#define KEYDATA_H 1
#ifdef _MSC_VER
#include "MSconfig.h"
#endif
#include "CCfits.h"
// Keyword
#include "Keyword.h"
#include <complex>
#include <iomanip>
#include "FitsError.h"
#include "FITSUtil.h"
namespace CCfits {
//class Keyword;
template <typename T>
class KeyData : public Keyword //## Inherits: <unnamed>%381F43399D58
{
public:
KeyData (const KeyData< T > &right);
KeyData (const String &keyname,
ValueType keytype,
const T &value,
HDU* p, // A pointer to the HDU containing the keyword. This is passed to the base class constructor.
const String &comment = "",
bool isLongStr = false);
virtual ~KeyData();
virtual KeyData <T>* clone () const;
virtual void write ();
const T& keyval () const;
void keyval (const T& value);
// Additional Public Declarations
protected:
virtual void copy (const Keyword& right);
virtual bool compare (const Keyword &right) const;
virtual std::ostream & put (std::ostream &s) const;
// Additional Protected Declarations
private:
// Data Members for Class Attributes
T m_keyval;
// Additional Private Declarations
private: //## implementation
// Additional Implementation Declarations
};
#if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
template<>
inline void KeyData<String>::write()
{
Keyword::write();
int status = 0;
if (fits_update_key(fitsPointer(), Tstring,
const_cast<char *>(name().c_str()),
const_cast<char*>(m_keyval.c_str()),
const_cast<char *>(comment().c_str()),
&status)) throw FitsError(status);
}
#else
template<> void KeyData<String>::write();
#endif
#if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
template<>
inline void KeyData<bool>::write()
{
Keyword::write();
int status = 0;
int value(0);
if (m_keyval) value=1;
if (fits_update_key(fitsPointer(), Tlogical,
const_cast<char *>(name().c_str()),
&value,
const_cast<char *>(comment().c_str()),
&status)) throw FitsError(status);
}
#else
template<> void KeyData<bool>::write();
#endif
#ifdef SPEC_TEMPLATE_DECL_DEFECT
template <>
inline const String& KeyData<String>::keyval() const
{
return m_keyval;
}
#else
template<> const String& KeyData<String>::keyval() const;
#endif
#ifndef SPEC_TEMPLATE_DECL_DEFECT
template<> void KeyData<String>::keyval(const String& );
#endif
#if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
template <>
inline std::ostream & KeyData<String>::put (std::ostream &s) const
{
using std::setw;
s << "Keyword Name: " << setw(10) << name() << " Value: " << setw(14)
<< keyval() << " Type: " << setw(20) << " string " << " Comment: " << comment();
return s;
}
#else
template<> std::ostream& KeyData<String>::put(std::ostream& s) const;
#endif
#if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
template <>
inline std::ostream & KeyData<bool>::put (std::ostream &s) const
{
using std::setw;
s << "Keyword Name: " << setw(10) << name()
<< " Value: " << std::boolalpha << setw(8) << keyval()
<< " Type: " << setw(20) << " logical " << " Comment: " << comment();
return s;
}
#else
template<> std::ostream& KeyData<bool>::put(std::ostream& s) const;
#endif
#if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
template<>
inline void KeyData<std::complex<float> >::write()
{
Keyword::write();
int status = 0;
FITSUtil::auto_array_ptr<float> keyVal( new float[2]);
keyVal[0] = m_keyval.real();
keyVal[1] = m_keyval.imag();
if (fits_update_key(fitsPointer(), Tcomplex,
const_cast<char *>(name().c_str()),
keyVal.get(),
const_cast<char *>(comment().c_str()),
&status)) throw FitsError(status);
}
#else
template<> void KeyData<std::complex<float> >::write();
#endif
#if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
template<>
inline void KeyData<std::complex<double> >::write()
{
Keyword::write();
int status = 0;
FITSUtil::auto_array_ptr<double> keyVal(new double[2]);
keyVal[0] = m_keyval.real();
keyVal[1] = m_keyval.imag();
if (fits_update_key(fitsPointer(), Tdblcomplex,
const_cast<char *>(name().c_str()),
keyVal.get(),
const_cast<char *>(comment().c_str()),
&status)) throw FitsError(status);
}
#else
template<> void KeyData<std::complex<double> >::write();
#endif
#if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
template <>
inline std::ostream & KeyData<std::complex<float> >::put (std::ostream &s) const
{
using std::setw;
s << "Keyword Name: " << name() << " Value: " << m_keyval.real() << " + i "
<< m_keyval.imag() << " Type: " << setw(20) << " complex<float> "
<< " Comment: " << comment() << std::endl;
return s;
}
template <>
inline std::ostream & KeyData<std::complex<double> >::put (std::ostream &s) const
{
using std::setw;
s << "Keyword Name: " << name() << " Value: " << m_keyval.real() << " + i "
<< m_keyval.imag() << " Type: " << setw(20) << " complex<double> "
<< " Comment: " << comment() << std::endl;
return s;
}
#else
template<> std::ostream& KeyData<std::complex<float> >::put(std::ostream& s) const;
template<> std::ostream& KeyData<std::complex<double> >::put(std::ostream& s) const;
#endif
#ifdef SPEC_TEMPLATE_DECL_DEFECT
template <>
inline const std::complex<float>& KeyData<std::complex<float> >::keyval() const
{
return m_keyval;
}
template <>
inline void KeyData<std::complex<float> >::keyval(const std::complex<float>& newVal)
{
m_keyval = newVal;
}
template <>
inline const std::complex<double>& KeyData<std::complex<double> >::keyval() const
{
return m_keyval;
}
template <>
inline void KeyData<std::complex<double> >::keyval(const std::complex<double>& newVal)
{
m_keyval = newVal;
}
#else
template<> const std::complex<float>& KeyData<std::complex<float> >::keyval() const;
template<> void KeyData<std::complex<float> >::keyval(const std::complex<float>& );
template<> const std::complex<double>& KeyData<std::complex<double> >::keyval() const;
template<> void KeyData<std::complex<double> >::keyval(const std::complex<double>& );
#endif
// Parameterized Class CCfits::KeyData
template <typename T>
inline std::ostream & KeyData<T>::put (std::ostream &s) const
{
s << "Keyword Name: " << name() << "\t Value: " << keyval() <<
"\t Type: " << keytype() << "\t Comment: " << comment();
return s;
}
template <typename T>
inline const T& KeyData<T>::keyval () const
{
return m_keyval;
}
template <typename T>
inline void KeyData<T>::keyval (const T& value)
{
m_keyval = value;
}
// Parameterized Class CCfits::KeyData
template <typename T>
KeyData<T>::KeyData(const KeyData<T> &right)
:Keyword(right),
m_keyval(right.m_keyval)
{
}
template <typename T>
KeyData<T>::KeyData (const String &keyname,
ValueType keytype,
const T &value,
HDU* p,
const String &comment,
bool isLongStr)
: Keyword(keyname, keytype, p, comment, isLongStr),
m_keyval(value)
{
}
template <typename T>
KeyData<T>::~KeyData()
{
}
template <typename T>
void KeyData<T>::copy (const Keyword& right)
{
Keyword::copy(right);
const KeyData<T>& that = static_cast<const KeyData<T>&>(right);
m_keyval = that.m_keyval;
}
template <typename T>
bool KeyData<T>::compare (const Keyword &right) const
{
if ( !Keyword::compare(right) ) return false;
const KeyData<T>& that = static_cast<const KeyData<T>&>(right);
if (this->m_keyval != that.m_keyval) return false;
return true;
}
template <typename T>
KeyData <T>* KeyData<T>::clone () const
{
return new KeyData<T>(*this);
}
template <typename T>
void KeyData<T>::write ()
{
Keyword::write();
int status = 0;
FITSUtil::MatchType<T> keyType;
if ( fits_update_key(fitsPointer(),keyType(),
const_cast<char *>(name().c_str()),
&m_keyval, // fits_write_key takes a void* here
const_cast<char *>(comment().c_str()),
&status) ) throw FitsError(status);
}
// Additional Declarations
} // namespace CCfits
#endif