KeyData.h

00001 //   Read the documentation to learn more about C++ code generator
00002 //   versioning.
00003 //      This is version 2.1 release dated Nov 2008
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
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            Keyword::write();
00072            int status = 0;
00073            if (fits_update_key(fitsPointer(), Tstring, 
00074                                    const_cast<char *>(name().c_str()),
00075                                    const_cast<char*>(m_keyval.c_str()),
00076                                    const_cast<char *>(comment().c_str()), 
00077                                    &status)) throw FitsError(status);
00078 
00079         }
00080 #else
00081 template<> void KeyData<String>::write();
00082 #endif
00083 
00084 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
00085         template<>
00086         inline void KeyData<bool>::write() 
00087         {
00088            Keyword::write();
00089            int status = 0;
00090            int value(0);
00091            if (m_keyval) value=1; 
00092            if (fits_update_key(fitsPointer(), Tlogical, 
00093                                    const_cast<char *>(name().c_str()),
00094                                    &value,
00095                                    const_cast<char *>(comment().c_str()), 
00096                                    &status)) throw FitsError(status);
00097 
00098         }
00099 #else
00100 template<> void KeyData<bool>::write();
00101 #endif
00102 
00103 #ifdef SPEC_TEMPLATE_DECL_DEFECT
00104         template  <>
00105         inline const String& KeyData<String>::keyval() const
00106         {
00107                 return m_keyval;
00108 
00109         }
00110 #else
00111 template<> const String& KeyData<String>::keyval() const;
00112 #endif
00113 
00114 #ifndef SPEC_TEMPLATE_DECL_DEFECT
00115 template<> void KeyData<String>::keyval(const String& );
00116 #endif
00117 
00118 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
00119         template <>
00120         inline std::ostream & KeyData<String>::put (std::ostream &s) const
00121         {
00122                 using std::setw;
00123                 s << "Keyword Name: " << setw(10) << name() << "  Value: " << setw(14) 
00124                   << keyval() << " Type: " << setw(20) << " string "  << " Comment: " << comment();
00125           return s;
00126         }
00127 
00128 #else
00129 template<> std::ostream& KeyData<String>::put(std::ostream& s) const;
00130 #endif
00131 
00132 
00133 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
00134         template <>
00135         inline std::ostream & KeyData<bool>::put (std::ostream &s) const
00136         {
00137                 using std::setw;
00138                 s << "Keyword Name: " << setw(10) << name() 
00139                   << "  Value: " << std::boolalpha  << setw(8) << keyval() 
00140                   << "  Type: " << setw(20) << " logical "  << " Comment: " << comment();
00141           return s;
00142         }
00143 
00144 #else
00145 template<> std::ostream& KeyData<bool>::put(std::ostream& s) const;
00146 #endif
00147 
00148 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
00149         template<>
00150         inline void KeyData<std::complex<float> >::write() 
00151         {
00152              Keyword::write();
00153              int status = 0;
00154              FITSUtil::auto_array_ptr<float> keyVal( new float[2]);
00155              keyVal[0] = m_keyval.real(); 
00156              keyVal[1] = m_keyval.imag(); 
00157              if (fits_update_key(fitsPointer(), Tcomplex, 
00158                                    const_cast<char *>(name().c_str()),
00159                                    keyVal.get(),
00160                                    const_cast<char *>(comment().c_str()), 
00161                                    &status)) throw FitsError(status);
00162 
00163         }
00164 #else
00165 template<> void KeyData<std::complex<float> >::write();
00166 #endif
00167 
00168 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
00169         template<>
00170         inline void KeyData<std::complex<double> >::write() 
00171         {
00172              Keyword::write();
00173              int status = 0;
00174              FITSUtil::auto_array_ptr<double> keyVal(new double[2]);
00175              keyVal[0] = m_keyval.real(); 
00176              keyVal[1] = m_keyval.imag(); 
00177              if (fits_update_key(fitsPointer(), Tdblcomplex, 
00178                                    const_cast<char *>(name().c_str()),
00179                                    keyVal.get(),
00180                                    const_cast<char *>(comment().c_str()), 
00181                                    &status)) throw FitsError(status);
00182 
00183         }
00184 #else
00185 template<> void KeyData<std::complex<double> >::write();
00186 #endif
00187 
00188 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
00189         template <>
00190         inline std::ostream & KeyData<std::complex<float> >::put (std::ostream &s) const
00191         {
00192                 using std::setw;
00193                 s << "Keyword Name: " << name() << " Value: " << m_keyval.real() << " +   i " 
00194                   << m_keyval.imag() <<   " Type: " <<  setw(20) << " complex<float> " 
00195                   << " Comment: " << comment()   << std::endl;
00196           return s;
00197         }
00198 
00199         template <>
00200         inline std::ostream & KeyData<std::complex<double> >::put (std::ostream &s) const
00201         {
00202                 using std::setw;
00203                 s << "Keyword Name: " << name() << " Value: " << m_keyval.real() << " +   i " 
00204                   << m_keyval.imag() <<   " Type: " <<  setw(20) << " complex<double> " 
00205                   << " Comment: " << comment()   << std::endl;
00206 
00207                   return s;
00208         }
00209 #else
00210 template<> std::ostream& KeyData<std::complex<float> >::put(std::ostream& s) const;
00211 template<> std::ostream& KeyData<std::complex<double> >::put(std::ostream& s) const;
00212 #endif
00213 
00214 #ifdef SPEC_TEMPLATE_DECL_DEFECT
00215   template  <>
00216   inline const std::complex<float>& KeyData<std::complex<float> >::keyval() const
00217   {
00218     return m_keyval;
00219 
00220   }
00221 
00222   template  <>
00223   inline void KeyData<std::complex<float> >::keyval(const std::complex<float>&  newVal)
00224   {
00225     m_keyval = newVal;
00226 
00227   }
00228 
00229   template  <>
00230   inline const std::complex<double>& KeyData<std::complex<double> >::keyval() const
00231   {
00232     return m_keyval;
00233 
00234   }
00235 
00236   template  <>
00237   inline void KeyData<std::complex<double> >::keyval(const std::complex<double>&  newVal)
00238   {
00239     m_keyval = newVal;
00240 
00241   }
00242 
00243 #else
00244 template<> const std::complex<float>&  KeyData<std::complex<float> >::keyval() const;
00245 template<> void KeyData<std::complex<float> >::keyval(const std::complex<float>&  );
00246 
00247 
00248 
00249 template<> const std::complex<double>&  KeyData<std::complex<double> >::keyval() const;
00250 template<> void KeyData<std::complex<double> >::keyval(const std::complex<double>&  );
00251 #endif
00252 
00253   // Parameterized Class CCfits::KeyData 
00254 
00255   template <typename T>
00256   inline std::ostream & KeyData<T>::put (std::ostream &s) const
00257   {
00258    s << "Keyword Name: " << name() << "\t Value: " << keyval() << 
00259      "\t Type: " << keytype() << "\t Comment: " << comment();
00260 
00261   return s;
00262   }
00263 
00264   template <typename T>
00265   inline const T& KeyData<T>::keyval () const
00266   {
00267     return m_keyval;
00268   }
00269 
00270   template <typename T>
00271   inline void KeyData<T>::keyval (const T& value)
00272   {
00273     m_keyval = value;
00274   }
00275 
00276   // Parameterized Class CCfits::KeyData 
00277 
00278   template <typename T>
00279   KeyData<T>::KeyData(const KeyData<T> &right)
00280       :Keyword(right),
00281        m_keyval(right.m_keyval)
00282   {
00283   }
00284 
00285   template <typename T>
00286   KeyData<T>::KeyData (const String &keyname, ValueType keytype, const T &value, HDU* p, const String &comment)
00287        : Keyword(keyname, keytype, p, comment), 
00288          m_keyval(value)
00289   {
00290   }
00291 
00292 
00293   template <typename T>
00294   KeyData<T>::~KeyData()
00295   {
00296   }
00297 
00298 
00299   template <typename T>
00300   void KeyData<T>::copy (const Keyword& right)
00301   {
00302   Keyword::copy(right);
00303   const KeyData<T>& that = static_cast<const KeyData<T>&>(right);
00304   m_keyval = that.m_keyval;
00305   }
00306 
00307   template <typename T>
00308   bool KeyData<T>::compare (const Keyword &right) const
00309   {
00310   if ( !Keyword::compare(right) ) return false;
00311   const KeyData<T>& that = static_cast<const KeyData<T>&>(right);
00312   if (this->m_keyval != that.m_keyval) return false;
00313   return true;
00314   }
00315 
00316   template <typename T>
00317   KeyData <T>* KeyData<T>::clone () const
00318   {
00319   return new KeyData<T>(*this);
00320   }
00321 
00322   template <typename T>
00323   void KeyData<T>::write ()
00324   {
00325    Keyword::write();
00326    int status = 0;
00327    FITSUtil::MatchType<T> keyType;
00328    if ( fits_update_key(fitsPointer(),keyType(), 
00329                            const_cast<char *>(name().c_str()),
00330                            &m_keyval,  // fits_write_key takes a void* here 
00331                            const_cast<char *>(comment().c_str()), 
00332                            &status) ) throw FitsError(status);
00333   }
00334 
00335   // Additional Declarations
00336 
00337 } // namespace CCfits
00338 
00339 
00340 #endif

Generated on Thu Nov 6 10:44:39 2008 for CCfits by  doxygen 1.5.4