00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef KEYDATA_H
00011 #define KEYDATA_H 1
00012 #ifdef _MSC_VER
00013 #include "MSconfig.h"
00014 #endif
00015
00016 #include "CCfits.h"
00017
00018
00019 #include "Keyword.h"
00020 #include <complex>
00021 #include <iomanip>
00022 #include "FitsError.h"
00023 #include "FITSUtil.h"
00024
00025
00026 namespace CCfits {
00027
00028
00029
00030
00031 template <typename T>
00032 class KeyData : public Keyword
00033 {
00034
00035 public:
00036 KeyData(const KeyData< T > &right);
00037 KeyData (const String &keyname, ValueType keytype, const T &value, HDU* p,
00038 const String &comment = "");
00039 virtual ~KeyData();
00040
00041 virtual KeyData <T>* clone () const;
00042 virtual void write ();
00043 const T& keyval () const;
00044 void keyval (const T& value);
00045
00046
00047
00048 protected:
00049 virtual void copy (const Keyword& right);
00050 virtual bool compare (const Keyword &right) const;
00051 virtual std::ostream & put (std::ostream &s) const;
00052
00053
00054
00055 private:
00056
00057 T m_keyval;
00058
00059
00060
00061 private:
00062
00063
00064 };
00065 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
00066 template<>
00067 inline void KeyData<String>::write()
00068 {
00069 int status = 0;
00070 if (fits_update_key(fitsPointer(), Tstring,
00071 const_cast<char *>(name().c_str()),
00072 const_cast<char*>(m_keyval.c_str()),
00073 const_cast<char *>(comment().c_str()),
00074 &status)) throw FitsError(status);
00075
00076 }
00077 #else
00078 template<> void KeyData<String>::write();
00079 #endif
00080
00081 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
00082 template<>
00083 inline void KeyData<bool>::write()
00084 {
00085 int status = 0;
00086 int value(0);
00087 if (m_keyval) value=1;
00088 if (fits_update_key(fitsPointer(), Tlogical,
00089 const_cast<char *>(name().c_str()),
00090 &value,
00091 const_cast<char *>(comment().c_str()),
00092 &status)) throw FitsError(status);
00093
00094 }
00095 #else
00096 template<> void KeyData<bool>::write();
00097 #endif
00098
00099 #ifdef SPEC_TEMPLATE_DECL_DEFECT
00100 template <>
00101 inline const String& KeyData<String>::keyval() const
00102 {
00103 return m_keyval;
00104
00105 }
00106 #else
00107 template<> const String& KeyData<String>::keyval() const;
00108 #endif
00109
00110 #ifndef SPEC_TEMPLATE_DECL_DEFECT
00111 template<> void KeyData<String>::keyval(const String& );
00112 #endif
00113
00114 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
00115 template <>
00116 inline std::ostream & KeyData<String>::put (std::ostream &s) const
00117 {
00118 using std::setw;
00119 s << "Keyword Name: " << setw(10) << name() << " Value: " << setw(14)
00120 << keyval() << " Type: " << setw(20) << " string " << " Comment: " << comment();
00121 return s;
00122 }
00123
00124 #else
00125 template<> std::ostream& KeyData<String>::put(std::ostream& s) const;
00126 #endif
00127
00128
00129 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
00130 template <>
00131 inline std::ostream & KeyData<bool>::put (std::ostream &s) const
00132 {
00133 using std::setw;
00134 s << "Keyword Name: " << setw(10) << name()
00135 << " Value: " << std::boolalpha << setw(8) << keyval()
00136 << " Type: " << setw(20) << " logical " << " Comment: " << comment();
00137 return s;
00138 }
00139
00140 #else
00141 template<> std::ostream& KeyData<bool>::put(std::ostream& s) const;
00142 #endif
00143
00144 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
00145 template<>
00146 inline void KeyData<std::complex<float> >::write()
00147 {
00148 int status = 0;
00149 FITSUtil::auto_array_ptr<float> keyVal( new float[2]);
00150 keyVal[0] = m_keyval.real();
00151 keyVal[1] = m_keyval.imag();
00152 if (fits_update_key(fitsPointer(), Tcomplex,
00153 const_cast<char *>(name().c_str()),
00154 keyVal.get(),
00155 const_cast<char *>(comment().c_str()),
00156 &status)) throw FitsError(status);
00157
00158 }
00159 #else
00160 template<> void KeyData<std::complex<float> >::write();
00161 #endif
00162
00163 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
00164 template<>
00165 inline void KeyData<std::complex<double> >::write()
00166 {
00167 int status = 0;
00168 FITSUtil::auto_array_ptr<double> keyVal(new double[2]);
00169 keyVal[0] = m_keyval.real();
00170 keyVal[1] = m_keyval.imag();
00171 if (fits_update_key(fitsPointer(), Tdblcomplex,
00172 const_cast<char *>(name().c_str()),
00173 keyVal.get(),
00174 const_cast<char *>(comment().c_str()),
00175 &status)) throw FitsError(status);
00176
00177 }
00178 #else
00179 template<> void KeyData<std::complex<double> >::write();
00180 #endif
00181
00182 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
00183 template <>
00184 inline std::ostream & KeyData<std::complex<float> >::put (std::ostream &s) const
00185 {
00186 using std::setw;
00187 s << "Keyword Name: " << name() << " Value: " << m_keyval.real() << " + i "
00188 << m_keyval.imag() << " Type: " << setw(20) << " complex<float> "
00189 << " Comment: " << comment() << std::endl;
00190 return s;
00191 }
00192
00193 template <>
00194 inline std::ostream & KeyData<std::complex<double> >::put (std::ostream &s) const
00195 {
00196 using std::setw;
00197 s << "Keyword Name: " << name() << " Value: " << m_keyval.real() << " + i "
00198 << m_keyval.imag() << " Type: " << setw(20) << " complex<double> "
00199 << " Comment: " << comment() << std::endl;
00200
00201 return s;
00202 }
00203 #else
00204 template<> std::ostream& KeyData<std::complex<float> >::put(std::ostream& s) const;
00205 template<> std::ostream& KeyData<std::complex<double> >::put(std::ostream& s) const;
00206 #endif
00207
00208 #ifdef SPEC_TEMPLATE_DECL_DEFECT
00209 template <>
00210 inline const std::complex<float>& KeyData<std::complex<float> >::keyval() const
00211 {
00212 return m_keyval;
00213
00214 }
00215
00216 template <>
00217 inline void KeyData<std::complex<float> >::keyval(const std::complex<float>& newVal)
00218 {
00219 m_keyval = newVal;
00220
00221 }
00222
00223 template <>
00224 inline const std::complex<double>& KeyData<std::complex<double> >::keyval() const
00225 {
00226 return m_keyval;
00227
00228 }
00229
00230 template <>
00231 inline void KeyData<std::complex<double> >::keyval(const std::complex<double>& newVal)
00232 {
00233 m_keyval = newVal;
00234
00235 }
00236
00237 #else
00238 template<> const std::complex<float>& KeyData<std::complex<float> >::keyval() const;
00239 template<> void KeyData<std::complex<float> >::keyval(const std::complex<float>& );
00240
00241
00242
00243 template<> const std::complex<double>& KeyData<std::complex<double> >::keyval() const;
00244 template<> void KeyData<std::complex<double> >::keyval(const std::complex<double>& );
00245 #endif
00246
00247
00248
00249 template <typename T>
00250 inline std::ostream & KeyData<T>::put (std::ostream &s) const
00251 {
00252 s << "Keyword Name: " << name() << "\t Value: " << keyval() <<
00253 "\t Type: " << keytype() << "\t Comment: " << comment();
00254
00255 return s;
00256 }
00257
00258 template <typename T>
00259 inline const T& KeyData<T>::keyval () const
00260 {
00261 return m_keyval;
00262 }
00263
00264 template <typename T>
00265 inline void KeyData<T>::keyval (const T& value)
00266 {
00267 m_keyval = value;
00268 }
00269
00270
00271
00272 template <typename T>
00273 KeyData<T>::KeyData(const KeyData<T> &right)
00274 :Keyword(right),
00275 m_keyval(right.m_keyval)
00276 {
00277 }
00278
00279 template <typename T>
00280 KeyData<T>::KeyData (const String &keyname, ValueType keytype, const T &value, HDU* p, const String &comment)
00281 : Keyword(keyname, keytype, p, comment),
00282 m_keyval(value)
00283 {
00284 }
00285
00286
00287 template <typename T>
00288 KeyData<T>::~KeyData()
00289 {
00290 }
00291
00292
00293 template <typename T>
00294 void KeyData<T>::copy (const Keyword& right)
00295 {
00296 Keyword::copy(right);
00297 const KeyData<T>& that = static_cast<const KeyData<T>&>(right);
00298 m_keyval = that.m_keyval;
00299 }
00300
00301 template <typename T>
00302 bool KeyData<T>::compare (const Keyword &right) const
00303 {
00304 if ( !Keyword::compare(right) ) return false;
00305 const KeyData<T>& that = static_cast<const KeyData<T>&>(right);
00306 if (this->m_keyval != that.m_keyval) return false;
00307 return true;
00308 }
00309
00310 template <typename T>
00311 KeyData <T>* KeyData<T>::clone () const
00312 {
00313 return new KeyData<T>(*this);
00314 }
00315
00316 template <typename T>
00317 void KeyData<T>::write ()
00318 {
00319 int status = 0;
00320 FITSUtil::MatchType<T> keyType;
00321 if ( fits_update_key(fitsPointer(),keyType(),
00322 const_cast<char *>(name().c_str()),
00323 &m_keyval,
00324 const_cast<char *>(comment().c_str()),
00325 &status) ) throw FitsError(status);
00326 }
00327
00328
00329
00330 }
00331
00332
00333 #endif