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