GammaLib 2.0.0
Loading...
Searching...
No Matches
GFitsHeader.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GFitsHeader.hpp - FITS header cards container 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 GFitsHeader.hpp
23 * @brief FITS header cards container class definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GFITSHEADER_HPP
28#define GFITSHEADER_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <map>
32#include <string>
33#include <vector>
34#include "GContainer.hpp"
35#include "GFitsHeaderCard.hpp"
36
37
38/***********************************************************************//**
39 * @class GFitsHeader
40 *
41 * @brief Interface for FITS header class
42 *
43 * The FITS header class is a container class for header cards.
44 *
45 * All cards of a FITS file extension will be held in memory, so no link to
46 * a FITS file is required. Cards are read from a file using the load()
47 * method, and cards are saved into a file using the save() method.
48 ***************************************************************************/
49class GFitsHeader : public GContainer {
50
51public:
52 // Constructors and destructors
53 GFitsHeader(void);
54 GFitsHeader(const GFitsHeader& header);
55 virtual ~GFitsHeader(void);
56
57 // Operators
58 GFitsHeader& operator=(const GFitsHeader& header);
59 GFitsHeaderCard& operator[](const int& cardno);
60 const GFitsHeaderCard& operator[](const int& cardno) const;
61 GFitsHeaderCard& operator[](const std::string& keyname);
62 const GFitsHeaderCard& operator[](const std::string& keyname) const;
63
64 // Methods
65 void clear(void);
66 GFitsHeader* clone(void) const;
67 std::string classname(void) const;
68 GFitsHeaderCard& at(const int& cardno);
69 const GFitsHeaderCard& at(const int& cardno) const;
70 GFitsHeaderCard& at(const std::string& keyname);
71 const GFitsHeaderCard& at(const std::string& keyname) const;
72 std::string string(const int& cardno) const;
73 std::string string(const std::string& keyname) const;
74 double real(const int& cardno) const;
75 double real(const std::string& keyname) const;
76 int integer(const int& cardno) const;
77 int integer(const std::string& keyname) const;
78 int size(void) const;
79 bool is_empty(void) const;
81 GFitsHeaderCard& insert(const int& cardno, const GFitsHeaderCard& card);
82 GFitsHeaderCard& insert(const std::string& keyname, const GFitsHeaderCard& card);
83 void remove(const int& cardno);
84 void remove(const std::string& keyname);
85 void reserve(const int& num);
86 void extend(const GFitsHeader& header);
87 bool contains(const int& cardno) const;
88 bool contains(const std::string& keyname) const;
89 void load(void* vptr);
90 void save(void* vptr) const;
91 std::string print(const GChatter& chatter = NORMAL) const;
92
93private:
94 // Private methods
95 void init_members(void);
96 void copy_members(const GFitsHeader& header);
97 void free_members(void);
98 int get_index(const std::string& keyname) const;
99 void update_keyname_map(void);
100
101 // Private data area
102 std::vector<GFitsHeaderCard> m_cards; //!< Header cards
103 std::map<std::string, GFitsHeaderCard*> m_keyname_map; //!< Header pointers
104};
105
106
107/***********************************************************************//**
108 * @brief Return class name
109 *
110 * @return String containing the class name ("GFitsHeader").
111 ***************************************************************************/
112inline
113std::string GFitsHeader::classname(void) const
114{
115 return ("GFitsHeader");
116}
117
118
119/***********************************************************************//**
120 * @brief Return header card
121 *
122 * @param[in] cardno Number of card in header [0,...,size()-1]
123 * @return Header card.
124 ***************************************************************************/
125inline
127{
128 return (m_cards[cardno]);
129}
130
131
132/***********************************************************************//**
133 * @brief Return pointer to model (const version)
134 *
135 * @param[in] cardno Number of card in header [0,...,size()-1]
136 * @return Header card.
137 ***************************************************************************/
138inline
139const GFitsHeaderCard& GFitsHeader::operator[](const int& cardno) const
140{
141 return (m_cards[cardno]);
142}
143
144
145/***********************************************************************//**
146 * @brief Return header card
147 *
148 * @param[in] keyname Name of header card
149 * @return Header card.
150 ***************************************************************************/
151inline
152GFitsHeaderCard& GFitsHeader::operator[](const std::string& keyname)
153{
154 return (at(keyname));
155}
156
157
158/***********************************************************************//**
159 * @brief Return header card (const version)
160 *
161 * @param[in] keyname Name of header card
162 * @return Header card.
163 ***************************************************************************/
164inline
165const GFitsHeaderCard& GFitsHeader::operator[](const std::string& keyname) const
166{
167 return (at(keyname));
168}
169
170
171/***********************************************************************//**
172 * @brief Return number of cards in header
173 *
174 * @return Number of cards in header.
175 *
176 * Returns the number of cards in the extension header.
177 ***************************************************************************/
178inline
179int GFitsHeader::size(void) const
180{
181 return (int)m_cards.size();
182}
183
184
185/***********************************************************************//**
186 * @brief Signals if there are no cards in the FITS header
187 *
188 * @return True if there are no cards in the FITS header, false otherwise
189 *
190 * Signals if there are no cards in the FITS header.
191 ***************************************************************************/
192inline
193bool GFitsHeader::is_empty(void) const
194{
195 return (m_cards.empty());
196}
197
198
199/***********************************************************************//**
200 * @brief Reserves space for cards in FITS header
201 *
202 * @param[in] num Number of cards
203 *
204 * Reserves space for @p num cards in the FITS header.
205 ***************************************************************************/
206inline
207void GFitsHeader::reserve(const int& num)
208{
209 m_cards.reserve(num);
210 return;
211}
212
213
214/***********************************************************************//**
215 * @brief Check if card is present in header
216 *
217 * @param[in] cardno Number of card in header.
218 * @return True of card exists, false otherwise.
219 *
220 * Signals whether a card with specified card number exists in header.
221 ***************************************************************************/
222inline
223bool GFitsHeader::contains(const int& cardno) const
224{
225 return (cardno >= 0 && cardno < size());
226}
227
228
229/***********************************************************************//**
230 * @brief Check if card is present in header
231 *
232 * @param[in] keyname Name of header card.
233 * @return True of card exists, false otherwise.
234 *
235 * Signals whether a card with specified @p keyname exists in header.
236 ***************************************************************************/
237inline
238bool GFitsHeader::contains(const std::string& keyname) const
239{
240 return (get_index(keyname) != -1);
241}
242
243#endif /* GFITSHEADER_HPP */
Definition of interface for container classes.
FITS header card class definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Interface class for container classes.
Implements FITS header card interface.
Interface for FITS header class.
void free_members(void)
Delete class members.
std::vector< GFitsHeaderCard > m_cards
Header cards.
GFitsHeader * clone(void) const
Clone header.
bool contains(const int &cardno) const
Check if card is present in header.
virtual ~GFitsHeader(void)
Destructor.
void reserve(const int &num)
Reserves space for cards in FITS header.
std::string string(const int &cardno) const
Return header card value as string value.
int get_index(const std::string &keyname) const
Get index of header card.
GFitsHeader(void)
Constructor.
GFitsHeaderCard & at(const int &cardno)
Return header card.
void init_members(void)
Initialise class members.
void save(void *vptr) const
Save header to FITS file.
std::string classname(void) const
Return class name.
void remove(const int &cardno)
Remove card from header.
void copy_members(const GFitsHeader &header)
Copy class members.
GFitsHeaderCard & append(const GFitsHeaderCard &card)
Append or update header card.
GFitsHeader & operator=(const GFitsHeader &header)
Assignment operator.
GFitsHeaderCard & operator[](const int &cardno)
Return header card.
std::string print(const GChatter &chatter=NORMAL) const
Print FITS header information.
void extend(const GFitsHeader &header)
Append header.
void clear(void)
Clear header.
int integer(const int &cardno) const
Return header card value as integer value.
std::map< std::string, GFitsHeaderCard * > m_keyname_map
Header pointers.
GFitsHeaderCard & insert(const int &cardno, const GFitsHeaderCard &card)
Insert card into header.
void update_keyname_map(void)
Update the header card pointers.
double real(const int &cardno) const
Return header card value as double precision value.
void load(void *vptr)
Load header from FITS file.
int size(void) const
Return number of cards in header.
bool is_empty(void) const
Signals if there are no cards in the FITS header.