GammaLib 2.0.0
Loading...
Searching...
No Matches
GSkyDirs.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GSkyDirs.hpp - Sky directions container class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2020 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 GSkyDirs.hpp
23 * @brief Sky directions container class definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GSKYDIRS_HPP
28#define GSKYDIRS_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <string>
32#include <vector>
33#include "GContainer.hpp"
34#include "GSkyDir.hpp"
35
36/* __ Forward declarations _______________________________________________ */
37
38/* __ Constants __________________________________________________________ */
39
40
41/***********************************************************************//**
42 * @class GSkyDirs
43 *
44 * @brief Sky directions container class
45 *
46 * This class is a container for sky directions. Sky directions are
47 * implemented by the GSkyDir class.
48 ***************************************************************************/
49class GSkyDirs : public GContainer {
50
51public:
52 // Constructors and destructors
53 GSkyDirs(void);
54 explicit GSkyDirs(const GSkyDir& dir);
55 GSkyDirs(const GSkyDirs& dirs);
56 virtual ~GSkyDirs(void);
57
58 // Operators
59 GSkyDirs& operator=(const GSkyDirs& dirs);
60 GSkyDir& operator[](const int& index);
61 const GSkyDir& operator[](const int& index) const;
62
63 // Methods
64 void clear(void);
65 GSkyDirs* clone(void) const;
66 std::string classname(void) const;
67 GSkyDir& at(const int& index);
68 const GSkyDir& at(const int& index) const;
69 int size(void) const;
70 bool is_empty(void) const;
71 GSkyDir& append(const GSkyDir& dir);
72 GSkyDir& insert(const int& index, const GSkyDir& dir);
73 void remove(const int& index);
74 void reserve(const int& num);
75 void extend(const GSkyDirs& dirs);
76 std::string print(const GChatter& chatter = NORMAL) const;
77
78protected:
79 // Protected methods
80 void init_members(void);
81 void copy_members(const GSkyDirs& dirs);
82 void free_members(void);
83
84 // Protected data members
85 std::vector<GSkyDir> m_dirs; //!< List of sky directions
86};
87
88
89/***********************************************************************//**
90 * @brief Return class name
91 *
92 * @return String containing the class name ("GSkyDirs").
93 ***************************************************************************/
94inline
95std::string GSkyDirs::classname(void) const
96{
97 return ("GSkyDirs");
98}
99
100
101/***********************************************************************//**
102 * @brief Return reference to sky direction
103 *
104 * @param[in] index Sky direction index [0,...,size()-1].
105 *
106 * Returns a reference to the sky direction with the specified @p index.
107 ***************************************************************************/
108inline
110{
111 return (m_dirs[index]);
112}
113
114
115/***********************************************************************//**
116 * @brief Return reference to sky direction (const version)
117 *
118 * @param[in] index Sky direction index [0,...,size()-1].
119 *
120 * Returns a const reference to the sky direction with the specified
121 * @p index.
122 ***************************************************************************/
123inline
124const GSkyDir& GSkyDirs::operator[](const int& index) const
125{
126 return (m_dirs[index]);
127}
128
129
130/***********************************************************************//**
131 * @brief Return reference to sky direction
132 *
133 * @param[in] index Sky direction index [0,...,size()-1].
134 *
135 * @exception GException::out_of_range
136 * Sky direction index is out of range.
137 *
138 * Returns a reference to the sky direction with the specified @p index.
139 ***************************************************************************/
140inline
141GSkyDir& GSkyDirs::at(const int& index)
142{
143 // Return reference to sky direction using const method
144 return const_cast<GSkyDir&>(static_cast<const GSkyDirs*>(this)->at(index));
145}
146
147
148/***********************************************************************//**
149 * @brief Return number of sky directions in container
150 *
151 * @return Number of sky directions in container.
152 *
153 * Returns the number of sky directions in the sky directions container.
154 ***************************************************************************/
155inline
156int GSkyDirs::size(void) const
157{
158 return ((int)m_dirs.size());
159}
160
161
162/***********************************************************************//**
163 * @brief Signals if there are no sky directions in container
164 *
165 * @return True if container is empty, false otherwise.
166 *
167 * Signals if the sky directions container does not contain any sky
168 * direction.
169 ***************************************************************************/
170inline
171bool GSkyDirs::is_empty(void) const
172{
173 return (m_dirs.empty());
174}
175
176
177/***********************************************************************//**
178 * @brief Reserves space for sky directions in container
179 *
180 * @param[in] num Number of sky directions.
181 *
182 * Reserves space for @p num sky directions in the container.
183 ***************************************************************************/
184inline
185void GSkyDirs::reserve(const int& num)
186{
187 m_dirs.reserve(num);
188 return;
189}
190
191#endif /* GSKYDIRS_HPP */
Definition of interface for container classes.
Sky direction class interface definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Interface class for container classes.
Sky direction class.
Definition GSkyDir.hpp:62
Sky directions container class.
Definition GSkyDirs.hpp:49
GSkyDir & append(const GSkyDir &dir)
Append sky direction to container.
Definition GSkyDirs.cpp:232
GSkyDir & insert(const int &index, const GSkyDir &dir)
Insert sky direction into container.
Definition GSkyDirs.cpp:254
void clear(void)
Clear sky directions container.
Definition GSkyDirs.cpp:175
void free_members(void)
Delete class members.
Definition GSkyDirs.cpp:413
std::vector< GSkyDir > m_dirs
List of sky directions.
Definition GSkyDirs.hpp:85
virtual ~GSkyDirs(void)
Destructor.
Definition GSkyDirs.cpp:121
std::string classname(void) const
Return class name.
Definition GSkyDirs.hpp:95
bool is_empty(void) const
Signals if there are no sky directions in container.
Definition GSkyDirs.hpp:171
void extend(const GSkyDirs &dirs)
Append sky directions container.
Definition GSkyDirs.cpp:314
GSkyDir & at(const int &index)
Return reference to sky direction.
Definition GSkyDirs.hpp:141
void remove(const int &index)
Remove sky direction from container.
Definition GSkyDirs.cpp:290
void init_members(void)
Initialise class members.
Definition GSkyDirs.cpp:385
GSkyDirs * clone(void) const
Clone sky directions container.
Definition GSkyDirs.cpp:195
std::string print(const GChatter &chatter=NORMAL) const
Print sky directions container information.
Definition GSkyDirs.cpp:345
void copy_members(const GSkyDirs &dirs)
Copy class members.
Definition GSkyDirs.cpp:400
GSkyDirs(void)
Void constructor.
Definition GSkyDirs.cpp:67
GSkyDir & operator[](const int &index)
Return reference to sky direction.
Definition GSkyDirs.hpp:109
int size(void) const
Return number of sky directions in container.
Definition GSkyDirs.hpp:156
GSkyDirs & operator=(const GSkyDirs &dirs)
Assignment operator.
Definition GSkyDirs.cpp:143
void reserve(const int &num)
Reserves space for sky directions in container.
Definition GSkyDirs.hpp:185