GammaLib 2.1.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-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 ***************************************************************************/
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 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
82protected:
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
103private:
104 // Private methods
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 ***************************************************************************/
118inline
119const 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 ***************************************************************************/
133inline
134const 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 ***************************************************************************/
146inline
148{
149 return (insert(m_cols, column));
150}
151
152#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.
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.