GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GSkyProjection.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GSkyProjection.cpp - Abstract sky projection base class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-2021 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 GSkyProjection.cpp
23  * @brief Abstract sky projection base class implementation
24  * @author Juergen Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include "GException.hpp"
32 #include "GTools.hpp"
33 #include "GSkyProjection.hpp"
34 
35 /* __ Method name definitions ____________________________________________ */
36 #define G_COORDSYS_SET "GSkyProjection::coordsys(std::string)"
37 
38 /* __ Macros _____________________________________________________________ */
39 
40 /* __ Coding definitions _________________________________________________ */
41 
42 /* __ Debug definitions __________________________________________________ */
43 
44 /* __ Local prototypes ___________________________________________________ */
45 
46 /* __ Constants __________________________________________________________ */
47 
48 
49 /*==========================================================================
50  = =
51  = Constructors/destructors =
52  = =
53  ==========================================================================*/
54 
55 /***********************************************************************//**
56  * @brief Void constructor
57  ***************************************************************************/
59 {
60  // Initialise class members
61  init_members();
62 
63  // Return
64  return;
65 }
66 
67 
68 /***********************************************************************//**
69  * @brief Copy constructor
70  *
71  * @param[in] proj Sky projection.
72  ***************************************************************************/
74 {
75  // Initialise class members
76  init_members();
77 
78  // Copy members
79  copy_members(proj);
80 
81  // Return
82  return;
83 }
84 
85 
86 /***********************************************************************//**
87  * @brief Destructor
88  ***************************************************************************/
90 {
91  // Free members
92  free_members();
93 
94  // Return
95  return;
96 }
97 
98 
99 /*==========================================================================
100  = =
101  = Operators =
102  = =
103  ==========================================================================*/
104 
105 /***********************************************************************//**
106  * @brief Assignment operator
107  *
108  * @param[in] proj Sky projection.
109  * @return Sky projection.
110  ***************************************************************************/
112 {
113  // Execute only if object is not identical
114  if (this != &proj) {
115 
116  // Free members
117  free_members();
118 
119  // Initialise private members for clean destruction
120  init_members();
121 
122  // Copy members
123  copy_members(proj);
124 
125  } // endif: object was not identical
126 
127  // Return this object
128  return *this;
129 }
130 
131 
132 /*==========================================================================
133  = =
134  = Public methods =
135  = =
136  ==========================================================================*/
137 
138 /***********************************************************************//**
139  * @brief Returns coordinate system.
140  *
141  * @return Coordinate system string.
142  *
143  * Returns one of
144  * 'CEL' (celestial),
145  * 'GAL' (galactic),
146  ***************************************************************************/
147 std::string GSkyProjection::coordsys(void) const
148 {
149  // Set coordinate system
150  std::string s_coordsys;
151  switch (m_coordsys) {
152  case 0:
153  s_coordsys = "CEL";
154  break;
155  case 1:
156  s_coordsys = "GAL";
157  break;
158  default:
159  s_coordsys = "UNKNOWN";
160  break;
161  }
162 
163  // Return coordinate system
164  return s_coordsys;
165 }
166 
167 
168 /***********************************************************************//**
169  * @brief Set coordinate system
170  *
171  * @param[in] coordsys Coordinate system
172  *
173  * @exception GException::invalid_argument
174  * Invalid @p coordsys parameter.
175  *
176  * Set coordinate system from std::string. The method recognizes the
177  * following codes:
178  * 'EQU', 'CEL', 'C': celestial,
179  * 'GAL', 'G': galactic,
180  ***************************************************************************/
181 void GSkyProjection::coordsys(const std::string& coordsys)
182 {
183  // Convert argument to upper case
184  std::string ucoordsys = gammalib::toupper(coordsys);
185 
186  // Set coordinate system
187  if (ucoordsys == "EQU" || ucoordsys == "CEL" || ucoordsys == "C") {
188  m_coordsys = 0;
189  }
190  else if (ucoordsys == "GAL" || ucoordsys == "G") {
191  m_coordsys = 1;
192  }
193  else {
194  std::string msg = "Invalid coordinate system "+coordsys+" specified. "
195  "Please specify one of \"EQU\",\"CEL\",\"C\",\"GAL\""
196  " or \"G\".";
198  }
199 
200  // Return
201  return;
202 }
203 
204 
205 /*==========================================================================
206  = =
207  = Protected methods =
208  = =
209  ==========================================================================*/
210 
211 /***********************************************************************//**
212  * @brief Initialise class members
213  ***************************************************************************/
215 {
216  // Initialise members
217  m_coordsys = 0; // 0 means CEL
218 
219  // Return
220  return;
221 }
222 
223 
224 /***********************************************************************//**
225  * @brief Copy class members
226  *
227  * @param[in] proj Sky projection.
228  ***************************************************************************/
230 {
231  // Copy attributes
232  m_coordsys = proj.m_coordsys;
233 
234  // Return
235  return;
236 }
237 
238 
239 /***********************************************************************//**
240  * @brief Delete class members
241  ***************************************************************************/
243 {
244  // Return
245  return;
246 }
247 
248 
249 /*==========================================================================
250  = =
251  = Friends =
252  = =
253  ==========================================================================*/
254 
255 /***********************************************************************//**
256  * @brief Equality operator
257  *
258  * @param[in] a First sky projection.
259  * @param[in] b Second sky projection.
260  * @return True if @p a and @p b are identical.
261  ***************************************************************************/
262 bool operator==(const GSkyProjection &a, const GSkyProjection &b)
263 {
264  // Return result
265  return a.compare(b);
266 }
267 
268 
269 /***********************************************************************//**
270  * @brief Non-equality operator
271  *
272  * @param[in] a First sky projection.
273  * @param[in] b Second sky projection.
274  * @return True if @p a and @p b are not identical.
275  ***************************************************************************/
276 bool operator!=(const GSkyProjection &a, const GSkyProjection &b)
277 {
278  // Return result
279  return !(a == b);
280 }
virtual GSkyProjection & operator=(const GSkyProjection &proj)
Assignment operator.
Abstract sky projection base class definition.
Gammalib tools definition.
#define G_COORDSYS_SET
void copy_members(const GSkyProjection &proj)
Copy class members.
virtual bool compare(const GSkyProjection &proj) const =0
GSkyProjection(void)
Void constructor.
int m_coordsys
0=CEL, 1=GAL
virtual std::string coordsys(void) const
Returns coordinate system.
void free_members(void)
Delete class members.
Exception handler interface definition.
void init_members(void)
Initialise class members.
std::string toupper(const std::string &s)
Convert string to upper case.
Definition: GTools.cpp:941
bool operator==(const GEnergy &a, const GEnergy &b)
Energy equality operator friend.
Definition: GEnergy.hpp:297
Abstract sky projection base class.
bool operator!=(const GEbounds &a, const GEbounds &b)
Energy boundaries inequality operator friend.
Definition: GEbounds.hpp:213
virtual ~GSkyProjection(void)
Destructor.