21 #include "FitsError.h"
31 class KeyData :
public Keyword
35 KeyData(
const KeyData< T > &right);
36 KeyData (
const String &keyname,
ValueType keytype,
const T &value, HDU* p,
37 const String &comment =
"");
40 virtual KeyData <T>* clone ()
const;
41 virtual void write ();
42 const T& keyval ()
const;
43 void keyval (
const T& value);
48 virtual void copy (
const Keyword& right);
49 virtual bool compare (
const Keyword &right)
const;
50 virtual std::ostream & put (std::ostream &s)
const;
64 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
66 inline void KeyData<String>::write()
70 if (fits_update_key(fitsPointer(), Tstring,
71 const_cast<char *>(name().c_str()),
72 const_cast<char*>(m_keyval.c_str()),
73 const_cast<char *>(comment().c_str()),
74 &status))
throw FitsError(status);
78 template<>
void KeyData<String>::write();
81 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
83 inline void KeyData<bool>::write()
88 if (m_keyval) value=1;
89 if (fits_update_key(fitsPointer(), Tlogical,
90 const_cast<char *>(name().c_str()),
92 const_cast<char *>(comment().c_str()),
93 &status))
throw FitsError(status);
97 template<>
void KeyData<bool>::write();
100 #ifdef SPEC_TEMPLATE_DECL_DEFECT
102 inline const String& KeyData<String>::keyval()
const
108 template<>
const String& KeyData<String>::keyval()
const;
111 #ifndef SPEC_TEMPLATE_DECL_DEFECT
112 template<>
void KeyData<String>::keyval(
const String& );
115 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
117 inline std::ostream & KeyData<String>::put (std::ostream &s)
const
120 s <<
"Keyword Name: " << setw(10) << name() <<
" Value: " << setw(14)
121 << keyval() <<
" Type: " << setw(20) <<
" string " <<
" Comment: " << comment();
126 template<> std::ostream& KeyData<String>::put(std::ostream& s)
const;
130 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
132 inline std::ostream & KeyData<bool>::put (std::ostream &s)
const
135 s <<
"Keyword Name: " << setw(10) << name()
136 <<
" Value: " << std::boolalpha << setw(8) << keyval()
137 <<
" Type: " << setw(20) <<
" logical " <<
" Comment: " << comment();
142 template<> std::ostream& KeyData<bool>::put(std::ostream& s)
const;
145 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
147 inline void KeyData<std::complex<float> >::write()
151 FITSUtil::auto_array_ptr<float> keyVal(
new float[2]);
152 keyVal[0] = m_keyval.real();
153 keyVal[1] = m_keyval.imag();
154 if (fits_update_key(fitsPointer(), Tcomplex,
155 const_cast<char *>(name().c_str()),
157 const_cast<char *>(comment().c_str()),
158 &status))
throw FitsError(status);
162 template<>
void KeyData<std::complex<float> >::write();
165 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
167 inline void KeyData<std::complex<double> >::write()
171 FITSUtil::auto_array_ptr<double> keyVal(
new double[2]);
172 keyVal[0] = m_keyval.real();
173 keyVal[1] = m_keyval.imag();
174 if (fits_update_key(fitsPointer(), Tdblcomplex,
175 const_cast<char *>(name().c_str()),
177 const_cast<char *>(comment().c_str()),
178 &status))
throw FitsError(status);
182 template<>
void KeyData<std::complex<double> >::write();
185 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
187 inline std::ostream & KeyData<std::complex<float> >::put (std::ostream &s)
const
190 s <<
"Keyword Name: " << name() <<
" Value: " << m_keyval.real() <<
" + i "
191 << m_keyval.imag() <<
" Type: " << setw(20) <<
" complex<float> "
192 <<
" Comment: " << comment() << std::endl;
197 inline std::ostream & KeyData<std::complex<double> >::put (std::ostream &s)
const
200 s <<
"Keyword Name: " << name() <<
" Value: " << m_keyval.real() <<
" + i "
201 << m_keyval.imag() <<
" Type: " << setw(20) <<
" complex<double> "
202 <<
" Comment: " << comment() << std::endl;
207 template<> std::ostream& KeyData<std::complex<float> >::put(std::ostream& s)
const;
208 template<> std::ostream& KeyData<std::complex<double> >::put(std::ostream& s)
const;
211 #ifdef SPEC_TEMPLATE_DECL_DEFECT
213 inline const std::complex<float>& KeyData<std::complex<float> >::keyval()
const
220 inline void KeyData<std::complex<float> >::keyval(
const std::complex<float>& newVal)
227 inline const std::complex<double>& KeyData<std::complex<double> >::keyval()
const
234 inline void KeyData<std::complex<double> >::keyval(
const std::complex<double>& newVal)
241 template<>
const std::complex<float>& KeyData<std::complex<float> >::keyval()
const;
242 template<>
void KeyData<std::complex<float> >::keyval(
const std::complex<float>& );
246 template<>
const std::complex<double>& KeyData<std::complex<double> >::keyval()
const;
247 template<>
void KeyData<std::complex<double> >::keyval(
const std::complex<double>& );
252 template <
typename T>
253 inline std::ostream & KeyData<T>::put (std::ostream &s)
const
255 s <<
"Keyword Name: " << name() <<
"\t Value: " << keyval() <<
256 "\t Type: " << keytype() <<
"\t Comment: " << comment();
261 template <
typename T>
262 inline const T& KeyData<T>::keyval ()
const
267 template <
typename T>
268 inline void KeyData<T>::keyval (
const T& value)
275 template <
typename T>
276 KeyData<T>::KeyData(
const KeyData<T> &right)
278 m_keyval(right.m_keyval)
282 template <
typename T>
283 KeyData<T>::KeyData (
const String &keyname,
ValueType keytype,
const T &value, HDU* p,
const String &comment)
284 : Keyword(keyname, keytype, p, comment),
290 template <
typename T>
291 KeyData<T>::~KeyData()
296 template <
typename T>
297 void KeyData<T>::copy (
const Keyword& right)
299 Keyword::copy(right);
300 const KeyData<T>& that =
static_cast<const KeyData<T>&
>(right);
301 m_keyval = that.m_keyval;
304 template <
typename T>
305 bool KeyData<T>::compare (
const Keyword &right)
const
307 if ( !Keyword::compare(right) )
return false;
308 const KeyData<T>& that =
static_cast<const KeyData<T>&
>(right);
309 if (this->m_keyval != that.m_keyval)
return false;
313 template <
typename T>
314 KeyData <T>* KeyData<T>::clone ()
const
316 return new KeyData<T>(*
this);
319 template <
typename T>
320 void KeyData<T>::write ()
324 FITSUtil::MatchType<T> keyType;
325 if ( fits_update_key(fitsPointer(),keyType(),
326 const_cast<char *>(name().c_str()),
328 const_cast<char *>(comment().c_str()),
329 &status) )
throw FitsError(status);