GSkyRegion.hpp

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

Download (6.17 KB)

 
1
/***************************************************************************
2
 *         GSkyRegion.hpp - Abstract virtual sky region base 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 GSkyRegion.hpp
23
 * @brief Abstract sky region base class interface definition
24
 * @author Pierrick Martin
25
 */
26

    
27
#ifndef GSKYREGION_HPP
28
#define GSKYREGION_HPP
29

    
30
/* __ Includes ___________________________________________________________ */
31
#include <vector>
32
#include <string>
33
#include "GBase.hpp"
34
#include "GXmlElement.hpp"
35

    
36

    
37
/***********************************************************************//**
38
 * @class GSkyRegion
39
 *
40
 * @brief Abstract interface for the sky region class
41
 *
42
 * This class provides an abstract interface for a sky region. The sky region 
43
 * is defined by an array of parameters, the meaning of which is specific 
44
 * to the derived class where the region type or shape is defined. 
45
 * The class holds several properties such as solid angle subtended by the 
46
 * region ... etc
47
 *
48
 ***************************************************************************/
49
class GSkyRegion : public GBase {
50

    
51
public:
52
    // Constructors and destructors
53
    GSkyRegion(void);
54
    GSkyRegion(const GSkyRegion& region);
55
    explicit GSkyRegion(const GXmlElement& xml);  
56
    virtual ~GSkyRegion(void);
57

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

    
65
    // Pure virtual methods
66
    virtual void         clear(void) = 0;
67
    virtual GSkyRegion*  clone(void) const = 0;
68
    virtual std::string  type(void) const = 0;
69
    virtual void         read(const GXmlElement& xml) = 0;
70
    virtual void         write(GXmlElement& xml) const = 0;
71
    virtual std::string  print(const GChatter& chatter = NORMAL) const = 0;
72

    
73
    // Implemented methods
74
    int                 size(void) const;
75
    const double        at(const int& index) const;
76
    bool                haspar(const std::string& name) const;
77
    const std::string&  name(void) const;
78
    void                name(const std::string& name);
79
    std::string         ids(void) const;
80
    void                ids(const std::string& ids);
81

    
82
protected:
83
    // Protected methods
84
    void         init_members(void);
85
    void         copy_members(const GSkyRegion& region);
86
    void         free_members(void);
87
    std::string  print_attributes(void) const;
88

    
89
    // Protected members
90
    std::string                  m_name;         //!< Model namespace
91
    std::vector<std::string>     m_ids;          //!< Identifiers to which region applies
92
    std::vector<double>          m_pars;         //!< Pointers to all region parameters
93
};
94

    
95

    
96
/***********************************************************************//**
97
 * @brief Returns reference to region parameter by index
98
 *
99
 * @param[in] index Parameter index [0,...,size()-1].
100
 * @return Reference to region parameter.
101
 *
102
 * Returns a reference to the region parameter of the specified @p index.
103
 ***************************************************************************/
104
inline
105
double GSkyRegion::operator[](const int& index)
106
{
107
    // Return reference
108
    return *(m_pars[index]);
109
}
110

    
111

    
112
/***********************************************************************//**
113
 * @brief Returns reference to region parameter by index (const version)
114
 *
115
 * @param[in] index Parameter index [0,...,size()-1].
116
 * @return Const reference to region parameter.
117
 *
118
 * Returns a const reference to the region parameter of the specified
119
 ***************************************************************************/
120
inline
121
const double GSkyRegion::operator[](const int& index) const
122
{
123
    // Return reference
124
    return *(m_pars[index]);
125
}
126

    
127

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

    
141

    
142
/***********************************************************************//**
143
 * @brief Return parameter name
144
 *
145
 * @return Parameter name.
146
 *
147
 * Returns the parameter name.
148
 ***************************************************************************/
149
inline
150
const std::string& GSkyRegion::name(void) const
151
{
152
    return m_name;
153
}
154

    
155

    
156
/***********************************************************************//**
157
 * @brief Set parameter name
158
 *
159
 * @param[in] name Parameter name.
160
 *
161
 * Set the parameter name.
162
 ***************************************************************************/
163
inline
164
void GSkyRegion::name(const std::string& name)
165
{
166
    m_name = name;
167
    return;
168
}
169

    
170
#endif /* GSKYREGION_HPP */