GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GFitsHeaderCard.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GFitsHeaderCard.hpp - FITS header card 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 GFitsHeaderCard.hpp
23  * @brief FITS header card class definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GFITSHEADERCARD_HPP
28 #define GFITSHEADERCARD_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GBase.hpp"
33 
34 
35 /***********************************************************************//**
36  * @class GFitsHeaderCard
37  *
38  * @brief Implements FITS header card interface
39  *
40  * This class implements a FITS header card. A header card consists of a
41  * keyname (string), a value (string, floating point, integer or logical)
42  * and a comment (string). COMMENT or HISTORY cards do not have a value.
43  ***************************************************************************/
44 class GFitsHeaderCard : public GBase {
45 
46  // Friend classes
47  friend class GFitsHeader;
48 
49 public:
50  // Constructors & Destructors
51  GFitsHeaderCard(void);
52  GFitsHeaderCard(const std::string& keyname, const std::string& value,
53  const std::string& unit, const std::string& comment);
54  GFitsHeaderCard(const std::string& keyname, const std::string& value,
55  const std::string& comment);
56  GFitsHeaderCard(const std::string& keyname, const double& value,
57  const std::string& comment);
58  GFitsHeaderCard(const std::string& keyname, const int& value,
59  const std::string& comment);
60  GFitsHeaderCard(const std::string& keyname, const bool& value,
61  const std::string& comment);
62  GFitsHeaderCard(const std::string& keyname, const char* value,
63  const std::string& comment);
64  GFitsHeaderCard(const GFitsHeaderCard& card);
65  virtual ~GFitsHeaderCard(void);
66 
67  // Operators
69 
70  // Methods
71  void clear(void);
72  GFitsHeaderCard* clone(void) const;
73  std::string classname(void) const;
74  void keyname(const std::string& keyname);
75  const std::string& keyname(void) const;
76  void value(const std::string& value);
77  void value(const bool& value);
78  void value(const float& value);
79  void value(const double& value);
80  void value(const unsigned short& value);
81  void value(const short& value);
82  void value(const unsigned int& value);
83  void value(const int& value);
84  void value(const long& value);
85  void value(const unsigned long& value);
86  void value(const long long& value);
87  const std::string& value(void) const;
88  const int& decimals(void) const;
89  void unit(const std::string& unit);
90  const std::string& unit(void) const;
91  void comment(const std::string& comment);
92  const std::string& comment(void) const;
93  std::string string(void) const;
94  double real(void) const;
95  int integer(void) const;
96  std::string print(const GChatter& chatter = NORMAL) const;
97 
98 private:
99  // Private methods
100  void init_members(void);
101  void copy_members(const GFitsHeaderCard& card);
102  void free_members(void);
103  void set_members(const std::string& keyname,
104  const std::string& value,
105  const std::string& unit,
106  const std::string& comment);
107  void copy_dtype(const GFitsHeaderCard& card);
108  void free_dtype(void);
109  void set_dtype(const std::string& value);
110  void read(void* vptr, const int& keynum);
111  void read(void* fptr, const std::string& keyname);
112  void write(void* fptr) const;
113 
114  // Private data area
115  std::string m_keyname; //!< Name of the card
116  std::string m_value; //!< Value of the card as read from file
117  std::string m_unit; //!< Unit of the card value
118  std::string m_comment; //!< Card comment
119  int m_dtype; //!< Native data type
120  int m_value_decimals; //!< Decimals of value (for float)
121  bool m_comment_write; //!< Signals that comment should be written
122  void* m_value_dtype; //!< Value in native data type
123 };
124 
125 
126 /***********************************************************************//**
127  * @brief Return class name
128  *
129  * @return String containing the class name ("GFitsHeaderCard").
130  ***************************************************************************/
131 inline
132 std::string GFitsHeaderCard::classname(void) const
133 {
134  return ("GFitsHeaderCard");
135 }
136 
137 
138 /***********************************************************************//**
139  * @brief Set unit of header card value
140  *
141  * @param[in] unit Unit of header card.
142  ***************************************************************************/
143 inline
144 void GFitsHeaderCard::unit(const std::string& unit)
145 {
146  m_unit = unit;
147  return;
148 }
149 
150 
151 /***********************************************************************//**
152  * @brief Set comment of header card
153  *
154  * @param[in] comment Header card comment.
155  ***************************************************************************/
156 inline
157 void GFitsHeaderCard::comment(const std::string& comment)
158 {
159  m_comment = comment;
160  return;
161 }
162 
163 
164 /***********************************************************************//**
165  * @brief Return header card keyname
166  ***************************************************************************/
167 inline
168 const std::string& GFitsHeaderCard::keyname(void) const
169 {
170  return m_keyname;
171 }
172 
173 
174 /***********************************************************************//**
175  * @brief Return header card value
176  ***************************************************************************/
177 inline
178 const std::string& GFitsHeaderCard::value(void) const
179 {
180  return m_value;
181 }
182 
183 
184 /***********************************************************************//**
185  * @brief Return header card decimals
186  ***************************************************************************/
187 inline
188 const int& GFitsHeaderCard::decimals(void) const
189 {
190  return m_value_decimals;
191 }
192 
193 
194 /***********************************************************************//**
195  * @brief Return header card value unit
196  ***************************************************************************/
197 inline
198 const std::string& GFitsHeaderCard::unit(void) const
199 {
200  return m_unit;
201 }
202 
203 
204 /***********************************************************************//**
205  * @brief Return header card comment
206  ***************************************************************************/
207 inline
208 const std::string& GFitsHeaderCard::comment(void) const
209 {
210  return m_comment;
211 }
212 
213 #endif /* GFITSHEADERCARD_HPP */
void * m_value_dtype
Value in native data type.
std::string string(void) const
Return header card value as string.
int m_dtype
Native data type.
GFitsHeaderCard(void)
Void constructor.
const std::string & keyname(void) const
Return header card keyname.
void copy_dtype(const GFitsHeaderCard &card)
Copy dtype.
GFitsHeaderCard * clone(void) const
Clone header card.
Definition of interface for all GammaLib classes.
void copy_members(const GFitsHeaderCard &card)
Copy class members.
void free_dtype(void)
Free dtype.
std::string print(const GChatter &chatter=NORMAL) const
Print header card information.
bool m_comment_write
Signals that comment should be written.
const std::string & unit(void) const
Return header card value unit.
std::string m_value
Value of the card as read from file.
const int & decimals(void) const
Return header card decimals.
GFitsHeaderCard & operator=(const GFitsHeaderCard &card)
Assignment operator.
Implements FITS header card interface.
Interface for FITS header class.
Definition: GFitsHeader.hpp:49
std::string m_comment
Card comment.
Interface class for all GammaLib classes.
Definition: GBase.hpp:52
const std::string & comment(void) const
Return header card comment.
void set_dtype(const std::string &value)
Set native data type from card string.
GChatter
Definition: GTypemaps.hpp:33
void read(void *vptr, const int &keynum)
Read header card from FITS file.
void write(void *fptr) const
Write header card.
std::string classname(void) const
Return class name.
double real(void) const
Return header card value as double precision.
void clear(void)
Clear header card.
void free_members(void)
Delete class members.
const std::string & value(void) const
Return header card value.
int m_value_decimals
Decimals of value (for float)
std::string m_keyname
Name of the card.
int integer(void) const
Return header card value as integer.
void set_members(const std::string &keyname, const std::string &value, const std::string &unit, const std::string &comment)
Set card members.
std::string m_unit
Unit of the card value.
virtual ~GFitsHeaderCard(void)
Destructor.
void init_members(void)
Initialise class members.