GammaLib 2.2.0.dev
Loading...
Searching...
No Matches
GFitsTable.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GFitsTable.hpp - FITS table abstract base class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2008-2026 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 ***************************************************************************/
44class GFitsTable : public GFitsHDU {
45
46public:
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 bool is_empty(void) const;
68 GFitsTableCol* set(const int& colnum, const GFitsTableCol& column);
69 GFitsTableCol* set(const std::string& colname, const GFitsTableCol& column);
70 GFitsTableCol* append(const GFitsTableCol& column);
71 GFitsTableCol* insert(int colnum, const GFitsTableCol& column);
72 GFitsTableCol* insert(const std::string& colname, const GFitsTableCol& column);
73 void remove(const int& colnum);
74 void remove(const std::string& colname);
75 void append_rows(const int& nrows);
76 void insert_rows(const int& row, const int& nrows);
77 void remove_rows(const int& row, const int& nrows);
78 const int& nrows(void) const;
79 const int& ncols(void) const;
80 bool contains(const std::string& colname) const;
81 std::string print(const GChatter& chatter = NORMAL) const;
82
83protected:
84 // Protected methods
85 void init_members(void);
86 void copy_members(const GFitsTable& table);
87 void free_members(void);
88 void free_columns(void);
89 void update_header(void);
90 void data_open(void* vptr);
91 void data_save(void);
92 void data_close(void);
93 void data_connect(void* vptr);
94 char* get_ttype(const int& colnum) const;
95 char* get_tform(const int& colnum) const;
96 char* get_tunit(const int& colnum) const;
97
98 // Protected data area
99 int m_type; //!< Table type (1=ASCII, 2=Binary)
100 int m_rows; //!< Number of rows in table
101 int m_cols; //!< Number of columns in table
102 GFitsTableCol** m_columns; //!< Array of table columns
103
104private:
105 // Private methods
107 GFitsTableCol* ptr_column(const std::string& colname) const;
108 int colnum(const std::string& colname) const;
109};
110
111
112/***********************************************************************//**
113 * @brief Signals if the FITS table has no row or columns
114 *
115 * @return True if FITS table has no row or columns.
116 ***************************************************************************/
117inline
118bool GFitsTable::is_empty(void) const
119{
120 return ((m_rows == 0) || (m_cols == 0));
121}
122
123
124/***********************************************************************//**
125 * @brief Return number of rows in table
126 *
127 * @return Number of rows in table
128 *
129 * Returns the number of rows in table.
130 ***************************************************************************/
131inline
132const int& GFitsTable::nrows(void) const
133{
134 return (m_rows);
135}
136
137
138/***********************************************************************//**
139 * @brief Return number of columns in table
140 *
141 * @return Number of columns in table
142 *
143 * Returns the number of columns in table. This method is equivalent to the
144 * size() method.
145 ***************************************************************************/
146inline
147const int& GFitsTable::ncols(void) const
148{
149 return (m_cols);
150}
151
152
153/***********************************************************************//**
154 * @brief Append column to the table
155 *
156 * @param[in] column Table column.
157 * @return Pointer to table column that has been appended
158 ***************************************************************************/
159inline
161{
162 return (insert(m_cols, column));
163}
164
165#endif /* GFITSTABLE_HPP */
Abstract FITS extension base class definition.
FITS table column abstract base class definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Abstract FITS extension base class.
Definition GFitsHDU.hpp:51
std::string typecode(int type) const
Return typecode as string.
Definition GFitsHDU.cpp:398
Abstract interface for FITS table column.
Abstract interface for FITS table.
void data_save(void)
Save table into FITS file.
virtual HDUType exttype(void) const =0
void data_open(void *vptr)
Open Table.
void remove(const int &colnum)
Remove column from the table.
void update_header(void)
Update header after row or column manipulations.
char * get_tunit(const int &colnum) const
Returns pointer to column unit.
int m_type
Table type (1=ASCII, 2=Binary)
void data_close(void)
Close table.
bool contains(const std::string &colname) const
Checks the presence of a column in table.
GFitsTableCol * ptr_column(const std::string &colname) const
Returns pointer of column with given name.
void data_connect(void *vptr)
Connect table data to FITS file.
void free_members(void)
Free class members.
virtual ~GFitsTable(void)
Destructor.
virtual GFitsTable * clone(void) const =0
Clones object.
GFitsTableCol * set(const int &colnum, const GFitsTableCol &column)
Set column.
GFitsTableCol * append(const GFitsTableCol &column)
Append column to the table.
void init_members(void)
Initialise class members.
int colnum(const std::string &colname) const
Returns column number of a given column name.
void free_columns(void)
Free column pointers.
bool is_empty(void) const
Signals if the FITS table has no row or columns.
GFitsTableCol * insert(int colnum, const GFitsTableCol &column)
Insert column into the table.
void append_rows(const int &nrows)
Append rows to the table.
GFitsTableCol ** m_columns
Array of table columns.
GFitsTableCol * alloc_column(int typecode) const
Allocates column.
char * get_tform(const int &colnum) const
Returns pointer to column format.
void insert_rows(const int &row, const int &nrows)
Insert rows into the table.
const int & nrows(void) const
Return number of rows in table.
GFitsTable & operator=(const GFitsTable &table)
Assignment operator.
GFitsTableCol * operator[](const int &colnum)
Returns pointer to table column.
int m_rows
Number of rows in table.
virtual void clear(void)=0
Clear object.
void remove_rows(const int &row, const int &nrows)
Remove rows from the table.
void copy_members(const GFitsTable &table)
Copy class members.
std::string print(const GChatter &chatter=NORMAL) const
Print table information.
const int & ncols(void) const
Return number of columns in table.
int m_cols
Number of columns in table.
virtual std::string classname(void) const =0
Return class name.
char * get_ttype(const int &colnum) const
Returns pointer to column type.
GFitsTable(void)
Void constructor.