CCfits: KeyData.h Source File

CCfits 2.7

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List

KeyData.h

    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,
    00037                  ValueType keytype,
    00038                  const T &value,
    00039                  HDU* p,    // A pointer to the HDU containing the keyword. This is passed to the base class constructor.
    00040                  const String &comment = "",
    00041                  bool isLongStr = false);
    00042         virtual ~KeyData();
    00043
    00044         virtual KeyData <T>* clone () const;
    00045         virtual void write ();
    00046         const T& keyval () const;
    00047         void keyval (const T& value);
    00048
    00049       // Additional Public Declarations
    00050
    00051     protected:
    00052         virtual void copy (const Keyword& right);
    00053         virtual bool compare (const Keyword &right) const;
    00054         virtual std::ostream & put (std::ostream &s) const;
    00055
    00056       // Additional Protected Declarations
    00057
    00058     private:
    00059       // Data Members for Class Attributes
    00060         T m_keyval;
    00061
    00062       // Additional Private Declarations
    00063
    00064     private: //## implementation
    00065       // Additional Implementation Declarations
    00066
    00067   };
    00068
    00069   class KeyNull : public Keyword
    00070   {
    00071    public:
    00072         enum class ValState {Empty, NumData, StrData};
    00073         KeyNull (const KeyNull &right);
    00074         KeyNull (const String &keyname,
    00075                  HDU* p,
    00076                  const String &comment = "");
    00077         virtual ~KeyNull();
    00078         virtual KeyNull* clone () const;
    00079         virtual void write ();
    00080         double numValue() const;
    00081         string stringValue() const;
    00082         ValState state() const;
    00083         void setStringValue(const string& val);
    00084         void setNumValue(double val, ValueType writeAs);
    00085    protected:
    00086         virtual void copy (const Keyword& right);
    00087         virtual bool compare (const Keyword &right) const;
    00088         virtual std::ostream & put (std::ostream &s) const;
    00089    private:
    00090         double m_numValue;
    00091         string m_stringValue;
    00092         ValState m_state;
    00093         ValueType m_writeAs;
    00094   };
    00095
    00096 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
    00097         template<>
    00098         inline void KeyData<String>::write()
    00099         {
    00100            Keyword::write();
    00101            int status = 0;
    00102            if (fits_update_key(fitsPointer(), Tstring,
    00103                        const_cast<char *>(name().c_str()),
    00104                        const_cast<char*>(m_keyval.c_str()),
    00105                        const_cast<char *>(comment().c_str()),
    00106                        &status)) throw FitsError(status);
    00107
    00108         }
    00109 #else
    00110 template<> void KeyData<String>::write();
    00111 #endif
    00112
    00113 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
    00114         template<>
    00115         inline void KeyData<bool>::write()
    00116         {
    00117            Keyword::write();
    00118            int status = 0;
    00119            int value(0);
    00120            if (m_keyval) value=1;
    00121            if (fits_update_key(fitsPointer(), Tlogical,
    00122                        const_cast<char *>(name().c_str()),
    00123                        &value,
    00124                        const_cast<char *>(comment().c_str()),
    00125                        &status)) throw FitsError(status);
    00126
    00127         }
    00128 #else
    00129 template<> void KeyData<bool>::write();
    00130 #endif
    00131
    00132 #ifdef SPEC_TEMPLATE_DECL_DEFECT
    00133         template  <>
    00134         inline const String& KeyData<String>::keyval() const
    00135         {
    00136                 return m_keyval;
    00137
    00138         }
    00139 #else
    00140 template<> const String& KeyData<String>::keyval() const;
    00141 #endif
    00142
    00143 #ifndef SPEC_TEMPLATE_DECL_DEFECT
    00144 template<> void KeyData<String>::keyval(const String& );
    00145 #endif
    00146
    00147 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
    00148         template <>
    00149         inline std::ostream & KeyData<String>::put (std::ostream &s) const
    00150         {
    00151         using std::setw;
    00152         s << "Keyword Name: " << setw(10) << name() << "  Value: " << setw(14)
    00153                   << keyval() << " Type: " << setw(20) << " string "  << " Comment: " << comment();
    00154           return s;
    00155         }
    00156
    00157 #else
    00158 template<> std::ostream& KeyData<String>::put(std::ostream& s) const;
    00159 #endif
    00160
    00161
    00162 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
    00163         template <>
    00164         inline std::ostream & KeyData<bool>::put (std::ostream &s) const
    00165         {
    00166         using std::setw;
    00167         s << "Keyword Name: " << setw(10) << name()
    00168                   << "  Value: " << std::boolalpha  << setw(8) << keyval()
    00169                   << "  Type: " << setw(20) << " logical "  << " Comment: " << comment();
    00170           return s;
    00171         }
    00172
    00173 #else
    00174 template<> std::ostream& KeyData<bool>::put(std::ostream& s) const;
    00175 #endif
    00176
    00177 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
    00178         template<>
    00179         inline void KeyData<std::complex<float> >::write()
    00180         {
    00181              Keyword::write();
    00182              int status = 0;
    00183              FITSUtil::auto_array_ptr<float> keyVal( new float[2]);
    00184              keyVal[0] = m_keyval.real();
    00185              keyVal[1] = m_keyval.imag();
    00186              if (fits_update_key(fitsPointer(), Tcomplex,
    00187                        const_cast<char *>(name().c_str()),
    00188                        keyVal.get(),
    00189                        const_cast<char *>(comment().c_str()),
    00190                        &status)) throw FitsError(status);
    00191
    00192         }
    00193 #else
    00194 template<> void KeyData<std::complex<float> >::write();
    00195 #endif
    00196
    00197 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
    00198         template<>
    00199         inline void KeyData<std::complex<double> >::write()
    00200         {
    00201              Keyword::write();
    00202              int status = 0;
    00203              FITSUtil::auto_array_ptr<double> keyVal(new double[2]);
    00204              keyVal[0] = m_keyval.real();
    00205              keyVal[1] = m_keyval.imag();
    00206              if (fits_update_key(fitsPointer(), Tdblcomplex,
    00207                        const_cast<char *>(name().c_str()),
    00208                        keyVal.get(),
    00209                        const_cast<char *>(comment().c_str()),
    00210                        &status)) throw FitsError(status);
    00211
    00212         }
    00213 #else
    00214 template<> void KeyData<std::complex<double> >::write();
    00215 #endif
    00216
    00217 #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT
    00218         template <>
    00219         inline std::ostream & KeyData<std::complex<float> >::put (std::ostream &s) const
    00220         {
    00221         using std::setw;
    00222             s << "Keyword Name: " << name() << " Value: " << m_keyval.real() << " +   i "
    00223                   << m_keyval.imag() <<   " Type: " <<  setw(20) << " complex<float> "
    00224                   << " Comment: " << comment()   << std::endl;
    00225           return s;
    00226         }
    00227
    00228         template <>
    00229         inline std::ostream & KeyData<std::complex<double> >::put (std::ostream &s) const
    00230         {
    00231         using std::setw;
    00232             s << "Keyword Name: " << name() << " Value: " << m_keyval.real() << " +   i "
    00233                   << m_keyval.imag() <<   " Type: " <<  setw(20) << " complex<double> "
    00234                   << " Comment: " << comment()   << std::endl;
    00235
    00236               return s;
    00237         }
    00238 #else
    00239 template<> std::ostream& KeyData<std::complex<float> >::put(std::ostream& s) const;
    00240 template<> std::ostream& KeyData<std::complex<double> >::put(std::ostream& s) const;
    00241 #endif
    00242
    00243 #ifdef SPEC_TEMPLATE_DECL_DEFECT
    00244   template  <>
    00245   inline const std::complex<float>& KeyData<std::complex<float> >::keyval() const
    00246   {
    00247     return m_keyval;
    00248
    00249   }
    00250
    00251   template  <>
    00252   inline void KeyData<std::complex<float> >::keyval(const std::complex<float>&  newVal)
    00253   {
    00254     m_keyval = newVal;
    00255
    00256   }
    00257
    00258   template  <>
    00259   inline const std::complex<double>& KeyData<std::complex<double> >::keyval() const
    00260   {
    00261     return m_keyval;
    00262
    00263   }
    00264
    00265   template  <>
    00266   inline void KeyData<std::complex<double> >::keyval(const std::complex<double>&  newVal)
    00267   {
    00268     m_keyval = newVal;
    00269
    00270   }
    00271
    00272 #else
    00273 template<> const std::complex<float>&  KeyData<std::complex<float> >::keyval() const;
    00274 template<> void KeyData<std::complex<float> >::keyval(const std::complex<float>&  );
    00275
    00276
    00277
    00278 template<> const std::complex<double>&  KeyData<std::complex<double> >::keyval() const;
    00279 template<> void KeyData<std::complex<double> >::keyval(const std::complex<double>&  );
    00280 #endif
    00281
    00282   // Parameterized Class CCfits::KeyData
    00283
    00284   template <typename T>
    00285   inline std::ostream & KeyData<T>::put (std::ostream &s) const
    00286   {
    00287    s << "Keyword Name: " << name() << "\t Value: " << keyval() <<
    00288      "\t Type: " << keytype() << "\t Comment: " << comment();
    00289
    00290   return s;
    00291   }
    00292
    00293   template <typename T>
    00294   inline const T& KeyData<T>::keyval () const
    00295   {
    00296     return m_keyval;
    00297   }
    00298
    00299   template <typename T>
    00300   inline void KeyData<T>::keyval (const T& value)
    00301   {
    00302     m_keyval = value;
    00303   }
    00304
    00305   // Parameterized Class CCfits::KeyData
    00306
    00307   template <typename T>
    00308   KeyData<T>::KeyData(const KeyData<T> &right)
    00309       :Keyword(right),
    00310        m_keyval(right.m_keyval)
    00311   {
    00312   }
    00313
    00314   template <typename T>
    00315   KeyData<T>::KeyData (const String &keyname,
    00316                        ValueType keytype,
    00317                        const T &value,
    00318                        HDU* p,
    00319                        const String &comment,
    00320                        bool isLongStr)
    00321        : Keyword(keyname, keytype, p, comment, isLongStr),
    00322          m_keyval(value)
    00323   {
    00324   }
    00325
    00326
    00327   template <typename T>
    00328   KeyData<T>::~KeyData()
    00329   {
    00330   }
    00331
    00332
    00333   template <typename T>
    00334   void KeyData<T>::copy (const Keyword& right)
    00335   {
    00336   Keyword::copy(right);
    00337   const KeyData<T>& that = static_cast<const KeyData<T>&>(right);
    00338   m_keyval = that.m_keyval;
    00339   }
    00340
    00341   template <typename T>
    00342   bool KeyData<T>::compare (const Keyword &right) const
    00343   {
    00344   if ( !Keyword::compare(right) ) return false;
    00345   const KeyData<T>& that = static_cast<const KeyData<T>&>(right);
    00346   if (this->m_keyval != that.m_keyval) return false;
    00347   return true;
    00348   }
    00349
    00350   template <typename T>
    00351   KeyData <T>* KeyData<T>::clone () const
    00352   {
    00353   return new KeyData<T>(*this);
    00354   }
    00355
    00356   template <typename T>
    00357   void KeyData<T>::write ()
    00358   {
    00359    Keyword::write();
    00360    int status = 0;
    00361    FITSUtil::MatchType<T> keyType;
    00362    if ( fits_update_key(fitsPointer(),keyType(),
    00363                const_cast<char *>(name().c_str()),
    00364                &m_keyval,  // fits_write_key takes a void* here
    00365                const_cast<char *>(comment().c_str()),
    00366                &status) ) throw FitsError(status);
    00367   }
    00368
    00369   inline double KeyNull::numValue() const
    00370   {
    00371      return m_numValue;
    00372   }
    00373
    00374   inline string KeyNull::stringValue() const
    00375   {
    00376      return m_stringValue;
    00377   }
    00378
    00379   inline KeyNull::ValState KeyNull::state() const
    00380   {
    00381      return m_state;
    00382   }
    00383
    00384   inline void KeyNull::setNumValue(double val, ValueType writeAs)
    00385   {
    00386      m_numValue = val;
    00387      m_state = ValState::NumData;
    00388      m_writeAs = writeAs;
    00389   }
    00390
    00391   inline void KeyNull::setStringValue(const string& val)
    00392   {
    00393      m_stringValue = val;
    00394      m_state = ValState::StrData;
    00395   }
    00396
    00397   // Additional Declarations
    00398
    00399 } // namespace CCfits
    00400
    00401
    00402 #endif