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
***************************************************************************/
49
class
GFitsHeader
:
public
GContainer
{
50
51
public
:
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
;
80
GFitsHeaderCard
&
append
(
const
GFitsHeaderCard
& card);
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
93
private
:
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
***************************************************************************/
112
inline
113
std::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
***************************************************************************/
125
inline
126
GFitsHeaderCard
&
GFitsHeader::operator[]
(
const
int
& cardno)
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
***************************************************************************/
138
inline
139
const
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
***************************************************************************/
151
inline
152
GFitsHeaderCard
&
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
***************************************************************************/
164
inline
165
const
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
***************************************************************************/
178
inline
179
int
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
***************************************************************************/
192
inline
193
bool
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
***************************************************************************/
206
inline
207
void
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
***************************************************************************/
222
inline
223
bool
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
***************************************************************************/
237
inline
238
bool
GFitsHeader::contains
(
const
std::string& keyname)
const
239
{
240
return
(
get_index
(keyname) != -1);
241
}
242
243
#endif
/* GFITSHEADER_HPP */
GContainer.hpp
Definition of interface for container classes.
GFitsHeaderCard.hpp
FITS header card class definition.
GChatter
GChatter
Definition
GTypemaps.hpp:33
NORMAL
@ NORMAL
Definition
GTypemaps.hpp:36
GContainer
Interface class for container classes.
Definition
GContainer.hpp:52
GFitsHeaderCard
Implements FITS header card interface.
Definition
GFitsHeaderCard.hpp:44
GFitsHeader
Interface for FITS header class.
Definition
GFitsHeader.hpp:49
GFitsHeader::free_members
void free_members(void)
Delete class members.
Definition
GFitsHeader.cpp:781
GFitsHeader::m_cards
std::vector< GFitsHeaderCard > m_cards
Header cards.
Definition
GFitsHeader.hpp:102
GFitsHeader::clone
GFitsHeader * clone(void) const
Clone header.
Definition
GFitsHeader.cpp:171
GFitsHeader::contains
bool contains(const int &cardno) const
Check if card is present in header.
Definition
GFitsHeader.hpp:223
GFitsHeader::~GFitsHeader
virtual ~GFitsHeader(void)
Destructor.
Definition
GFitsHeader.cpp:101
GFitsHeader::reserve
void reserve(const int &num)
Reserves space for cards in FITS header.
Definition
GFitsHeader.hpp:207
GFitsHeader::string
std::string string(const int &cardno) const
Return header card value as string value.
Definition
GFitsHeader.cpp:282
GFitsHeader::get_index
int get_index(const std::string &keyname) const
Get index of header card.
Definition
GFitsHeader.cpp:797
GFitsHeader::GFitsHeader
GFitsHeader(void)
Constructor.
Definition
GFitsHeader.cpp:70
GFitsHeader::at
GFitsHeaderCard & at(const int &cardno)
Return header card.
Definition
GFitsHeader.cpp:186
GFitsHeader::init_members
void init_members(void)
Initialise class members.
Definition
GFitsHeader.cpp:749
GFitsHeader::save
void save(void *vptr) const
Save header to FITS file.
Definition
GFitsHeader.cpp:689
GFitsHeader::classname
std::string classname(void) const
Return class name.
Definition
GFitsHeader.hpp:113
GFitsHeader::remove
void remove(const int &cardno)
Remove card from header.
Definition
GFitsHeader.cpp:541
GFitsHeader::copy_members
void copy_members(const GFitsHeader &header)
Copy class members.
Definition
GFitsHeader.cpp:765
GFitsHeader::append
GFitsHeaderCard & append(const GFitsHeaderCard &card)
Append or update header card.
Definition
GFitsHeader.cpp:427
GFitsHeader::operator=
GFitsHeader & operator=(const GFitsHeader &header)
Assignment operator.
Definition
GFitsHeader.cpp:123
GFitsHeader::operator[]
GFitsHeaderCard & operator[](const int &cardno)
Return header card.
Definition
GFitsHeader.hpp:126
GFitsHeader::print
std::string print(const GChatter &chatter=NORMAL) const
Print FITS header information.
Definition
GFitsHeader.cpp:715
GFitsHeader::extend
void extend(const GFitsHeader &header)
Append header.
Definition
GFitsHeader.cpp:600
GFitsHeader::clear
void clear(void)
Clear header.
Definition
GFitsHeader.cpp:153
GFitsHeader::integer
int integer(const int &cardno) const
Return header card value as integer value.
Definition
GFitsHeader.cpp:378
GFitsHeader::m_keyname_map
std::map< std::string, GFitsHeaderCard * > m_keyname_map
Header pointers.
Definition
GFitsHeader.hpp:103
GFitsHeader::insert
GFitsHeaderCard & insert(const int &cardno, const GFitsHeaderCard &card)
Insert card into header.
Definition
GFitsHeader.cpp:465
GFitsHeader::update_keyname_map
void update_keyname_map(void)
Update the header card pointers.
Definition
GFitsHeader.cpp:828
GFitsHeader::real
double real(const int &cardno) const
Return header card value as double precision value.
Definition
GFitsHeader.cpp:330
GFitsHeader::load
void load(void *vptr)
Load header from FITS file.
Definition
GFitsHeader.cpp:639
GFitsHeader::size
int size(void) const
Return number of cards in header.
Definition
GFitsHeader.hpp:179
GFitsHeader::is_empty
bool is_empty(void) const
Signals if there are no cards in the FITS header.
Definition
GFitsHeader.hpp:193
include
GFitsHeader.hpp
Generated on Tue Jan 14 2025 15:02:54 for GammaLib by
1.11.0