CCfits  2.4
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 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29 
30 #ifdef SSTREAM_DEFECT
31 #include <strstream>
32 #else
33 #include <sstream>
34 #endif
35 
36 
37 namespace CCfits {
38 
280  class Table : public ExtHDU //## Inherits: <unnamed>%3804A126EB10
281  {
282 
283  public:
284 
285 
286 
287  class NoSuchColumn : public FitsException //## Inherits: <unnamed>%397CB0970174
288  {
289  public:
290  NoSuchColumn (const String& name, bool silent = true);
291  NoSuchColumn (int index, bool silent = true);
292 
293  protected:
294  private:
295  private: //## implementation
296  };
297 
298 
299 
300  class InvalidColumnSpecification : public FitsException //## Inherits: <unnamed>%3B1E52D703B0
301  {
302  public:
303  InvalidColumnSpecification (const String& msg, bool silent = true);
304 
305  protected:
306  private:
307  private: //## implementation
308  };
309  Table(const Table &right);
310  virtual ~Table();
311 
312  // ! return reference to a column given by column name.
313  virtual Column& column (const String& colName, bool caseSensitive = true) const;
314  virtual Column& column (int colIndex // ! return reference to a column given by a column index number
315  ) const;
316  virtual long rows () const;
317  void updateRows ();
318  void rows (long numRows);
319  virtual void deleteColumn (const String& columnName);
320  // Insert one or more blank rows into a FITS column.
321  void insertRows (long first, long number = 1);
322  void deleteRows (long first, long number = 1);
323  void deleteRows (const std::vector<long>& rowList);
324  virtual long getRowsize () const;
325  virtual int numCols () const;
326  virtual const std::map<string, Column*>& column () const;
327  virtual std::map<string, Column*>& column ();
328 
329  public:
330  // Additional Public Declarations
331 
332  protected:
333  Table (FITSBase* p, HduType xtype, const String &hduName, int rows, // ! Number of rows in table at creation, to be used to initialize NAXIS2
334  const std::vector<String>& columnName, const std::vector<String>& columnFmt, const std::vector<String>& columnUnit = std::vector<String>(), int version = 1);
335  // To be called by reading operations.
336  Table (FITSBase* p, HduType xtype, const String &hduName = String(""), int version = 1);
337  // ExtHDU constructor for getting ExtHDUs by number.
338  // Necessary since EXTNAME is a reserved not required
339  // keyword.
340  Table (FITSBase* p, HduType xtype, int number);
341 
342  virtual std::ostream & put (std::ostream &s) const;
343  void column (int columnNum, Column *value);
344  void init (bool readFlag = false, const std::vector<String>& keys = std::vector<String>());
345  virtual void setColumn (const String& colname, Column* value);
346  void reindex ();
347  void numCols (int value);
348 
349  // Additional Protected Declarations
350 
351  private:
352  virtual void initRead ();
353  virtual void readTableHeader (int ncols, std::vector<String>& colName, std::vector<String>& colFmt, std::vector<String>& colUnit) = 0;
354  // deep erasure , to be called by assignment and dtors.
355  void clearData ();
356  void copyData (const Table& right);
357 
358  // Additional Private Declarations
359 
360  private: //## implementation
361  // Data Members for Class Attributes
362  int m_numCols;
363 
364  // Data Members for Associations
365  std::map<string, Column*> m_column;
366 
367  // Additional Implementation Declarations
368  friend class Column;
369  };
370 
371  // Class CCfits::Table::NoSuchColumn
372 
373  // Class CCfits::Table::InvalidColumnSpecification
374 
375  // Class CCfits::Table
376 
377  inline long Table::rows () const
378  {
379 
380  return axis(1);
381  }
382 
383  inline void Table::rows (long numRows)
384  {
385 
386  naxes(1) = numRows;
387  }
388 
389  inline int Table::numCols () const
390  {
391  return m_numCols;
392  }
393 
394  inline const std::map<string, Column*>& Table::column () const
395  {
396  return m_column;
397  }
398 
399  inline void Table::numCols (int value)
400  {
401  m_numCols = value;
402  }
403 
404  inline std::map<string, Column*>& Table::column ()
405  {
406  return m_column;
407  }
408 
409 } // namespace CCfits
410 
411 
412 #endif