CCfits  2.4
Table.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 TABLE_H
00010 #define TABLE_H 1
00011 
00012 // ExtHDU
00013 #include "ExtHDU.h"
00014 // FitsError
00015 #include "FitsError.h"
00016 
00017 namespace CCfits {
00018   class Column;
00019 
00020 } // namespace CCfits
00021 
00022 #ifdef _MSC_VER
00023 #include "MSconfig.h" // for truncation warning
00024 #endif
00025 
00026 #ifdef HAVE_CONFIG_H
00027 #include "config.h"
00028 #endif
00029 
00030 #ifdef SSTREAM_DEFECT
00031 #include <strstream>
00032 #else
00033 #include <sstream>
00034 #endif
00035 
00036 
00037 namespace CCfits {
00038 
00280   class Table : public ExtHDU  //## Inherits: <unnamed>%3804A126EB10
00281   {
00282 
00283     public:
00284 
00285 
00286 
00287       class NoSuchColumn : public FitsException  //## Inherits: <unnamed>%397CB0970174
00288       {
00289         public:
00290             NoSuchColumn (const String& name, bool silent = true);
00291             NoSuchColumn (int index, bool silent = true);
00292 
00293         protected:
00294         private:
00295         private: //## implementation
00296       };
00297 
00298 
00299 
00300       class InvalidColumnSpecification : public FitsException  //## Inherits: <unnamed>%3B1E52D703B0
00301       {
00302         public:
00303             InvalidColumnSpecification (const String& msg, bool silent = true);
00304 
00305         protected:
00306         private:
00307         private: //## implementation
00308       };
00309         Table(const Table &right);
00310         virtual ~Table();
00311 
00312         //      ! return reference to a column given by column name.
00313         virtual Column& column (const String& colName, bool caseSensitive = true) const;
00314         virtual Column& column (int colIndex    // ! return reference to a column given by a column index number
00315         ) const;
00316         virtual long rows () const;
00317         void updateRows ();
00318         void rows (long numRows);
00319         virtual void deleteColumn (const String& columnName);
00320         //      Insert one or more blank rows into a FITS column.
00321         void insertRows (long first, long number = 1);
00322         void deleteRows (long first, long number = 1);
00323         void deleteRows (const std::vector<long>& rowList);
00324         virtual long getRowsize () const;
00325         virtual int numCols () const;
00326         virtual const std::map<string, Column*>& column () const;
00327         virtual std::map<string, Column*>& column ();
00328 
00329     public:
00330       // Additional Public Declarations
00331 
00332     protected:
00333         Table (FITSBase* p, HduType xtype, const String &hduName, int rows,     // ! Number of rows in table at creation, to be used to initialize NAXIS2
00334         const std::vector<String>& columnName, const std::vector<String>& columnFmt, const std::vector<String>& columnUnit = std::vector<String>(), int version = 1);
00335         //      To be called by reading operations.
00336         Table (FITSBase* p, HduType xtype, const String &hduName = String(""), int version = 1);
00337         //      ExtHDU constructor for getting ExtHDUs by number.
00338         //      Necessary since EXTNAME is a reserved not required
00339         //      keyword.
00340         Table (FITSBase* p, HduType xtype, int number);
00341 
00342         virtual std::ostream & put (std::ostream &s) const;
00343         void column (int columnNum, Column *value);
00344         void init (bool readFlag = false, const std::vector<String>& keys = std::vector<String>());
00345         virtual void setColumn (const String& colname, Column* value);
00346         void reindex ();
00347         void numCols (int value);
00348 
00349       // Additional Protected Declarations
00350 
00351     private:
00352         virtual void initRead ();
00353         virtual void readTableHeader (int ncols, std::vector<String>& colName, std::vector<String>& colFmt, std::vector<String>& colUnit) = 0;
00354         //      deep erasure , to be called by  assignment and dtors.
00355         void clearData ();
00356         void copyData (const Table& right);
00357 
00358       // Additional Private Declarations
00359 
00360     private: //## implementation
00361       // Data Members for Class Attributes
00362         int m_numCols;
00363 
00364       // Data Members for Associations
00365         std::map<string, Column*> m_column;
00366 
00367       // Additional Implementation Declarations
00368       friend class Column;
00369   };
00370 
00371   // Class CCfits::Table::NoSuchColumn 
00372 
00373   // Class CCfits::Table::InvalidColumnSpecification 
00374 
00375   // Class CCfits::Table 
00376 
00377   inline long Table::rows () const
00378   {
00379 
00380     return axis(1);
00381   }
00382 
00383   inline void Table::rows (long numRows)
00384   {
00385 
00386     naxes(1) = numRows;
00387   }
00388 
00389   inline int Table::numCols () const
00390   {
00391      return m_numCols;
00392   }
00393 
00394   inline const std::map<string, Column*>& Table::column () const
00395   {
00396     return m_column;
00397   }
00398 
00399   inline void Table::numCols (int value)
00400   {
00401     m_numCols = value;
00402   }
00403 
00404   inline std::map<string, Column*>& Table::column ()
00405   {
00406     return m_column;
00407   }
00408 
00409 } // namespace CCfits
00410 
00411 
00412 #endif