GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GFitsTable.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GFitsTable.hpp - FITS table abstract base class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2008-2018 by Juergen Knoedlseder *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 /**
22  * @file GFitsTable.hpp
23  * @brief FITS table abstract base class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GFITSTABLE_HPP
28 #define GFITSTABLE_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include "GFitsHDU.hpp"
32 #include "GFitsTableCol.hpp"
33 
34 
35 /***********************************************************************//**
36  * @class GFitsTable
37  *
38  * @brief Abstract interface for FITS table
39  *
40  * This class defines the abstract interface for a FITS table. A FITS table
41  * is a collection of columns with an identical number of rows. This class
42  * provides high level access to table columns.
43  ***************************************************************************/
44 class GFitsTable : public GFitsHDU {
45 
46 public:
47  // Constructors and destructors
48  GFitsTable(void);
49  explicit GFitsTable(const int& nrows);
50  GFitsTable(const GFitsTable& table);
51  virtual ~GFitsTable(void);
52 
53  // Operators
54  GFitsTable& operator=(const GFitsTable& table);
55  GFitsTableCol* operator[](const int& colnum);
56  const GFitsTableCol* operator[](const int& colnum) const;
57  GFitsTableCol* operator[](const std::string& colname);
58  const GFitsTableCol* operator[](const std::string& colname) const;
59 
60  // Pure virtual methods
61  virtual void clear(void) = 0;
62  virtual GFitsTable* clone(void) const = 0;
63  virtual std::string classname(void) const = 0;
64  virtual HDUType exttype(void) const = 0;
65 
66  // Implemented Methods
67  GFitsTableCol* set(const int& colnum, const GFitsTableCol& column);
68  GFitsTableCol* set(const std::string& colname, const GFitsTableCol& column);
69  GFitsTableCol* append(const GFitsTableCol& column);
70  GFitsTableCol* insert(int colnum, const GFitsTableCol& column);
71  GFitsTableCol* insert(const std::string& colname, const GFitsTableCol& column);
72  void remove(const int& colnum);
73  void remove(const std::string& colname);
74  void append_rows(const int& nrows);
75  void insert_rows(const int& row, const int& nrows);
76  void remove_rows(const int& row, const int& nrows);
77  const int& nrows(void) const;
78  const int& ncols(void) const;
79  bool contains(const std::string& colname) const;
80  std::string print(const GChatter& chatter = NORMAL) const;
81 
82 protected:
83  // Protected methods
84  void init_members(void);
85  void copy_members(const GFitsTable& table);
86  void free_members(void);
87  void free_columns(void);
88  void update_header(void);
89  void data_open(void* vptr);
90  void data_save(void);
91  void data_close(void);
92  void data_connect(void* vptr);
93  char* get_ttype(const int& colnum) const;
94  char* get_tform(const int& colnum) const;
95  char* get_tunit(const int& colnum) const;
96 
97  // Protected data area
98  int m_type; //!< Table type (1=ASCII, 2=Binary)
99  int m_rows; //!< Number of rows in table
100  int m_cols; //!< Number of columns in table
101  GFitsTableCol** m_columns; //!< Array of table columns
102 
103 private:
104  // Private methods
105  GFitsTableCol* alloc_column(int typecode) const;
106  GFitsTableCol* ptr_column(const std::string& colname) const;
107  int colnum(const std::string& colname) const;
108 };
109 
110 
111 /***********************************************************************//**
112  * @brief Return number of rows in table
113  *
114  * @return Number of rows in table
115  *
116  * Returns the number of rows in table.
117  ***************************************************************************/
118 inline
119 const int& GFitsTable::nrows(void) const
120 {
121  return m_rows;
122 }
123 
124 
125 /***********************************************************************//**
126  * @brief Return number of columns in table
127  *
128  * @return Number of columns in table
129  *
130  * Returns the number of columns in table. This method is equivalent to the
131  * size() method.
132  ***************************************************************************/
133 inline
134 const int& GFitsTable::ncols(void) const
135 {
136  return m_cols;
137 }
138 
139 
140 /***********************************************************************//**
141  * @brief Append column to the table
142  *
143  * @param[in] column Table column.
144  * @return Pointer to table column that has been appended
145  ***************************************************************************/
146 inline
148 {
149  return (insert(m_cols, column));
150 }
151 
152 #endif /* GFITSTABLE_HPP */
const int & ncols(void) const
Return number of columns in table.
Definition: GFitsTable.hpp:134
int m_rows
Number of rows in table.
Definition: GFitsTable.hpp:99
GFitsTable(void)
Void constructor.
Definition: GFitsTable.cpp:89
char * get_ttype(const int &colnum) const
Returns pointer to column type.
GFitsTableCol * set(const int &colnum, const GFitsTableCol &column)
Set column.
Definition: GFitsTable.cpp:356
void insert_rows(const int &row, const int &nrows)
Insert rows into the table.
Definition: GFitsTable.cpp:675
Abstract FITS extension base class.
Definition: GFitsHDU.hpp:51
int m_type
Table type (1=ASCII, 2=Binary)
Definition: GFitsTable.hpp:98
GFitsTableCol * alloc_column(int typecode) const
Allocates column.
bool contains(const std::string &colname) const
Checks the presence of a column in table.
Definition: GFitsTable.cpp:759
virtual HDUType exttype(void) const =0
void append_rows(const int &nrows)
Append rows to the table.
Definition: GFitsTable.cpp:647
GFitsTableCol * append(const GFitsTableCol &column)
Append column to the table.
Definition: GFitsTable.hpp:147
GFitsTableCol ** m_columns
Array of table columns.
Definition: GFitsTable.hpp:101
char * get_tform(const int &colnum) const
Returns pointer to column format.
FITS table column abstract base class definition.
GFitsTableCol * operator[](const int &colnum)
Returns pointer to table column.
Definition: GFitsTable.cpp:199
Abstract FITS extension base class definition.
virtual std::string classname(void) const =0
Return class name.
void data_save(void)
Save table into FITS file.
char * get_tunit(const int &colnum) const
Returns pointer to column unit.
void update_header(void)
Update header after row or column manipulations.
Definition: GFitsTable.cpp:951
Abstract interface for FITS table column.
void data_open(void *vptr)
Open Table.
void copy_members(const GFitsTable &table)
Copy class members.
Definition: GFitsTable.cpp:868
virtual ~GFitsTable(void)
Destructor.
Definition: GFitsTable.cpp:140
Abstract interface for FITS table.
Definition: GFitsTable.hpp:44
GChatter
Definition: GTypemaps.hpp:33
virtual void clear(void)=0
Clear object.
void init_members(void)
Initialise class members.
Definition: GFitsTable.cpp:848
const int & nrows(void) const
Return number of rows in table.
Definition: GFitsTable.hpp:119
int colnum(const std::string &colname) const
Returns column number of a given column name.
std::string typecode(int type) const
Return typecode as string.
Definition: GFitsHDU.cpp:398
int m_cols
Number of columns in table.
Definition: GFitsTable.hpp:100
void free_members(void)
Free class members.
Definition: GFitsTable.cpp:898
virtual GFitsTable * clone(void) const =0
Clones object.
void data_close(void)
Close table.
void data_connect(void *vptr)
Connect table data to FITS file.
void free_columns(void)
Free column pointers.
Definition: GFitsTable.cpp:913
GFitsTableCol * insert(int colnum, const GFitsTableCol &column)
Insert column into the table.
Definition: GFitsTable.cpp:433
GFitsTableCol * ptr_column(const std::string &colname) const
Returns pointer of column with given name.
GFitsTable & operator=(const GFitsTable &table)
Assignment operator.
Definition: GFitsTable.cpp:162
void remove_rows(const int &row, const int &nrows)
Remove rows from the table.
Definition: GFitsTable.cpp:718
std::string print(const GChatter &chatter=NORMAL) const
Print table information.
Definition: GFitsTable.cpp:775