KeyData.h

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

Generated on Thu Jun 28 11:49:08 2007 for CCfits by  doxygen 1.4.7