GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GFitsTableBitCol.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GFitsTableBitCol.hpp - FITS table bit column class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2008-2017 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 GFitsTableBitCol.hpp
23  * @brief FITS table bit column class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GFITSTABLEBITCOL_HPP
28 #define GFITSTABLEBITCOL_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GFitsTableCol.hpp"
33 
34 
35 /***********************************************************************//**
36  * @class GFitsTableBitCol
37  *
38  * @brief FITS table Bit column
39  *
40  * This class implements a FITS table Bit column. Bits are stored internally
41  * in an array of type char and is transferred to the file in junks of
42  * 8 Bits (using the CFITSIO type TBYTE).
43  ***************************************************************************/
45 
46 public:
47  // Constructors and destructors
48  GFitsTableBitCol(void);
49  GFitsTableBitCol(const std::string& name, const int& nrows,
50  const int& size = 1);
51  GFitsTableBitCol(const GFitsTableBitCol& column);
52  virtual ~GFitsTableBitCol(void);
53 
54  // Operators
56  bool& operator()(const int& row, const int& inx = 0);
57  const bool& operator()(const int& row, const int& inx = 0) const;
58 
59  // Implemented virtual methods
60  virtual void clear(void);
61  virtual GFitsTableBitCol* clone(void) const;
62  virtual std::string classname(void) const;
63  virtual std::string string(const int& row, const int& col = 0) const;
64  virtual double real(const int& row, const int& col = 0) const;
65  virtual int integer(const int& row, const int& col = 0) const;
66  virtual void insert(const int& row, const int& nrows);
67  virtual void remove(const int& row, const int& nrows);
68  virtual bool is_loaded(void) const;
69 
70  // Other methods
71  unsigned char* data(void);
72  unsigned char* nulval(void);
73  void nulval(const unsigned char* value);
74 
75 private:
76  // Private methods
77  void init_members(void);
78  void copy_members(const GFitsTableBitCol& column);
79  void free_members(void);
80  void alloc_nulval(const unsigned char* value);
81  void get_bit(const int& row, const int& inx);
82  void set_pending(void);
83 
84  // Implemented virtual base class methods
85  virtual void alloc_data(void);
86  virtual void init_data(void);
87  virtual void fetch_data(void) const;
88  virtual void resize_data(const int& index, const int& number);
89  virtual void release_data(void);
90  virtual void* ptr_data(const int& index = 0);
91  virtual void* ptr_nulval(void);
92  virtual std::string ascii_format(void) const;
93 
94  // Overloaded virtual methods
95  virtual void load_column(void);
96  virtual void save_column(void);
97 
98  // Private data area
99  int m_bits; //!< Total number of Bits in column
100  int m_bytes_per_row; //!< Number of Bytes per row
101  int m_bits_per_row; //!< Number of Bits per row
102  unsigned char* m_data; //!< Data area
103  unsigned char* m_nulval; //!< NULL value
104 
105  // Bit access data area
106  bool m_bit_pending; //!< Bit value has to be written back
107  bool m_bit_value; //!< Actual bit to be accessed
108  int m_bit_byte; //!< Row of actual bit to be accessed
109  int m_bit_mask; //!< Index of actual bit to be accessed
110 };
111 
112 
113 /***********************************************************************//**
114  * @brief Return class name
115  *
116  * @return String containing the class name ("GFitsTableBitCol").
117  ***************************************************************************/
118 inline
119 std::string GFitsTableBitCol::classname(void) const
120 {
121  return ("GFitsTableBitCol");
122 }
123 
124 
125 /***********************************************************************//**
126  * @brief Checks if column has been loaded
127  *
128  * @return True if column has been loaded, false otherwise
129  ***************************************************************************/
130 inline
132 {
133  return (m_data != NULL);
134 }
135 
136 
137 /***********************************************************************//**
138  * @brief Returns pointer to column data
139  *
140  * @return Pointer to column data.
141  ***************************************************************************/
142 inline
143 unsigned char* GFitsTableBitCol::data(void)
144 {
145  return m_data;
146 }
147 
148 
149 /***********************************************************************//**
150  * @brief Returns pointer to nul value
151  *
152  * @return Pointer to nul value.
153  ***************************************************************************/
154 inline
155 unsigned char* GFitsTableBitCol::nulval(void)
156 {
157  return m_nulval;
158 }
159 
160 
161 /***********************************************************************//**
162  * @brief Returns void pointer to column data
163  *
164  * @return Void pointer to column data.
165  ***************************************************************************/
166 inline
167 void* GFitsTableBitCol::ptr_data(const int& index)
168 {
169  return (m_data+index);
170 }
171 
172 
173 /***********************************************************************//**
174  * @brief Returns void pointer to nul value
175  *
176  * @return Void pointer to nul value.
177  ***************************************************************************/
178 inline
180 {
181  return m_nulval;
182 }
183 
184 #endif /* GFITSTABLEBITCOL_HPP */
int m_bits
Total number of Bits in column.
virtual void release_data(void)
Release column data.
virtual int integer(const int &row, const int &col=0) const
Get integer value.
void free_members(void)
Delete class members.
virtual void resize_data(const int &index, const int &number)
Resize column data.
virtual std::string string(const int &row, const int &col=0) const
Get string value.
virtual ~GFitsTableBitCol(void)
Destructor.
virtual GFitsTableBitCol * clone(void) const
Clone column.
bool m_bit_value
Actual bit to be accessed.
const std::string & name(void) const
Returns column name.
virtual void insert(const int &row, const int &nrows)
Insert rows in column.
virtual void clear(void)
Clear instance.
unsigned char * m_data
Data area.
void init_members(void)
Initialise class members.
bool m_bit_pending
Bit value has to be written back.
void copy_members(const GFitsTableBitCol &column)
Copy class members.
bool & operator()(const int &row, const int &inx=0)
Column data access operator.
unsigned char * m_nulval
NULL value.
FITS table column abstract base class definition.
virtual void * ptr_nulval(void)
Returns void pointer to nul value.
const int & number(void) const
Returns number of elements in column.
virtual double real(const int &row, const int &col=0) const
Get double precision value.
int m_bits_per_row
Number of Bits per row.
FITS table Bit column.
Abstract interface for FITS table column.
virtual std::string classname(void) const
Return class name.
GFitsTableBitCol & operator=(const GFitsTableBitCol &column)
Assignment operator.
unsigned char * nulval(void)
Returns pointer to nul value.
virtual bool is_loaded(void) const
Checks if column has been loaded.
virtual void alloc_data(void)
Allocates column data.
int m_bit_byte
Row of actual bit to be accessed.
virtual void fetch_data(void) const
Fetch column data.
void get_bit(const int &row, const int &inx)
Get Bit for boolean access.
virtual void * ptr_data(const int &index=0)
Returns void pointer to column data.
virtual void save_column(void)
Save table column into FITS file.
int m_bit_mask
Index of actual bit to be accessed.
const int & nrows(void) const
Returns number of rows in column.
GFitsTableBitCol(void)
Constructor.
int m_bytes_per_row
Number of Bytes per row.
virtual void load_column(void)
Load table column from FITS file.
void set_pending(void)
Set pending Bit.
unsigned char * data(void)
Returns pointer to column data.
virtual std::string ascii_format(void) const
Returns format string of ASCII table.
virtual void init_data(void)
Initialise column data.
void alloc_nulval(const unsigned char *value)
Allocates null value.