Commit b2297ef02eb8a100cfd87dbc2a3bc5e484e39402
1 parent
6393b152
Add GCOMDris container class
Showing
5 changed files
with
712 additions
and
2 deletions
inst/com/Makefile.am
1 | 1 | ############################################################################# |
2 | 2 | # Makefile.am for com module # |
3 | 3 | # ------------------------------------------------------------------------- # |
4 | -# Copyright (C) 2016-2022 Juergen Knoedlseder # | |
4 | +# Copyright (C) 2016-2023 Juergen Knoedlseder # | |
5 | 5 | # ------------------------------------------------------------------------- # |
6 | 6 | # # |
7 | 7 | # This program is free software: you can redistribute it and/or modify # |
... | ... | @@ -39,6 +39,7 @@ sources = src/com_helpers_response_vector.cpp \ |
39 | 39 | src/GCOMSupport.cpp \ |
40 | 40 | src/GCOMSelection.cpp \ |
41 | 41 | src/GCOMStatus.cpp \ |
42 | + src/GCOMDris.cpp \ | |
42 | 43 | src/GCOMDri.cpp \ |
43 | 44 | src/GCOMOads.cpp \ |
44 | 45 | src/GCOMOad.cpp \ |
... | ... | @@ -65,6 +66,7 @@ sources = src/com_helpers_response_vector.cpp \ |
65 | 66 | pkginclude_HEADERS = include/GCOMTools.hpp \ |
66 | 67 | include/GCOMSelection.hpp \ |
67 | 68 | include/GCOMStatus.hpp \ |
69 | + include/GCOMDris.hpp \ | |
68 | 70 | include/GCOMDri.hpp \ |
69 | 71 | include/GCOMOads.hpp \ |
70 | 72 | include/GCOMOad.hpp \ | ... | ... |
inst/com/include/GCOMDris.hpp
0 → 100644
1 | +/*************************************************************************** | |
2 | + * GCOMDris.hpp - COMPTEL Data Space container class * | |
3 | + * ----------------------------------------------------------------------- * | |
4 | + * copyright (C) 2023 by Juergen Knodlseder * | |
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 GCOMDris.hpp | |
23 | + * @brief COMPTEL Data Space container class definition | |
24 | + * @author Juergen Knodlseder | |
25 | + */ | |
26 | + | |
27 | +#ifndef GCOMDRIS_HPP | |
28 | +#define GCOMDRIS_HPP | |
29 | + | |
30 | +/* __ Includes ___________________________________________________________ */ | |
31 | +#include <string> | |
32 | +#include <vector> | |
33 | +#include "GCOMDri.hpp" | |
34 | +#include "GContainer.hpp" | |
35 | + | |
36 | +/* __ Forward declarations _______________________________________________ */ | |
37 | +//class GFilename; | |
38 | +//class GFitsTable; | |
39 | + | |
40 | +/* __ Constants __________________________________________________________ */ | |
41 | + | |
42 | + | |
43 | +/***********************************************************************//** | |
44 | + * @class GCOMDris | |
45 | + * | |
46 | + * @brief COMPTEL Data Space container class | |
47 | + * | |
48 | + * The COMPTEL Data Space container class holds instances of the COMPTEL | |
49 | + * Data Space. It allows for an efficient computation of data and response | |
50 | + * information for multiple energy bins. | |
51 | + ***************************************************************************/ | |
52 | +class GCOMDris : public GContainer { | |
53 | + | |
54 | +public: | |
55 | + // Constructors and destructors | |
56 | + GCOMDris(void); | |
57 | + GCOMDris(const GCOMDris& dris); | |
58 | + virtual ~GCOMDris(void); | |
59 | + | |
60 | + // Operators | |
61 | + GCOMDris& operator=(const GCOMDris& dris); | |
62 | + GCOMDri& operator[](const int& index); | |
63 | + const GCOMDri& operator[](const int& index) const; | |
64 | + | |
65 | + // Methods | |
66 | + void clear(void); | |
67 | + GCOMDris* clone(void) const; | |
68 | + std::string classname(void) const; | |
69 | + GCOMDri& at(const int& index); | |
70 | + const GCOMDri& at(const int& index) const; | |
71 | + int size(void) const; | |
72 | + bool is_empty(void) const; | |
73 | + GCOMDri& append(const GCOMDri& dri); | |
74 | + GCOMDri& insert(const int& index, const GCOMDri& dri); | |
75 | + void remove(const int& index); | |
76 | + void reserve(const int& num); | |
77 | + void extend(const GCOMDris& dris); | |
78 | + std::string print(const GChatter& chatter = NORMAL) const; | |
79 | + | |
80 | +protected: | |
81 | + // Protected methods | |
82 | + void init_members(void); | |
83 | + void copy_members(const GCOMDris& dris); | |
84 | + void free_members(void); | |
85 | + | |
86 | + // Protected data members | |
87 | + std::vector<GCOMDri> m_dris; //!< Data space instances | |
88 | +}; | |
89 | + | |
90 | + | |
91 | +/***********************************************************************//** | |
92 | + * @brief Return class name | |
93 | + * | |
94 | + * @return String containing the class name ("GCOMDris"). | |
95 | + ***************************************************************************/ | |
96 | +inline | |
97 | +std::string GCOMDris::classname(void) const | |
98 | +{ | |
99 | + return ("GCOMDris"); | |
100 | +} | |
101 | + | |
102 | + | |
103 | +/***********************************************************************//** | |
104 | + * @brief Return reference to Data space instance | |
105 | + * | |
106 | + * @param[in] index Data space index [0,...,size()-1]. | |
107 | + * | |
108 | + * Returns a reference to the Data space instance with the specified @p index. | |
109 | + ***************************************************************************/ | |
110 | +inline | |
111 | +GCOMDri& GCOMDris::operator[](const int& index) | |
112 | +{ | |
113 | + return (m_dris[index]); | |
114 | +} | |
115 | + | |
116 | + | |
117 | +/***********************************************************************//** | |
118 | + * @brief Return reference to Data space instance (const version) | |
119 | + * | |
120 | + * @param[in] index Data space index [0,...,size()-1]. | |
121 | + * | |
122 | + * Returns a reference to the Data space instance with the specified @p index. | |
123 | + ***************************************************************************/ | |
124 | +inline | |
125 | +const GCOMDri& GCOMDris::operator[](const int& index) const | |
126 | +{ | |
127 | + return (m_dris[index]); | |
128 | +} | |
129 | + | |
130 | + | |
131 | +/***********************************************************************//** | |
132 | + * @brief Return number of Data space instances in container | |
133 | + * | |
134 | + * @return Number of Data space instances in container. | |
135 | + * | |
136 | + * Returns the number of Data space instances in the container. | |
137 | + ***************************************************************************/ | |
138 | +inline | |
139 | +int GCOMDris::size(void) const | |
140 | +{ | |
141 | + return (int)m_dris.size(); | |
142 | +} | |
143 | + | |
144 | + | |
145 | +/***********************************************************************//** | |
146 | + * @brief Signals if there are no Data space instances in container | |
147 | + * | |
148 | + * @return True if container is empty, false otherwise. | |
149 | + * | |
150 | + * Signals if the Data space instances container does not contain any Data | |
151 | + * space instances. | |
152 | + ***************************************************************************/ | |
153 | +inline | |
154 | +bool GCOMDris::is_empty(void) const | |
155 | +{ | |
156 | + return (m_dris.empty()); | |
157 | +} | |
158 | + | |
159 | + | |
160 | +/***********************************************************************//** | |
161 | + * @brief Reserves space for Data space instances in container | |
162 | + * | |
163 | + * @param[in] num Number of Data space instances. | |
164 | + * | |
165 | + * Reserves space for @p num Data space instances in the container. | |
166 | + ***************************************************************************/ | |
167 | +inline | |
168 | +void GCOMDris::reserve(const int& num) | |
169 | +{ | |
170 | + m_dris.reserve(num); | |
171 | + return; | |
172 | +} | |
173 | + | |
174 | +#endif /* GCOMDRIS_HPP */ | ... | ... |
inst/com/pyext/GCOMDris.i
0 → 100644
1 | +/*************************************************************************** | |
2 | + * GCOMDris.i - COMPTEL Data Space container class * | |
3 | + * ----------------------------------------------------------------------- * | |
4 | + * copyright (C) 2023 by Juergen Knodlseder * | |
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 GCOMDris.i | |
23 | + * @brief COMPTEL Data Space container class definition | |
24 | + * @author Juergen Knodlseder | |
25 | + */ | |
26 | +%{ | |
27 | +/* Put headers and other declarations here that are needed for compilation */ | |
28 | +#include "GCOMDris.hpp" | |
29 | +%} | |
30 | + | |
31 | + | |
32 | +/***********************************************************************//** | |
33 | + * @class GCOMDris | |
34 | + * | |
35 | + * @brief COMPTEL Data Space container class | |
36 | + ***************************************************************************/ | |
37 | +class GCOMDris : public GContainer { | |
38 | + | |
39 | +public: | |
40 | + // Constructors and destructors | |
41 | + GCOMDris(void); | |
42 | + GCOMDris(const GCOMDris& dris); | |
43 | + virtual ~GCOMDris(void); | |
44 | + | |
45 | + // Methods | |
46 | + void clear(void); | |
47 | + GCOMDris* clone(void) const; | |
48 | + std::string classname(void) const; | |
49 | + int size(void) const; | |
50 | + bool is_empty(void) const; | |
51 | + GCOMDri& append(const GCOMDri& dri); | |
52 | + GCOMDri& insert(const int& index, const GCOMDri& dri); | |
53 | + void remove(const int& index); | |
54 | + void reserve(const int& num); | |
55 | + void extend(const GCOMDris& dris); | |
56 | +}; | |
57 | + | |
58 | + | |
59 | +/***********************************************************************//** | |
60 | + * @brief GCOMDris class extension | |
61 | + ***************************************************************************/ | |
62 | +%extend GCOMDris { | |
63 | + GCOMDri& __getitem__(const int& index) { | |
64 | + // Counting from start, e.g. [2] | |
65 | + if (index >= 0 && index < self->size()) { | |
66 | + return (*self)[index]; | |
67 | + } | |
68 | + // Counting from end, e.g. [-1] | |
69 | + else if (index < 0 && self->size()+index >= 0) { | |
70 | + return (*self)[self->size()+index]; | |
71 | + } | |
72 | + else { | |
73 | + throw GException::out_of_range("__getitem__(int)", "DRI index", | |
74 | + index, self->size()); | |
75 | + } | |
76 | + } | |
77 | + GCOMDris* __getitem__(PyObject *param) { | |
78 | + if (PySlice_Check(param)) { | |
79 | + Py_ssize_t start = 0; | |
80 | + Py_ssize_t stop = 0; | |
81 | + Py_ssize_t step = 0; | |
82 | + Py_ssize_t len = self->size(); | |
83 | + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) { | |
84 | + GCOMDris* dris = new GCOMDris; | |
85 | + if (step > 0) { | |
86 | + for (int i = (int)start; i < (int)stop; i += (int)step) { | |
87 | + dris->append((*self)[i]); | |
88 | + } | |
89 | + } | |
90 | + else { | |
91 | + for (int i = (int)start; i > (int)stop; i += (int)step) { | |
92 | + dris->append((*self)[i]); | |
93 | + } | |
94 | + } | |
95 | + return dris; | |
96 | + } | |
97 | + else { | |
98 | + throw GException::invalid_argument("__getitem__(PyObject)", | |
99 | + "Invalid slice indices"); | |
100 | + } | |
101 | + } | |
102 | + else { | |
103 | + throw GException::invalid_argument("__getitem__(PyObject)",""); | |
104 | + } | |
105 | + } | |
106 | + void __setitem__(const int& index, const GCOMDri& val) { | |
107 | + // Counting from start, e.g. [2] | |
108 | + if (index >= 0 && index < self->size()) { | |
109 | + (*self)[index] = val; | |
110 | + } | |
111 | + // Counting from end, e.g. [-1] | |
112 | + else if (index < 0 && self->size()+index >= 0) { | |
113 | + (*self)[self->size()+index] = val; | |
114 | + } | |
115 | + else { | |
116 | + throw GException::out_of_range("__setitem__(int)", "DRI index", | |
117 | + index, self->size()); | |
118 | + } | |
119 | + } | |
120 | + GCOMDris copy() { | |
121 | + return (*self); | |
122 | + } | |
123 | +%pythoncode { | |
124 | + def __getstate__(self): | |
125 | + state = tuple([x for x in self]), | |
126 | + return state | |
127 | + def __setstate__(self, state): | |
128 | + self.__init__() | |
129 | + size = len(state[0]) | |
130 | + self.reserve(size) | |
131 | + for x in state[0]: | |
132 | + self.append(x) | |
133 | +} | |
134 | +}; | ... | ... |
inst/com/pyext/com.i
1 | 1 | /*************************************************************************** |
2 | 2 | * com.i - COMPTEL module * |
3 | 3 | * ----------------------------------------------------------------------- * |
4 | - * copyright (C) 2012-2022 by Juergen Knoedlseder * | |
4 | + * copyright (C) 2012-2023 by Juergen Knoedlseder * | |
5 | 5 | * ----------------------------------------------------------------------- * |
6 | 6 | * * |
7 | 7 | * This program is free software: you can redistribute it and/or modify * |
... | ... | @@ -122,5 +122,6 @@ |
122 | 122 | %include "GCOMBvc.i" |
123 | 123 | %include "GCOMBvcs.i" |
124 | 124 | %include "GCOMDri.i" |
125 | +%include "GCOMDris.i" | |
125 | 126 | %include "GCOMStatus.i" |
126 | 127 | %include "GCOMSelection.i" | ... | ... |
inst/com/src/GCOMDris.cpp
0 → 100644
1 | +/*************************************************************************** | |
2 | + * GCOMDris.cpp - COMPTEL Data Space container class * | |
3 | + * ----------------------------------------------------------------------- * | |
4 | + * copyright (C) 2023 by Juergen Knodlseder * | |
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 GCOMDris.hpp | |
23 | + * @brief COMPTEL Data Space container class implementation | |
24 | + * @author Juergen Knodlseder | |
25 | + */ | |
26 | + | |
27 | +/* __ Includes ___________________________________________________________ */ | |
28 | +#ifdef HAVE_CONFIG_H | |
29 | +#include <config.h> | |
30 | +#endif | |
31 | +#include "GException.hpp" | |
32 | +#include "GMath.hpp" | |
33 | +#include "GCOMTools.hpp" | |
34 | +#include "GCOMSupport.hpp" | |
35 | +#include "GCOMDris.hpp" | |
36 | + | |
37 | +/* __ Method name definitions ____________________________________________ */ | |
38 | +#define G_AT "GCOMDris::at(int&)" | |
39 | +#define G_INSERT "GCOMDris::insert(int&, GCOMDri&)" | |
40 | +#define G_REMOVE "GCOMDris::remove(int&)" | |
41 | + | |
42 | +/* __ Macros _____________________________________________________________ */ | |
43 | + | |
44 | +/* __ Coding definitions _________________________________________________ */ | |
45 | + | |
46 | +/* __ Debug definitions __________________________________________________ */ | |
47 | + | |
48 | + | |
49 | +/*========================================================================== | |
50 | + = = | |
51 | + = Constructors/destructors = | |
52 | + = = | |
53 | + ==========================================================================*/ | |
54 | + | |
55 | +/***********************************************************************//** | |
56 | + * @brief Void constructor | |
57 | + * | |
58 | + * Constructs an empty Data Space container. | |
59 | + ***************************************************************************/ | |
60 | +GCOMDris::GCOMDris(void) | |
61 | +{ | |
62 | + // Initialise class members | |
63 | + init_members(); | |
64 | + | |
65 | + // Return | |
66 | + return; | |
67 | +} | |
68 | + | |
69 | + | |
70 | +/***********************************************************************//** | |
71 | + * @brief Copy constructor | |
72 | + * | |
73 | + * @param[in] dris Data Space container. | |
74 | + ***************************************************************************/ | |
75 | +GCOMDris::GCOMDris(const GCOMDris& dris) | |
76 | +{ | |
77 | + // Initialise class members | |
78 | + init_members(); | |
79 | + | |
80 | + // Copy members | |
81 | + copy_members(dris); | |
82 | + | |
83 | + // Return | |
84 | + return; | |
85 | +} | |
86 | + | |
87 | + | |
88 | +/***********************************************************************//** | |
89 | + * @brief Destructor | |
90 | + ***************************************************************************/ | |
91 | +GCOMDris::~GCOMDris(void) | |
92 | +{ | |
93 | + // Free members | |
94 | + free_members(); | |
95 | + | |
96 | + // Return | |
97 | + return; | |
98 | +} | |
99 | + | |
100 | + | |
101 | +/*========================================================================== | |
102 | + = = | |
103 | + = Operators = | |
104 | + = = | |
105 | + ==========================================================================*/ | |
106 | + | |
107 | +/***********************************************************************//** | |
108 | + * @brief Assignment operator | |
109 | + * | |
110 | + * @param[in] dris Data Space container. | |
111 | + * @return Data Space container. | |
112 | + ***************************************************************************/ | |
113 | +GCOMDris& GCOMDris::operator=(const GCOMDris& dris) | |
114 | +{ | |
115 | + // Execute only if object is not identical | |
116 | + if (this != &dris) { | |
117 | + | |
118 | + // Free members | |
119 | + free_members(); | |
120 | + | |
121 | + // Initialise private members | |
122 | + init_members(); | |
123 | + | |
124 | + // Copy members | |
125 | + copy_members(dris); | |
126 | + | |
127 | + } // endif: object was not identical | |
128 | + | |
129 | + // Return this object | |
130 | + return *this; | |
131 | +} | |
132 | + | |
133 | + | |
134 | +/*========================================================================== | |
135 | + = = | |
136 | + = Public methods = | |
137 | + = = | |
138 | + ==========================================================================*/ | |
139 | + | |
140 | +/***********************************************************************//** | |
141 | + * @brief Clear Data Space container | |
142 | + ***************************************************************************/ | |
143 | +void GCOMDris::clear(void) | |
144 | +{ | |
145 | + // Free members | |
146 | + free_members(); | |
147 | + | |
148 | + // Initialise private members | |
149 | + init_members(); | |
150 | + | |
151 | + // Return | |
152 | + return; | |
153 | +} | |
154 | + | |
155 | + | |
156 | +/***********************************************************************//** | |
157 | + * @brief Clone Data Space container | |
158 | + * | |
159 | + * @return Pointer to deep copy of Data Space container. | |
160 | + ***************************************************************************/ | |
161 | +GCOMDris* GCOMDris::clone(void) const | |
162 | +{ | |
163 | + return new GCOMDris(*this); | |
164 | +} | |
165 | + | |
166 | + | |
167 | +/***********************************************************************//** | |
168 | + * @brief Return reference to Data Space | |
169 | + * | |
170 | + * @param[in] index Data Space index [0,...,size()-1]. | |
171 | + * | |
172 | + * @exception GException::out_of_range | |
173 | + * Data Space index is out of range. | |
174 | + * | |
175 | + * Returns a reference to the Data Space with the specified @p index. | |
176 | + ***************************************************************************/ | |
177 | +GCOMDri& GCOMDris::at(const int& index) | |
178 | +{ | |
179 | + // Raise exception if index is out of range | |
180 | + if (index < 0 || index >= size()) { | |
181 | + throw GException::out_of_range(G_AT, "Data Space index", | |
182 | + index, size()); | |
183 | + } | |
184 | + | |
185 | + // Return reference | |
186 | + return m_dris[index]; | |
187 | +} | |
188 | + | |
189 | + | |
190 | +/***********************************************************************//** | |
191 | + * @brief Return reference to Data Space (const version) | |
192 | + * | |
193 | + * @param[in] index Data Space index [0,...,size()-1]. | |
194 | + * | |
195 | + * @exception GException::out_of_range | |
196 | + * Data Space index is out of range. | |
197 | + * | |
198 | + * Returns a reference to the Data Space with the specified @p index. | |
199 | + ***************************************************************************/ | |
200 | +const GCOMDri& GCOMDris::at(const int& index) const | |
201 | +{ | |
202 | + // Raise exception if index is out of range | |
203 | + if (index < 0 || index >= size()) { | |
204 | + throw GException::out_of_range(G_AT, "Data Space index", | |
205 | + index, size()); | |
206 | + } | |
207 | + | |
208 | + // Return reference | |
209 | + return m_dris[index]; | |
210 | +} | |
211 | + | |
212 | + | |
213 | +/***********************************************************************//** | |
214 | + * @brief Append Data Space to container | |
215 | + * | |
216 | + * @param[in] dri Data Space. | |
217 | + * @return Reference to appended Data Space. | |
218 | + * | |
219 | + * Appends Data Space to the container by making a deep copy of the Data | |
220 | + * Space. | |
221 | + ***************************************************************************/ | |
222 | +GCOMDri& GCOMDris::append(const GCOMDri& dri) | |
223 | +{ | |
224 | + // Append dri to list | |
225 | + m_dris.push_back(dri); | |
226 | + | |
227 | + // Return reference | |
228 | + return m_dris[size()-1]; | |
229 | +} | |
230 | + | |
231 | + | |
232 | +/***********************************************************************//** | |
233 | + * @brief Insert Data Space into container | |
234 | + * | |
235 | + * @param[in] index Data Space index (0,...,size()-1). | |
236 | + * @param[in] dri Data Space. | |
237 | + * | |
238 | + * @exception GException::out_of_range | |
239 | + * Data Space index is out of range. | |
240 | + * | |
241 | + * Inserts a Data Space into the container before the Data Space with the | |
242 | + * specified @p index. | |
243 | + ***************************************************************************/ | |
244 | +GCOMDri& GCOMDris::insert(const int& index, const GCOMDri& dri) | |
245 | +{ | |
246 | + // Compile option: raise exception if index is out of range | |
247 | + #if defined(G_RANGE_CHECK) | |
248 | + if (is_empty()) { | |
249 | + if (index > 0) { | |
250 | + throw GException::out_of_range(G_INSERT, "Data Space index", | |
251 | + index, size()); | |
252 | + } | |
253 | + } | |
254 | + else { | |
255 | + if (index < 0 || index >= size()) { | |
256 | + throw GException::out_of_range(G_INSERT, "Data Space index", | |
257 | + index, size()); | |
258 | + } | |
259 | + } | |
260 | + #endif | |
261 | + | |
262 | + // Inserts Data Space | |
263 | + m_dris.insert(m_dris.begin()+index, dri); | |
264 | + | |
265 | + // Return reference | |
266 | + return m_dris[index]; | |
267 | +} | |
268 | + | |
269 | + | |
270 | +/***********************************************************************//** | |
271 | + * @brief Remove Data Space from container | |
272 | + * | |
273 | + * @param[in] index Data Space index (0,...,size()-1). | |
274 | + * | |
275 | + * @exception GException::out_of_range | |
276 | + * Data Space index is out of range. | |
277 | + * | |
278 | + * Remove Data Space of specified @p index from container. | |
279 | + ***************************************************************************/ | |
280 | +void GCOMDris::remove(const int& index) | |
281 | +{ | |
282 | + // Compile option: raise exception if index is out of range | |
283 | + #if defined(G_RANGE_CHECK) | |
284 | + if (index < 0 || index >= size()) { | |
285 | + throw GException::out_of_range(G_REMOVE, "Data Space index", | |
286 | + index, size()); | |
287 | + } | |
288 | + #endif | |
289 | + | |
290 | + // Erase Data Space from container | |
291 | + m_dris.erase(m_dris.begin() + index); | |
292 | + | |
293 | + // Return | |
294 | + return; | |
295 | +} | |
296 | + | |
297 | + | |
298 | +/***********************************************************************//** | |
299 | + * @brief Append Data Space container | |
300 | + * | |
301 | + * @param[in] oads Data Space container. | |
302 | + * | |
303 | + * Append Data Space container to the container. | |
304 | + ***************************************************************************/ | |
305 | +void GCOMDris::extend(const GCOMDris& dris) | |
306 | +{ | |
307 | + // Do nothing if Data Space container is empty | |
308 | + if (!dris.is_empty()) { | |
309 | + | |
310 | + // Get size. Note that we extract the size first to avoid an | |
311 | + // endless loop that arises when a container is appended to | |
312 | + // itself. | |
313 | + int num = dris.size(); | |
314 | + | |
315 | + // Reserve enough space | |
316 | + reserve(size() + num); | |
317 | + | |
318 | + // Loop over all elements and append them to container | |
319 | + for (int i = 0; i < num; ++i) { | |
320 | + m_dris.push_back(dris[i]); | |
321 | + } | |
322 | + | |
323 | + } // endif: Data Space container was not empty | |
324 | + | |
325 | + // Return | |
326 | + return; | |
327 | +} | |
328 | + | |
329 | + | |
330 | +/***********************************************************************//** | |
331 | + * @brief Print Data Space container | |
332 | + * | |
333 | + * @param[in] chatter Chattiness. | |
334 | + * @return String containing Data Space container information. | |
335 | + ***************************************************************************/ | |
336 | +std::string GCOMDris::print(const GChatter& chatter) const | |
337 | +{ | |
338 | + // Initialise result string | |
339 | + std::string result; | |
340 | + | |
341 | + // Continue only if chatter is not silent | |
342 | + if (chatter != SILENT) { | |
343 | + | |
344 | + // Append header | |
345 | + result.append("=== GCOMDris ==="); | |
346 | + | |
347 | + // Append container information | |
348 | + result.append("\n"+gammalib::parformat("Number of DRIs")); | |
349 | + result.append(gammalib::str(size())); | |
350 | + | |
351 | + } // endif: chatter was not silent | |
352 | + | |
353 | + // Return result | |
354 | + return result; | |
355 | +} | |
356 | + | |
357 | + | |
358 | +/*========================================================================== | |
359 | + = = | |
360 | + = Private methods = | |
361 | + = = | |
362 | + ==========================================================================*/ | |
363 | + | |
364 | +/***********************************************************************//** | |
365 | + * @brief Initialise class members | |
366 | + ***************************************************************************/ | |
367 | +void GCOMDris::init_members(void) | |
368 | +{ | |
369 | + // Initialise members | |
370 | + m_dris.clear(); | |
371 | + | |
372 | + // Return | |
373 | + return; | |
374 | +} | |
375 | + | |
376 | + | |
377 | +/***********************************************************************//** | |
378 | + * @brief Copy class members | |
379 | + * | |
380 | + * @param[in] dris Data Space container. | |
381 | + ***************************************************************************/ | |
382 | +void GCOMDris::copy_members(const GCOMDris& dris) | |
383 | +{ | |
384 | + // Copy members | |
385 | + m_dris = dris.m_dris; | |
386 | + | |
387 | + // Return | |
388 | + return; | |
389 | +} | |
390 | + | |
391 | + | |
392 | +/***********************************************************************//** | |
393 | + * @brief Delete class members | |
394 | + ***************************************************************************/ | |
395 | +void GCOMDris::free_members(void) | |
396 | +{ | |
397 | + // Return | |
398 | + return; | |
399 | +} | ... | ... |