CCfits  2.5
Table.h
1 // Astrophysics Science Division,
2 // NASA/ Goddard Space Flight Center
3 // HEASARC
4 // http://heasarc.gsfc.nasa.gov
5 // e-mail: ccfits@legacy.gsfc.nasa.gov
6 //
7 // Original author: Ben Dorman
8 
9 #ifndef TABLE_H
10 #define TABLE_H 1
11 
12 // ExtHDU
13 #include "ExtHDU.h"
14 // FitsError
15 #include "FitsError.h"
16 
17 namespace CCfits {
18  class Column;
19 
20 } // namespace CCfits
21 
22 #ifdef _MSC_VER
23 #include "MSconfig.h" // for truncation warning
24 #endif
25 
26 
27 #ifdef SSTREAM_DEFECT
28 #include <strstream>
29 #else
30 #include <sstream>
31 #endif
32 
33 
34 namespace CCfits {
35 
271  class Table : public ExtHDU //## Inherits: <unnamed>%3804A126EB10
272  {
273 
274  public:
275 
276 
277 
278  class NoSuchColumn : public FitsException //## Inherits: <unnamed>%397CB0970174
279  {
280  public:
281  NoSuchColumn (const String& name, bool silent = true);
282  NoSuchColumn (int index, bool silent = true);
283 
284  protected:
285  private:
286  private: //## implementation
287  };
288 
289 
290 
291  class InvalidColumnSpecification : public FitsException //## Inherits: <unnamed>%3B1E52D703B0
292  {
293  public:
294  InvalidColumnSpecification (const String& msg, bool silent = true);
295 
296  protected:
297  private:
298  private: //## implementation
299  };
300  Table(const Table &right);
301  virtual ~Table();
302 
303  // ! return reference to a column given by column name.
304  virtual Column& column (const String& colName, bool caseSensitive = true) const;
305  virtual Column& column (int colIndex // ! return reference to a column given by a column index number
306  ) const;
307  virtual long rows () const;
308  void updateRows ();
309  void rows (long numRows);
310  virtual void deleteColumn (const String& columnName);
311  // Insert one or more blank rows into a FITS column.
312  void insertRows (long first, long number = 1);
313  void deleteRows (long first, long number = 1);
314  void deleteRows (const std::vector<long>& rowList);
315  virtual long getRowsize () const;
316  virtual int numCols () const;
317  virtual const ColMap& column () const;
318  virtual ColMap& column ();
319  virtual void copyColumn(const Column& inColumn, int colIndx, bool insertNewCol=true);
320 
321  public:
322  // Additional Public Declarations
323 
324  protected:
325  Table (FITSBase* p, HduType xtype, const String &hduName, int rows, // ! Number of rows in table at creation, to be used to initialize NAXIS2
326  const std::vector<String>& columnName, const std::vector<String>& columnFmt, const std::vector<String>& columnUnit = std::vector<String>(), int version = 1);
327  // To be called by reading operations.
328  Table (FITSBase* p, HduType xtype, const String &hduName = String(""), int version = 1);
329  // ExtHDU constructor for getting ExtHDUs by number.
330  // Necessary since EXTNAME is a reserved not required
331  // keyword.
332  Table (FITSBase* p, HduType xtype, int number);
333 
334  virtual std::ostream & put (std::ostream &s) const;
335  void init (bool readFlag = false, const std::vector<String>& keys = std::vector<String>());
336  virtual void setColumn (const String& colname, Column* value);
337  void reindex (int startNum, bool isInsert);
338  void numCols (int value);
339 
340  // Additional Protected Declarations
341 
342  private:
343  virtual void initRead ();
344  virtual void readTableHeader (int ncols, std::vector<String>& colName, std::vector<String>& colFmt, std::vector<String>& colUnit) = 0;
345  // deep erasure , to be called by assignment and dtors.
346  void clearData ();
347  void copyData (const Table& right);
348 
349  // Additional Private Declarations
350 
351  private: //## implementation
352  // Data Members for Class Attributes
353  int m_numCols;
354 
355  // Data Members for Associations
356  ColMap m_column;
357 
358  // Additional Implementation Declarations
359  friend class Column;
360  };
361 
362  // Class CCfits::Table::NoSuchColumn
363 
364  // Class CCfits::Table::InvalidColumnSpecification
365 
366  // Class CCfits::Table
367 
368  inline long Table::rows () const
369  {
370 
371  return axis(1);
372  }
373 
374  inline void Table::rows (long numRows)
375  {
376 
377  naxes(1) = numRows;
378  }
379 
380  inline int Table::numCols () const
381  {
382  return m_numCols;
383  }
384 
385  inline const ColMap& Table::column () const
386  {
387  return m_column;
388  }
389 
390  inline void Table::numCols (int value)
391  {
392  m_numCols = value;
393  }
394 
396  {
397  return m_column;
398  }
399 
400 } // namespace CCfits
401 
402 
403 #endif
virtual long rows() const
return the number of rows in the table (NAXIS2).
Definition: Table.h:368
void updateRows()
update the number of rows in the table
Definition: Table.cxx:301
const String & name() const
return the name of the extension.
Definition: ExtHDU.h:651
virtual ~Table()
destructor
Definition: Table.cxx:135
void init(bool readFlag=false, const std::vector< String > &keys=std::vector< String >())
Definition: Table.cxx:214
int version() const
return the extension version number.
Definition: ExtHDU.h:677
int index() const
return the HDU number
Definition: HDU.h:885
virtual int numCols() const
return the number of Columns in the Table (the TFIELDS keyword).
Definition: Table.h:380
FitsException is the base class for all exceptions thrown by this library.
Definition: FitsError.h:93
Namespace enclosing all CCfits classes and globals definitions.
Definition: AsciiTable.cxx:26
base class for all FITS extension HDUs, i.e. Image Extensions and Tables.
Definition: ExtHDU.h:438
long axis(size_t index) const
return the size of axis numbered index [zero based].
Definition: HDU.h:873
NoSuchColumn(const String &name, bool silent=true)
Exception ctor for exception thrown if the requested column (specified by name) is not present...
Definition: Table.cxx:27
std::multimap< std::string, CCfits::Column * > ColMap
Type definition for a table&#39;s column container.
Definition: CCfits.h:109
Exception to be thrown on a failure to retrieve a column specified either by name or index number...
Definition: Table.h:278
Definition: Table.h:271
Table(const Table &right)
copy constructor
Definition: Table.cxx:56
virtual void deleteColumn(const String &columnName)
delete a column in a Table extension by name.
Definition: Table.cxx:314
virtual const ColMap & column() const
return a reference to the multimap containing the columns.
Definition: Table.h:385
virtual long getRowsize() const
return the optimal number of rows to read or write at a time
Definition: Table.cxx:432
std::vector< long > & naxes()
return the HDU data axis array.
Definition: HDU.h:979
Abstract base class for Column objects.
Definition: Column.h:841
void insertRows(long first, long number=1)
insert empty rows into the table
Definition: Table.cxx:337
virtual void copyColumn(const Column &inColumn, int colIndx, bool insertNewCol=true)
copy a column (from different or same HDU and file) into an existing table HDU.
Definition: Table.cxx:441
void deleteRows(long first, long number=1)
delete a range of rows in a table.
Definition: Table.cxx:356