// Astrophysics Science Division, // NASA/ Goddard Space Flight Center // HEASARC // http://heasarc.gsfc.nasa.gov // e-mail: ccfits@legacy.gsfc.nasa.gov // // Original author: Ben Dorman #ifndef KEYDATA_H #define KEYDATA_H 1 #ifdef _MSC_VER #include "MSconfig.h" #endif #include "CCfits.h" // Keyword #include "Keyword.h" #include #include #include "FitsError.h" #include "FITSUtil.h" namespace CCfits { //class Keyword; template class KeyData : public Keyword //## Inherits: %381F43399D58 { public: KeyData(const KeyData< T > &right); 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. const String &comment = ""); virtual ~KeyData(); virtual KeyData * clone () const; virtual void write (); const T& keyval () const; void keyval (const T& value); // Additional Public Declarations protected: virtual void copy (const Keyword& right); virtual bool compare (const Keyword &right) const; virtual std::ostream & put (std::ostream &s) const; // Additional Protected Declarations private: // Data Members for Class Attributes T m_keyval; // Additional Private Declarations private: //## implementation // Additional Implementation Declarations }; #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT template<> inline void KeyData::write() { Keyword::write(); int status = 0; if (fits_update_key(fitsPointer(), Tstring, const_cast(name().c_str()), const_cast(m_keyval.c_str()), const_cast(comment().c_str()), &status)) throw FitsError(status); } #else template<> void KeyData::write(); #endif #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT template<> inline void KeyData::write() { Keyword::write(); int status = 0; int value(0); if (m_keyval) value=1; if (fits_update_key(fitsPointer(), Tlogical, const_cast(name().c_str()), &value, const_cast(comment().c_str()), &status)) throw FitsError(status); } #else template<> void KeyData::write(); #endif #ifdef SPEC_TEMPLATE_DECL_DEFECT template <> inline const String& KeyData::keyval() const { return m_keyval; } #else template<> const String& KeyData::keyval() const; #endif #ifndef SPEC_TEMPLATE_DECL_DEFECT template<> void KeyData::keyval(const String& ); #endif #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT template <> inline std::ostream & KeyData::put (std::ostream &s) const { using std::setw; s << "Keyword Name: " << setw(10) << name() << " Value: " << setw(14) << keyval() << " Type: " << setw(20) << " string " << " Comment: " << comment(); return s; } #else template<> std::ostream& KeyData::put(std::ostream& s) const; #endif #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT template <> inline std::ostream & KeyData::put (std::ostream &s) const { using std::setw; s << "Keyword Name: " << setw(10) << name() << " Value: " << std::boolalpha << setw(8) << keyval() << " Type: " << setw(20) << " logical " << " Comment: " << comment(); return s; } #else template<> std::ostream& KeyData::put(std::ostream& s) const; #endif #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT template<> inline void KeyData >::write() { Keyword::write(); int status = 0; FITSUtil::auto_array_ptr keyVal( new float[2]); keyVal[0] = m_keyval.real(); keyVal[1] = m_keyval.imag(); if (fits_update_key(fitsPointer(), Tcomplex, const_cast(name().c_str()), keyVal.get(), const_cast(comment().c_str()), &status)) throw FitsError(status); } #else template<> void KeyData >::write(); #endif #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT template<> inline void KeyData >::write() { Keyword::write(); int status = 0; FITSUtil::auto_array_ptr keyVal(new double[2]); keyVal[0] = m_keyval.real(); keyVal[1] = m_keyval.imag(); if (fits_update_key(fitsPointer(), Tdblcomplex, const_cast(name().c_str()), keyVal.get(), const_cast(comment().c_str()), &status)) throw FitsError(status); } #else template<> void KeyData >::write(); #endif #if SPEC_TEMPLATE_IMP_DEFECT || SPEC_TEMPLATE_DECL_DEFECT template <> inline std::ostream & KeyData >::put (std::ostream &s) const { using std::setw; s << "Keyword Name: " << name() << " Value: " << m_keyval.real() << " + i " << m_keyval.imag() << " Type: " << setw(20) << " complex " << " Comment: " << comment() << std::endl; return s; } template <> inline std::ostream & KeyData >::put (std::ostream &s) const { using std::setw; s << "Keyword Name: " << name() << " Value: " << m_keyval.real() << " + i " << m_keyval.imag() << " Type: " << setw(20) << " complex " << " Comment: " << comment() << std::endl; return s; } #else template<> std::ostream& KeyData >::put(std::ostream& s) const; template<> std::ostream& KeyData >::put(std::ostream& s) const; #endif #ifdef SPEC_TEMPLATE_DECL_DEFECT template <> inline const std::complex& KeyData >::keyval() const { return m_keyval; } template <> inline void KeyData >::keyval(const std::complex& newVal) { m_keyval = newVal; } template <> inline const std::complex& KeyData >::keyval() const { return m_keyval; } template <> inline void KeyData >::keyval(const std::complex& newVal) { m_keyval = newVal; } #else template<> const std::complex& KeyData >::keyval() const; template<> void KeyData >::keyval(const std::complex& ); template<> const std::complex& KeyData >::keyval() const; template<> void KeyData >::keyval(const std::complex& ); #endif // Parameterized Class CCfits::KeyData template inline std::ostream & KeyData::put (std::ostream &s) const { s << "Keyword Name: " << name() << "\t Value: " << keyval() << "\t Type: " << keytype() << "\t Comment: " << comment(); return s; } template inline const T& KeyData::keyval () const { return m_keyval; } template inline void KeyData::keyval (const T& value) { m_keyval = value; } // Parameterized Class CCfits::KeyData template KeyData::KeyData(const KeyData &right) :Keyword(right), m_keyval(right.m_keyval) { } template KeyData::KeyData (const String &keyname, ValueType keytype, const T &value, HDU* p, const String &comment) : Keyword(keyname, keytype, p, comment), m_keyval(value) { } template KeyData::~KeyData() { } template void KeyData::copy (const Keyword& right) { Keyword::copy(right); const KeyData& that = static_cast&>(right); m_keyval = that.m_keyval; } template bool KeyData::compare (const Keyword &right) const { if ( !Keyword::compare(right) ) return false; const KeyData& that = static_cast&>(right); if (this->m_keyval != that.m_keyval) return false; return true; } template KeyData * KeyData::clone () const { return new KeyData(*this); } template void KeyData::write () { Keyword::write(); int status = 0; FITSUtil::MatchType keyType; if ( fits_update_key(fitsPointer(),keyType(), const_cast(name().c_str()), &m_keyval, // fits_write_key takes a void* here const_cast(comment().c_str()), &status) ) throw FitsError(status); } // Additional Declarations } // namespace CCfits #endif