CCfits  2.4
ExtHDU.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 EXTHDU_H
00010 #define EXTHDU_H 1
00011 
00012 // CCfitsHeader
00013 #include "CCfits.h"
00014 // HDU
00015 #include "HDU.h"
00016 // FitsError
00017 #include "FitsError.h"
00018 
00019 namespace CCfits {
00020   class Column;
00021 
00022 } // namespace CCfits
00023 
00024 
00025 namespace CCfits {
00026 
00421   class ExtHDU : public HDU  //## Inherits: <unnamed>%38048213E7A8
00422   {
00423 
00424     public:
00425 
00426 
00427 
00428       class WrongExtensionType : public FitsException  //## Inherits: <unnamed>%39E61E630349
00429       {
00430         public:
00431             WrongExtensionType (const String& msg, bool silent = true);
00432 
00433         protected:
00434         private:
00435         private: //## implementation
00436       };
00437         ExtHDU(const ExtHDU &right);
00438         virtual ~ExtHDU();
00439         friend bool operator<(const ExtHDU &left,const ExtHDU &right);
00440 
00441         friend bool operator>(const ExtHDU &left,const ExtHDU &right);
00442 
00443         friend bool operator<=(const ExtHDU &left,const ExtHDU &right);
00444 
00445         friend bool operator>=(const ExtHDU &left,const ExtHDU &right);
00446 
00447         static void readHduName (const fitsfile* fptr, int hduIndex, String& hduName, int& hduVersion);
00448         virtual void readData (bool readFlag = false, const std::vector<String>& keys = std::vector<String>()) = 0;
00449         const String& name () const;
00450         virtual HDU * clone (FITSBase* p) const = 0;
00451         //      By all means necessary, set the fitsfile pointer so that
00452         //      this HDU is the current HDU.
00453         //
00454         //      This would appear to be a good candidate for the public
00455         //      interface.
00456         virtual void makeThisCurrent () const;
00457         virtual Column& column (const String& colName, bool caseSensitive = true) const;
00458         virtual Column& column (int colIndex) const;
00459         virtual long rows () const;
00460         virtual void addColumn (ValueType type, const String& columnName, long repeatWidth, const String& colUnit = String(""), long decimals = -1, size_t columnNumber = 0);
00461         virtual void deleteColumn (const String& columnName);
00462         virtual long getRowsize () const;
00463         virtual int numCols () const;
00464         virtual const std::map<string, Column*>& column () const;
00465 
00466         bool isCompressed () const;
00467         int version () const;
00468         void version (int value);
00469         static const String& missHDU ();
00470         static void setMissHDU (const String& value);
00471 
00472     public:
00473       // Additional Public Declarations
00474 
00475       // interface is virtually identical to PHDU. The implementation is
00476       // similar apart from a check for wrong extension type.
00477 
00478 
00479 
00480 
00481       template <typename S>
00482       void write(const std::vector<long>& first,
00483                     long nElements,
00484                     const std::valarray<S>& data,
00485                     S* nullValue);
00486 
00487 
00488       template <typename S>
00489       void write(long first,
00490                     long nElements,
00491                     const std::valarray<S>& data,
00492                     S* nullValue);                
00493 
00494       template <typename S>
00495       void write(const std::vector<long>& first,
00496                     long nElements,
00497                     const std::valarray<S>& data);
00498 
00499 
00500       template <typename S>
00501       void write(long first,
00502                     long nElements,
00503                     const std::valarray<S>& data);
00504 
00505       template <typename S>
00506       void write(const std::vector<long>& firstVertex,
00507                     const std::vector<long>& lastVertex,
00508                     const std::valarray<S>& data);     
00509 
00510       // read image data & return the array. Can't return a reference because type
00511       // conversion in general requires allocating a new object.
00512       // note semantics of reading column data are easily distinguished: they require
00513       // the user to perform the operation EXT.column({name,index}).read(...)
00514 
00515       template <typename S>
00516       void read (std::valarray<S>& image) ; 
00517 
00518       template<typename S> 
00519       void read (std::valarray<S>& image, 
00520                       long first,
00521                       long nElements, 
00522                       S* nullValue) ; 
00523 
00524       template<typename S>
00525       void read (std::valarray<S>& image, 
00526                       const std::vector<long>& first, 
00527                       long nElements, 
00528                       S* nullValue) ; 
00529 
00530       template<typename S>
00531       void read (std::valarray<S>& image, 
00532                       const std::vector<long>& firstVertex, 
00533                       const std::vector<long>& lastVertex, 
00534                       const std::vector<long>& stride) ; 
00535 
00536       template<typename S>
00537       void read (std::valarray<S>& image, 
00538                       long first,
00539                       long nElements) ; 
00540 
00541       template<typename S>
00542       void read (std::valarray<S>& image, 
00543                       const std::vector<long>& first,
00544                       long nElements) ; 
00545 
00546       template<typename S>
00547       void read (std::valarray<S>& image, 
00548                       const std::vector<long>& firstVertex, 
00549                       const std::vector<long>& lastVertex, 
00550                       const std::vector<long>& stride, 
00551                       S* nullValue) ; 
00552 
00553     protected:
00554         //      ExtHDU needs a default constructor. This is it.
00555         ExtHDU (FITSBase* p, HduType xtype, const String &hduName, int version);
00556         //      The writing constructor. Forces the user to supply a name
00557         //      for the HDU
00558         ExtHDU (FITSBase* p, HduType xtype, const String &hduName, int bitpix, int naxis, const std::vector<long>& axes, int version);
00559         //      ExtHDU constructor for getting ExtHDUs by number.
00560         //      Necessary since EXTNAME is a reserved not required
00561         //      keyword.
00562         ExtHDU (FITSBase* p, HduType xtype, int number);
00563 
00564         virtual std::ostream & put (std::ostream &s) const = 0;
00565         virtual void setColumn (const String& colname, Column* value);
00566         virtual void checkExtensionType () const;
00567         int getVersion ();
00568         long pcount () const;
00569         void pcount (long value);
00570         long gcount () const;
00571         void gcount (long value);
00572         HduType xtension () const;
00573         void xtension (HduType value);
00574 
00575       // Additional Protected Declarations
00576 
00577     private:
00578         virtual void initRead () = 0;
00579         void checkXtension ();
00580 
00581       // Additional Private Declarations
00582 
00583     private: //## implementation
00584       // Data Members for Class Attributes
00585         long m_pcount;
00586         long m_gcount;
00587         int m_version;
00588         HduType m_xtension;
00589         static String s_missHDU;
00590 
00591       // Data Members for Associations
00592         String m_name;
00593 
00594       // Additional Implementation Declarations
00595 
00596   };
00597 
00598   // Class CCfits::ExtHDU::WrongExtensionType 
00599 
00600   // Class CCfits::ExtHDU 
00601 
00602   inline bool operator<(const ExtHDU &left,const ExtHDU &right)
00603   {
00604         if (left.m_name < right.m_name) return true; 
00605         if (left.m_name > right.m_name) return false;
00606         if (left.m_name == right.m_name)
00607         {
00608                 if (left.m_version < right.m_version) return true;
00609         }      
00610         return false;       
00611   }
00612 
00613   inline bool operator>(const ExtHDU &left,const ExtHDU &right)
00614   {
00615      return !operator<=(left,right);
00616   }
00617 
00618   inline bool operator<=(const ExtHDU &left,const ExtHDU &right)
00619   {
00620         if (left.m_name <= right.m_name) 
00621         {
00622                 if (left.m_version <= right.m_version) return true;
00623         }
00624         return false;     
00625   }
00626 
00627   inline bool operator>=(const ExtHDU &left,const ExtHDU &right)
00628   {
00629     return !operator<(left,right);    
00630   }
00631 
00632 
00633   inline const String& ExtHDU::name () const
00634   {
00635 
00636     return m_name;
00637   }
00638 
00639   inline long ExtHDU::pcount () const
00640   {
00641     return m_pcount;
00642   }
00643 
00644   inline void ExtHDU::pcount (long value)
00645   {
00646     m_pcount = value;
00647   }
00648 
00649   inline long ExtHDU::gcount () const
00650   {
00651     return m_gcount;
00652   }
00653 
00654   inline void ExtHDU::gcount (long value)
00655   {
00656     m_gcount = value;
00657   }
00658 
00659   inline int ExtHDU::version () const
00660   {
00661     return m_version;
00662   }
00663 
00664   inline void ExtHDU::version (int value)
00665   {
00666     m_version = value;
00667   }
00668 
00669   inline HduType ExtHDU::xtension () const
00670   {
00671     return m_xtension;
00672   }
00673 
00674   inline void ExtHDU::xtension (HduType value)
00675   {
00676     m_xtension = value;
00677   }
00678 
00679   inline const String& ExtHDU::missHDU ()
00680   {
00681     return s_missHDU;
00682   }
00683 
00684   inline void ExtHDU::setMissHDU (const String& value)
00685   {
00686     s_missHDU = value;
00687   }
00688 
00689 } // namespace CCfits
00690 
00691 
00692 #endif