GSkyRegions.hpp
1 |
/***************************************************************************
|
---|---|
2 |
* GSkyRegions.hpp - Sky region container class *
|
3 |
* ----------------------------------------------------------------------- *
|
4 |
* copyright (C) 2009-2013 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 GSkyRegions.hpp
|
23 |
* @brief Sky regions container class definition
|
24 |
* @author Pierrick martin
|
25 |
*/
|
26 |
|
27 |
#ifndef GSKYREGIONS_HPP
|
28 |
#define GSKYREGIONS_HPP
|
29 |
|
30 |
/* __ Includes ___________________________________________________________ */
|
31 |
#include <string> |
32 |
#include <vector> |
33 |
#include "GBase.hpp" |
34 |
#include "GXml.hpp" |
35 |
#include "GSkyRegion.hpp" |
36 |
|
37 |
|
38 |
/***********************************************************************//** |
39 |
* @class GSkyRegions
|
40 |
*
|
41 |
* @brief Sky region container class
|
42 |
*
|
43 |
* This container class collects sky regions of type GSkyRegion that are
|
44 |
* used to extract properties over regions of the sky (events, exposure,...)
|
45 |
* The names of all regions in the container have to be unique, i.e. every
|
46 |
* name can occur only once. This allows for accessing the regions by name
|
47 |
* and by index.
|
48 |
*
|
49 |
* To be clarified:
|
50 |
* - Role/need of at() and reserve() methods ?
|
51 |
* - Role/need of load/save and read/write methods (especially if DS9 file format) ?
|
52 |
***************************************************************************/
|
53 |
class GSkyRegions : public GBase { |
54 |
|
55 |
public:
|
56 |
// Constructors and destructors
|
57 |
GSkyRegions(void);
|
58 |
GSkyRegions(const GSkyRegions& regions);;
|
59 |
virtual ~GSkyRegions(void); |
60 |
|
61 |
// Operators
|
62 |
GSkyRegions& operator=(const GSkyRegions& regions); |
63 |
GSkyRegion* operator[](const int& index); |
64 |
const GSkyRegion* operator[](const int& index) const; |
65 |
GSkyRegion* operator[](const std::string& name); |
66 |
const GSkyRegion* operator[](const std::string& name) const; |
67 |
|
68 |
// Methods
|
69 |
void clear(void); |
70 |
GSkyRegions* clone(void) const; |
71 |
GSkyRegion* at(const int& index); |
72 |
const GSkyRegion* at(const int& index) const; |
73 |
int size(void) const; |
74 |
bool isempty(void) const; |
75 |
GSkyRegion* set(const int& index, const GSkyRegion& region); |
76 |
GSkyRegion* set(const std::string& name, const GSkyRegion& region); |
77 |
GSkyRegion* append(const GSkyRegion& region);
|
78 |
GSkyRegion* insert(const int& index, const GSkyRegion& region); |
79 |
GSkyRegion* insert(const std::string& name, const GSkyRegion& region); |
80 |
void remove(const int& index); |
81 |
void remove(const std::string& name); |
82 |
void reserve(const int& num); |
83 |
void extend(const GSkyRegions& regions); |
84 |
bool contains(const std::string& name) const; |
85 |
void load(const std::string& filename); |
86 |
void save(const std::string& filename) const; |
87 |
void read(const GXml& xml); |
88 |
void write(GXml& xml) const; |
89 |
std::string print(const GChatter& chatter = NORMAL) const; |
90 |
|
91 |
protected:
|
92 |
// Protected methods
|
93 |
void init_members(void); |
94 |
void copy_members(const GSkyRegions& regions); |
95 |
void free_members(void); |
96 |
void set_pointers(void); |
97 |
int get_index(const std::string& name) const; |
98 |
|
99 |
// Protected members
|
100 |
std::vector<GSkyRegion*> m_regions; //!< List of regions
|
101 |
}; |
102 |
|
103 |
|
104 |
/***********************************************************************//** |
105 |
* @brief Return pointer to region
|
106 |
*
|
107 |
* @param[in] index region index [0,...,size()-1].
|
108 |
*
|
109 |
* Returns a pointer to the region with the specified @p index.
|
110 |
***************************************************************************/
|
111 |
inline
|
112 |
GSkyRegion* GSkyRegions::operator[](const int& index) |
113 |
{ |
114 |
return (m_regions[index]);
|
115 |
} |
116 |
|
117 |
|
118 |
/***********************************************************************//** |
119 |
* @brief Return pointer to region (const version)
|
120 |
*
|
121 |
* @param[in] index region index [0,...,size()-1].
|
122 |
*
|
123 |
* Returns a const pointer to the region with the specified @p index.
|
124 |
***************************************************************************/
|
125 |
inline
|
126 |
const GSkyRegion* GSkyRegions::operator[](const int& index) const |
127 |
{ |
128 |
return (m_regions[index]);
|
129 |
} |
130 |
|
131 |
|
132 |
/***********************************************************************//** |
133 |
* @brief Return number of regions in container
|
134 |
*
|
135 |
* @return Number of regions in container.
|
136 |
*
|
137 |
* Returns the number of regions in the region container.
|
138 |
***************************************************************************/
|
139 |
inline
|
140 |
int GSkyRegions::size(void) const |
141 |
{ |
142 |
return (m_regions.size());
|
143 |
} |
144 |
|
145 |
|
146 |
/***********************************************************************//** |
147 |
* @brief Signals if there are no regions in container
|
148 |
*
|
149 |
* @return True if container is empty, false otherwise.
|
150 |
*
|
151 |
* Signals if the region container does not contain any region.
|
152 |
***************************************************************************/
|
153 |
inline
|
154 |
bool GSkyRegions::isempty(void) const |
155 |
{ |
156 |
return (m_regions.empty());
|
157 |
} |
158 |
|
159 |
|
160 |
/***********************************************************************//** |
161 |
* @brief Reserves space for regions in container
|
162 |
*
|
163 |
* @param[in] num Number of regions
|
164 |
*
|
165 |
* Reserves space for @p num regions in the container.
|
166 |
***************************************************************************/
|
167 |
inline
|
168 |
void GSkyRegions::reserve(const int& num) |
169 |
{ |
170 |
m_regions.reserve(num); |
171 |
return;
|
172 |
} |
173 |
|
174 |
#endif /* GSKYREGIONS_HPP */ |