CCfits  2.7
HDUCreator.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 HDUCREATOR_H
00010 #define HDUCREATOR_H 1
00011 
00012 // valarray
00013 #include <valarray>
00014 // typeinfo
00015 #include <typeinfo>
00016 // vector
00017 #include <vector>
00018 // string
00019 #include <string>
00020 // CCfitsHeader
00021 #include "CCfits.h"
00022 // FitsError
00023 #include "FitsError.h"
00024 
00025 namespace CCfits {
00026   class FITS;
00027   class HDU;
00028   class PHDU;
00029   class ExtHDU;
00030 
00031 } // namespace CCfits
00032 
00033 
00034 namespace CCfits {
00035 
00036 
00037 
00038   class HDUCreator 
00039   {
00040 
00041     public:
00042         HDUCreator (FITS* p);
00043         ~HDUCreator();
00044 
00045         //  Read a specified HDU from given fitsfile and
00046         //  return a pointer to it.
00047         HDU * getHdu (const String& hduName, bool readDataFlag = false, const std::vector<String> &keys = std::vector<String>(), bool primary = false, int version = 1);
00048         PHDU * createImage (int bitpix, long naxis, const std::vector<long>& naxes);
00049         void reset ();
00050         HDU * Make (const String& hduName, bool readDataFlag, const std::vector<String> &keys, bool primary, int version);
00051         HDU* createTable (const String &name, HduType xtype, int rows, const std::vector<String>& colName, const std::vector<String> colFmt, const std::vector<String> colUnit, int version);
00052         //  Read a specified HDU from given fitsfile and
00053         //  return a pointer to it.
00054         //
00055         //  With no arguments this reads the PrimaryHDU.
00056         HDU * getHdu (int index = 0, bool readDataFlag = false, const std::vector<String> &keys = std::vector<String>());
00057         ExtHDU * createImage (const String &name, int bitpix, long naxis, const std::vector<long>& naxes, int version);
00058         // MakeImage needs to be public so that FITS.h can friend it, so that 
00059         // MakeImage can see FITS::m_pHDU pointer, rather than FITS.h friending
00060         // entire HDUCreator class
00061         PHDU * MakeImage (int bpix, int naxis, const std::vector<long>& naxes);
00062         
00063 
00064       // Additional Public Declarations
00065 
00066     protected:
00067       // Additional Protected Declarations
00068 
00069     private:
00070         HDU* MakeTable (const String &name, HduType xtype, int rows, const std::vector<String>& colName, const std::vector<String>& colFmt, const std::vector<String>& colUnit, int version);
00071         HDU * Make (int index, bool readDataFlag, const std::vector<String> &keys);
00072         ExtHDU * MakeImage (const String &name, int bpix, long naxis, const std::vector<long>& naxes, int version);
00073         void getScaling (long& type, double& zero, double& scale) const;
00074         void parent (FITS* value);
00075         
00076         // Utility function to implement both of the Make() function interfaces.
00077         HDU* commonMake(const String& hduName, bool readDataFlag, const std::vector<String> &keys, bool primary, int version);
00078       
00079         // Data Members for Class Attributes
00080         HDU *m_hdu;
00081 
00082       // Additional Private Declarations
00083 
00084     private: //## implementation
00085       // Data Members for Associations
00086         FITS* m_parent;
00087 
00088       // Additional Implementation Declarations
00089 
00090   };
00091 
00092   // Class CCfits::HDUCreator 
00093 
00094   inline HDU * HDUCreator::getHdu (const String& hduName, bool readDataFlag, const std::vector<String> &keys, bool primary, int version)
00095   {
00097   if ( m_hdu == 0 ) m_hdu = Make(hduName,readDataFlag,keys,primary,version);
00098   return m_hdu;
00099   }
00100 
00101   inline void HDUCreator::reset ()
00102   {
00103   m_hdu = 0;
00104   }
00105 
00106   inline HDU* HDUCreator::createTable (const String &name, HduType xtype, int rows, const std::vector<String>& colName, const std::vector<String> colFmt, const std::vector<String> colUnit, int version)
00107   {
00109         if (m_hdu == 0) m_hdu = MakeTable(name,xtype,rows,colName,colFmt,colUnit,version);
00110         return m_hdu;
00111   }
00112 
00113   inline HDU * HDUCreator::getHdu (int index, bool readDataFlag, const std::vector<String> &keys)
00114   {
00116   if ( m_hdu == 0 ) m_hdu = Make(index,readDataFlag,keys);
00117   return m_hdu;
00118   }
00119 
00120   inline void HDUCreator::parent (FITS* value)
00121   {
00122     m_parent = value;
00123   }
00124 
00125 } // namespace CCfits
00126 
00127 
00128 #endif