GSkyRegions.hpp

Martin Pierrick, 05/02/2013 01:40 PM

Download (6.39 KB)

 
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
 ***************************************************************************/
50
class GSkyRegions : public GBase {
51

    
52
public:
53
    // Constructors and destructors
54
    GSkyRegions(void);
55
    GSkyRegions(const GSkyRegions& regions);;
56
    virtual ~GSkyRegions(void);
57

    
58
    // Operators
59
    GSkyRegions&      operator=(const GSkyRegions& regions);
60
    GSkyRegion*       operator[](const int& index);
61
    const GSkyRegion* operator[](const int& index) const;
62
    GSkyRegion*       operator[](const std::string& name);
63
    const GSkyRegion* operator[](const std::string& name) const;
64

    
65
    // Methods
66
    void              clear(void);
67
    GSkyRegions*      clone(void) const;
68
    GSkyRegion*       at(const int& index);
69
    const GSkyRegion* at(const int& index) const;
70
    int               size(void) const;
71
    bool              isempty(void) const;
72
    GSkyRegion*       set(const int& index, const GSkyRegion& region);
73
    GSkyRegion*       set(const std::string& name, const GSkyRegion& region);
74
    GSkyRegion*       append(const GSkyRegion& region);
75
    GSkyRegion*       insert(const int& index, const GSkyRegion& region);
76
    GSkyRegion*       insert(const std::string& name, const GSkyRegion& region);
77
    void              remove(const int& index);
78
    void              remove(const std::string& name);
79
    void              reserve(const int& num);
80
    void              extend(const GSkyRegions& regions);
81
    bool              contains(const std::string& name) const;
82
    void              load(const std::string& filename);
83
    void              save(const std::string& filename) const;
84
    void              read(const GXml& xml);
85
    void              write(GXml& xml) const;
86
    std::string       print(const GChatter& chatter = NORMAL) const;
87

    
88
protected:
89
    // Protected methods
90
    void          init_members(void);
91
    void          copy_members(const GSkyRegions& regions);
92
    void          free_members(void);
93
    void          set_pointers(void);
94
    int           get_index(const std::string& name) const;
95

    
96
    // Protected members
97
    std::vector<GSkyRegion*> m_regions;  //!< List of regions
98
};
99

    
100

    
101
/***********************************************************************//**
102
 * @brief Return pointer to region
103
 *
104
 * @param[in] index region index [0,...,size()-1].
105
 *
106
 * Returns a pointer to the region with the specified @p index.
107
 ***************************************************************************/
108
inline
109
GSkyRegion* GSkyRegions::operator[](const int& index)
110
{
111
    return (m_regions[index]);
112
}
113

    
114

    
115
/***********************************************************************//**
116
 * @brief Return pointer to region (const version)
117
 *
118
 * @param[in] index region index [0,...,size()-1].
119
 *
120
 * Returns a const pointer to the region with the specified @p index.
121
 ***************************************************************************/
122
inline
123
const GSkyRegion* GSkyRegions::operator[](const int& index) const
124
{
125
    return (m_regions[index]);
126
}
127

    
128

    
129
/***********************************************************************//**
130
 * @brief Return number of regions in container
131
 *
132
 * @return Number of regions in container.
133
 *
134
 * Returns the number of regions in the region container.
135
 ***************************************************************************/
136
inline
137
int GSkyRegions::size(void) const
138
{
139
    return (m_regions.size());
140
}
141

    
142

    
143
/***********************************************************************//**
144
 * @brief Signals if there are no regions in container
145
 *
146
 * @return True if container is empty, false otherwise.
147
 *
148
 * Signals if the region container does not contain any region.
149
 ***************************************************************************/
150
inline
151
bool GSkyRegions::isempty(void) const
152
{
153
    return (m_regions.empty());
154
}
155

    
156

    
157
/***********************************************************************//**
158
 * @brief Reserves space for regions in container
159
 *
160
 * @param[in] num Number of regions
161
 *
162
 * Reserves space for @p num regions in the container.
163
 ***************************************************************************/
164
inline
165
void GSkyRegions::reserve(const int& num)
166
{
167
    m_regions.reserve(num);
168
    return;
169
}
170

    
171
#endif /* GSKYREGIONS_HPP */