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