Commit 4b8907dd64a644f28e456575aee18634968206ca

Authored by Jürgen Knödlseder
1 parent 74b633f0

Remove index range check from operator[] and declare operator inline. Add at() m…

…ethod for index range check. Put size() method inline.
include/GModelSpatial.hpp
@@ -97,8 +97,10 @@ public: @@ -97,8 +97,10 @@ public:
97 virtual std::string print(const GChatter& chatter = NORMAL) const = 0; 97 virtual std::string print(const GChatter& chatter = NORMAL) const = 0;
98 98
99 // Methods 99 // Methods
100 - int size(void) const;  
101 - void autoscale(void); 100 + GModelPar& at(const int& index);
  101 + const GModelPar& at(const int& index) const;
  102 + int size(void) const;
  103 + void autoscale(void);
102 104
103 protected: 105 protected:
104 // Protected methods 106 // Protected methods
@@ -112,6 +114,36 @@ protected: @@ -112,6 +114,36 @@ protected:
112 114
113 115
114 /***********************************************************************//** 116 /***********************************************************************//**
  117 + * @brief Returns model parameter
  118 + *
  119 + * @param[in] index Parameter index [0,...,size()-1].
  120 + * @return Model parameter.
  121 + *
  122 + * Returns model parameter without @p index range checking.
  123 + ***************************************************************************/
  124 +inline
  125 +GModelPar& GModelSpatial::operator[](const int& index)
  126 +{
  127 + return *(m_pars[index]);
  128 +}
  129 +
  130 +
  131 +/***********************************************************************//**
  132 + * @brief Returns model parameter (const version)
  133 + *
  134 + * @param[in] index Parameter index [0,...,size()-1].
  135 + * @return Model parameter.
  136 + *
  137 + * Returns model parameter without @p index range checking.
  138 + ***************************************************************************/
  139 +inline
  140 +const GModelPar& GModelSpatial::operator[](const int& index) const
  141 +{
  142 + return *(m_pars[index]);
  143 +}
  144 +
  145 +
  146 +/***********************************************************************//**
115 * @brief Return number of parameters 147 * @brief Return number of parameters
116 * 148 *
117 * @return Number of parameters in spatial model component. 149 * @return Number of parameters in spatial model component.
include/GModelSpectral.hpp
1 /*************************************************************************** 1 /***************************************************************************
2 * GModelSpectral.hpp - Abstract spectral model base class * 2 * GModelSpectral.hpp - Abstract spectral model base class *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2009-2013 by Juergen Knoedlseder * 4 + * copyright (C) 2009-2014 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -97,8 +97,10 @@ public: @@ -97,8 +97,10 @@ public:
97 virtual std::string print(const GChatter& chatter = NORMAL) const = 0; 97 virtual std::string print(const GChatter& chatter = NORMAL) const = 0;
98 98
99 // Methods 99 // Methods
100 - int size(void) const;  
101 - void autoscale(void); 100 + GModelPar& at(const int& index);
  101 + const GModelPar& at(const int& index) const;
  102 + int size(void) const;
  103 + void autoscale(void);
102 104
103 protected: 105 protected:
104 // Protected methods 106 // Protected methods
@@ -110,4 +112,48 @@ protected: @@ -110,4 +112,48 @@ protected:
110 std::vector<GModelPar*> m_pars; //!< Parameter pointers 112 std::vector<GModelPar*> m_pars; //!< Parameter pointers
111 }; 113 };
112 114
  115 +
  116 +/***********************************************************************//**
  117 + * @brief Returns model parameter
  118 + *
  119 + * @param[in] index Parameter index [0,...,size()-1].
  120 + * @return Model parameter.
  121 + *
  122 + * Returns model parameter without @p index range checking.
  123 + ***************************************************************************/
  124 +inline
  125 +GModelPar& GModelSpectral::operator[](const int& index)
  126 +{
  127 + return *(m_pars[index]);
  128 +}
  129 +
  130 +
  131 +/***********************************************************************//**
  132 + * @brief Returns model parameter (const version)
  133 + *
  134 + * @param[in] index Parameter index [0,...,size()-1].
  135 + * @return Model parameter.
  136 + *
  137 + * Returns model parameter without @p index range checking.
  138 + ***************************************************************************/
  139 +inline
  140 +const GModelPar& GModelSpectral::operator[](const int& index) const
  141 +{
  142 + return *(m_pars[index]);
  143 +}
  144 +
  145 +
  146 +/***********************************************************************//**
  147 + * @brief Return number of parameters
  148 + *
  149 + * @return Number of parameters in spectral model component.
  150 + *
  151 + * Returns the number of parameters in the spectral model component.
  152 + ***************************************************************************/
  153 +inline
  154 +int GModelSpectral::size(void) const
  155 +{
  156 + return (m_pars.size());
  157 +}
  158 +
113 #endif /* GMODELSPECTRAL_HPP */ 159 #endif /* GMODELSPECTRAL_HPP */
include/GModelTemporal.hpp
1 /*************************************************************************** 1 /***************************************************************************
2 * GModelTemporal.hpp - Abstract temporal model base class * 2 * GModelTemporal.hpp - Abstract temporal model base class *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2009-2013 by Juergen Knoedlseder * 4 + * copyright (C) 2009-2014 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -76,8 +76,10 @@ public: @@ -76,8 +76,10 @@ public:
76 virtual std::string print(const GChatter& chatter = NORMAL) const = 0; 76 virtual std::string print(const GChatter& chatter = NORMAL) const = 0;
77 77
78 // Methods 78 // Methods
79 - int size(void) const;  
80 - void autoscale(void); 79 + GModelPar& at(const int& index);
  80 + const GModelPar& at(const int& index) const;
  81 + int size(void) const;
  82 + void autoscale(void);
81 83
82 protected: 84 protected:
83 // Protected methods 85 // Protected methods
@@ -89,4 +91,48 @@ protected: @@ -89,4 +91,48 @@ protected:
89 std::vector<GModelPar*> m_pars; //!< Parameter pointers 91 std::vector<GModelPar*> m_pars; //!< Parameter pointers
90 }; 92 };
91 93
  94 +
  95 +/***********************************************************************//**
  96 + * @brief Returns model parameter
  97 + *
  98 + * @param[in] index Parameter index [0,...,size()-1].
  99 + * @return Model parameter.
  100 + *
  101 + * Returns model parameter without @p index range checking.
  102 + ***************************************************************************/
  103 +inline
  104 +GModelPar& GModelTemporal::operator[](const int& index)
  105 +{
  106 + return *(m_pars[index]);
  107 +}
  108 +
  109 +
  110 +/***********************************************************************//**
  111 + * @brief Returns model parameter (const version)
  112 + *
  113 + * @param[in] index Parameter index [0,...,size()-1].
  114 + * @return Model parameter.
  115 + *
  116 + * Returns model parameter without @p index range checking.
  117 + ***************************************************************************/
  118 +inline
  119 +const GModelPar& GModelTemporal::operator[](const int& index) const
  120 +{
  121 + return *(m_pars[index]);
  122 +}
  123 +
  124 +
  125 +/***********************************************************************//**
  126 + * @brief Return number of parameters
  127 + *
  128 + * @return Number of parameters in temporal model component.
  129 + *
  130 + * Returns the number of parameters in the temporal model component.
  131 + ***************************************************************************/
  132 +inline
  133 +int GModelTemporal::size(void) const
  134 +{
  135 + return (m_pars.size());
  136 +}
  137 +
92 #endif /* GMODELTEMPORAL_HPP */ 138 #endif /* GMODELTEMPORAL_HPP */
pyext/GModelSpatial.i
@@ -57,8 +57,9 @@ public: @@ -57,8 +57,9 @@ public:
57 virtual void write(GXmlElement& xml) const = 0; 57 virtual void write(GXmlElement& xml) const = 0;
58 58
59 // Methods 59 // Methods
60 - int size(void) const;  
61 - void autoscale(void); 60 + GModelPar& at(const int& index);
  61 + int size(void) const;
  62 + void autoscale(void);
62 }; 63 };
63 64
64 65
pyext/GModelSpectral.i
@@ -61,8 +61,9 @@ public: @@ -61,8 +61,9 @@ public:
61 virtual void write(GXmlElement& xml) const = 0; 61 virtual void write(GXmlElement& xml) const = 0;
62 62
63 // Methods 63 // Methods
64 - int size(void) const;  
65 - void autoscale(void); 64 + GModelPar& at(const int& index);
  65 + int size(void) const;
  66 + void autoscale(void);
66 }; 67 };
67 68
68 69
pyext/GModelTemporal.i
@@ -55,8 +55,9 @@ public: @@ -55,8 +55,9 @@ public:
55 virtual void write(GXmlElement& xml) const = 0; 55 virtual void write(GXmlElement& xml) const = 0;
56 56
57 // Methods 57 // Methods
58 - int size(void) const;  
59 - void autoscale(void); 58 + GModelPar& at(const int& index);
  59 + int size(void) const;
  60 + void autoscale(void);
60 }; 61 };
61 62
62 63
src/model/GModelSpatial.cpp
1 /*************************************************************************** 1 /***************************************************************************
2 * GModelSpatial.cpp - Abstract spatial model base class * 2 * GModelSpatial.cpp - Abstract spatial model base class *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2009-2013 by Juergen Knoedlseder * 4 + * copyright (C) 2009-2014 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -32,8 +32,8 @@ @@ -32,8 +32,8 @@
32 #include "GModelSpatial.hpp" 32 #include "GModelSpatial.hpp"
33 33
34 /* __ Method name definitions ____________________________________________ */ 34 /* __ Method name definitions ____________________________________________ */
35 -#define G_ACCESS1 "GModelSpatial::operator[](int&)"  
36 -#define G_ACCESS2 "GModelSpatial::operator[](std::string&)" 35 +#define G_ACCESS "GModelSpatial::operator[](std::string&)"
  36 +#define G_AT "GModelPar& GModelSpatial::at(int&)"
37 37
38 /* __ Macros _____________________________________________________________ */ 38 /* __ Macros _____________________________________________________________ */
39 39
@@ -126,56 +126,6 @@ GModelSpatial&amp; GModelSpatial::operator= (const GModelSpatial&amp; model) @@ -126,56 +126,6 @@ GModelSpatial&amp; GModelSpatial::operator= (const GModelSpatial&amp; model)
126 126
127 127
128 /***********************************************************************//** 128 /***********************************************************************//**
129 - * @brief Return model parameter  
130 - *  
131 - * @param[in] index Parameter index [0,...,size()-1].  
132 - * @return Model parameter reference.  
133 - *  
134 - * @exception GException::out_of_range  
135 - * Parameter index is out of range.  
136 - *  
137 - * Returns reference to the model parameter of specified @p index.  
138 - ***************************************************************************/  
139 -GModelPar& GModelSpatial::operator[](const int& index)  
140 -{  
141 - // Compile option: raise exception if index is out of range  
142 - #if defined(G_RANGE_CHECK)  
143 - if (index < 0 || index >= size()) {  
144 - throw GException::out_of_range(G_ACCESS1, index, 0, size()-1);  
145 - }  
146 - #endif  
147 -  
148 - // Return reference  
149 - return *(m_pars[index]);  
150 -}  
151 -  
152 -  
153 -/***********************************************************************//**  
154 - * @brief Returns model parameter (const version)  
155 - *  
156 - * @param[in] index Parameter index [0,...,size()-1].  
157 - * @return Model parameter reference.  
158 - *  
159 - * @exception GException::out_of_range  
160 - * Parameter index is out of range.  
161 - *  
162 - * Returns reference to the model parameter of specified @p index.  
163 - ***************************************************************************/  
164 -const GModelPar& GModelSpatial::operator[](const int& index) const  
165 -{  
166 - // Compile option: raise exception if index is out of range  
167 - #if defined(G_RANGE_CHECK)  
168 - if (index < 0 || index >= size()) {  
169 - throw GException::out_of_range(G_ACCESS1, index, 0, size()-1);  
170 - }  
171 - #endif  
172 -  
173 - // Return reference  
174 - return *(m_pars[index]);  
175 -}  
176 -  
177 -  
178 -/***********************************************************************//**  
179 * @brief Returns model parameter 129 * @brief Returns model parameter
180 * 130 *
181 * @param[in] name Parameter name. 131 * @param[in] name Parameter name.
@@ -198,7 +148,7 @@ GModelPar&amp; GModelSpatial::operator[](const std::string&amp; name) @@ -198,7 +148,7 @@ GModelPar&amp; GModelSpatial::operator[](const std::string&amp; name)
198 148
199 // Throw exception if parameter name was not found 149 // Throw exception if parameter name was not found
200 if (index >= size()) { 150 if (index >= size()) {
201 - throw GException::par_not_found(G_ACCESS2, name); 151 + throw GException::par_not_found(G_ACCESS, name);
202 } 152 }
203 153
204 // Return reference 154 // Return reference
@@ -229,7 +179,7 @@ const GModelPar&amp; GModelSpatial::operator[](const std::string&amp; name) const @@ -229,7 +179,7 @@ const GModelPar&amp; GModelSpatial::operator[](const std::string&amp; name) const
229 179
230 // Throw exception if parameter name was not found 180 // Throw exception if parameter name was not found
231 if (index >= size()) { 181 if (index >= size()) {
232 - throw GException::par_not_found(G_ACCESS2, name); 182 + throw GException::par_not_found(G_ACCESS, name);
233 } 183 }
234 184
235 // Return reference 185 // Return reference
@@ -244,6 +194,52 @@ const GModelPar&amp; GModelSpatial::operator[](const std::string&amp; name) const @@ -244,6 +194,52 @@ const GModelPar&amp; GModelSpatial::operator[](const std::string&amp; name) const
244 ==========================================================================*/ 194 ==========================================================================*/
245 195
246 /***********************************************************************//** 196 /***********************************************************************//**
  197 + * @brief Returns model parameter
  198 + *
  199 + * @param[in] index Parameter index [0,...,size()-1].
  200 + * @return Model parameter.
  201 + *
  202 + * @exception GException::out_of_range
  203 + * Parameter index is out of range.
  204 + *
  205 + * Returns model parameter with @p index range checking.
  206 + ***************************************************************************/
  207 +GModelPar& GModelSpatial::at(const int& index)
  208 +{
  209 + // Compile option: raise exception if index is out of range
  210 + if (index < 0 || index >= size()) {
  211 + throw GException::out_of_range(G_AT, index, 0, size()-1);
  212 + }
  213 +
  214 + // Return reference
  215 + return *(m_pars[index]);
  216 +}
  217 +
  218 +
  219 +/***********************************************************************//**
  220 + * @brief Returns model parameter (const version)
  221 + *
  222 + * @param[in] index Parameter index [0,...,size()-1].
  223 + * @return Model parameter.
  224 + *
  225 + * @exception GException::out_of_range
  226 + * Parameter index is out of range.
  227 + *
  228 + * Returns model parameter with @p index range checking.
  229 + ***************************************************************************/
  230 +const GModelPar& GModelSpatial::at(const int& index) const
  231 +{
  232 + // Compile option: raise exception if index is out of range
  233 + if (index < 0 || index >= size()) {
  234 + throw GException::out_of_range(G_AT, index, 0, size()-1);
  235 + }
  236 +
  237 + // Return reference
  238 + return *(m_pars[index]);
  239 +}
  240 +
  241 +
  242 +/***********************************************************************//**
247 * @brief Autoscale parameters 243 * @brief Autoscale parameters
248 * 244 *
249 * Sets the scale factors for all parameters so that the values are unity. 245 * Sets the scale factors for all parameters so that the values are unity.
src/model/GModelSpectral.cpp
1 /*************************************************************************** 1 /***************************************************************************
2 * GModelSpectral.cpp - Abstract spectral model base class * 2 * GModelSpectral.cpp - Abstract spectral model base class *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2009-2013 by Juergen Knoedlseder * 4 + * copyright (C) 2009-2014 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -32,8 +32,8 @@ @@ -32,8 +32,8 @@
32 #include "GModelSpectral.hpp" 32 #include "GModelSpectral.hpp"
33 33
34 /* __ Method name definitions ____________________________________________ */ 34 /* __ Method name definitions ____________________________________________ */
35 -#define G_ACCESS1 "GModelSpectral::operator[](int&)"  
36 -#define G_ACCESS2 "GModelSpectral::operator[](std::string&)" 35 +#define G_ACCESS "GModelSpectral::operator[](std::string&)"
  36 +#define G_AT "GModelPar& GModelSpectral::at(int&)"
37 37
38 /* __ Macros _____________________________________________________________ */ 38 /* __ Macros _____________________________________________________________ */
39 39
@@ -102,8 +102,9 @@ GModelSpectral::~GModelSpectral(void) @@ -102,8 +102,9 @@ GModelSpectral::~GModelSpectral(void)
102 * @brief Assignment operator 102 * @brief Assignment operator
103 * 103 *
104 * @param[in] model Spectral model. 104 * @param[in] model Spectral model.
  105 + * @return Spectral model.
105 ***************************************************************************/ 106 ***************************************************************************/
106 -GModelSpectral& GModelSpectral::operator= (const GModelSpectral& model) 107 +GModelSpectral& GModelSpectral::operator=(const GModelSpectral& model)
107 { 108 {
108 // Execute only if object is not identical 109 // Execute only if object is not identical
109 if (this != &model) { 110 if (this != &model) {
@@ -125,48 +126,6 @@ GModelSpectral&amp; GModelSpectral::operator= (const GModelSpectral&amp; model) @@ -125,48 +126,6 @@ GModelSpectral&amp; GModelSpectral::operator= (const GModelSpectral&amp; model)
125 126
126 127
127 /***********************************************************************//** 128 /***********************************************************************//**
128 - * @brief Returns model parameter  
129 - *  
130 - * @param[in] index Parameter index [0,...,size()-1].  
131 - *  
132 - * @exception GException::out_of_range  
133 - * Parameter index is out of range.  
134 - ***************************************************************************/  
135 -GModelPar& GModelSpectral::operator[](const int& index)  
136 -{  
137 - // Compile option: raise exception if index is out of range  
138 - #if defined(G_RANGE_CHECK)  
139 - if (index < 0 || index >= size())  
140 - throw GException::out_of_range(G_ACCESS1, index, 0, size()-1);  
141 - #endif  
142 -  
143 - // Return reference  
144 - return *(m_pars[index]);  
145 -}  
146 -  
147 -  
148 -/***********************************************************************//**  
149 - * @brief Returns model parameter (const version)  
150 - *  
151 - * @param[in] index Parameter index [0,...,size()-1].  
152 - *  
153 - * @exception GException::out_of_range  
154 - * Parameter index is out of range.  
155 - ***************************************************************************/  
156 -const GModelPar& GModelSpectral::operator[](const int& index) const  
157 -{  
158 - // Compile option: raise exception if index is out of range  
159 - #if defined(G_RANGE_CHECK)  
160 - if (index < 0 || index >= size())  
161 - throw GException::out_of_range(G_ACCESS1, index, 0, size()-1);  
162 - #endif  
163 -  
164 - // Return reference  
165 - return *(m_pars[index]);  
166 -}  
167 -  
168 -  
169 -/***********************************************************************//**  
170 * @brief Returns reference to model parameter 129 * @brief Returns reference to model parameter
171 * 130 *
172 * @param[in] name Parameter name. 131 * @param[in] name Parameter name.
@@ -179,13 +138,15 @@ GModelPar&amp; GModelSpectral::operator[](const std::string&amp; name) @@ -179,13 +138,15 @@ GModelPar&amp; GModelSpectral::operator[](const std::string&amp; name)
179 // Get parameter index 138 // Get parameter index
180 int index = 0; 139 int index = 0;
181 for (; index < size(); ++index) { 140 for (; index < size(); ++index) {
182 - if (m_pars[index]->name() == name) 141 + if (m_pars[index]->name() == name) {
183 break; 142 break;
  143 + }
184 } 144 }
185 145
186 // Throw exception if parameter name was not found 146 // Throw exception if parameter name was not found
187 - if (index >= size())  
188 - throw GException::par_not_found(G_ACCESS2, name); 147 + if (index >= size()) {
  148 + throw GException::par_not_found(G_ACCESS, name);
  149 + }
189 150
190 // Return reference 151 // Return reference
191 return *(m_pars[index]); 152 return *(m_pars[index]);
@@ -205,13 +166,15 @@ const GModelPar&amp; GModelSpectral::operator[](const std::string&amp; name) const @@ -205,13 +166,15 @@ const GModelPar&amp; GModelSpectral::operator[](const std::string&amp; name) const
205 // Get parameter index 166 // Get parameter index
206 int index = 0; 167 int index = 0;
207 for (; index < size(); ++index) { 168 for (; index < size(); ++index) {
208 - if (m_pars[index]->name() == name) 169 + if (m_pars[index]->name() == name) {
209 break; 170 break;
  171 + }
210 } 172 }
211 173
212 // Throw exception if parameter name was not found 174 // Throw exception if parameter name was not found
213 - if (index >= size())  
214 - throw GException::par_not_found(G_ACCESS2, name); 175 + if (index >= size()) {
  176 + throw GException::par_not_found(G_ACCESS, name);
  177 + }
215 178
216 // Return reference 179 // Return reference
217 return *(m_pars[index]); 180 return *(m_pars[index]);
@@ -225,16 +188,48 @@ const GModelPar&amp; GModelSpectral::operator[](const std::string&amp; name) const @@ -225,16 +188,48 @@ const GModelPar&amp; GModelSpectral::operator[](const std::string&amp; name) const
225 ==========================================================================*/ 188 ==========================================================================*/
226 189
227 /***********************************************************************//** 190 /***********************************************************************//**
228 - * @brief Return number of parameters 191 + * @brief Returns model parameter
  192 + *
  193 + * @param[in] index Parameter index [0,...,size()-1].
  194 + * @return Model parameter.
  195 + *
  196 + * @exception GException::out_of_range
  197 + * Parameter index is out of range.
  198 + *
  199 + * Returns model parameter with @p index range checking.
  200 + ***************************************************************************/
  201 +GModelPar& GModelSpectral::at(const int& index)
  202 +{
  203 + // Compile option: raise exception if index is out of range
  204 + if (index < 0 || index >= size()) {
  205 + throw GException::out_of_range(G_AT, index, 0, size()-1);
  206 + }
  207 +
  208 + // Return reference
  209 + return *(m_pars[index]);
  210 +}
  211 +
  212 +
  213 +/***********************************************************************//**
  214 + * @brief Returns model parameter (const version)
  215 + *
  216 + * @param[in] index Parameter index [0,...,size()-1].
  217 + * @return Model parameter.
229 * 218 *
230 - * @return Number of parameters in spectral model component. 219 + * @exception GException::out_of_range
  220 + * Parameter index is out of range.
231 * 221 *
232 - * Returns the number of parameters in the spectral model component. 222 + * Returns model parameter with @p index range checking.
233 ***************************************************************************/ 223 ***************************************************************************/
234 -int GModelSpectral::size(void) const 224 +const GModelPar& GModelSpectral::at(const int& index) const
235 { 225 {
236 - // Return number of parameters  
237 - return (m_pars.size()); 226 + // Compile option: raise exception if index is out of range
  227 + if (index < 0 || index >= size()) {
  228 + throw GException::out_of_range(G_AT, index, 0, size()-1);
  229 + }
  230 +
  231 + // Return reference
  232 + return *(m_pars[index]);
238 } 233 }
239 234
240 235
src/model/GModelTemporal.cpp
1 /*************************************************************************** 1 /***************************************************************************
2 * GModelTemporal.cpp - Abstract temporal model base class * 2 * GModelTemporal.cpp - Abstract temporal model base class *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2009-2013 by Juergen Knoedlseder * 4 + * copyright (C) 2009-2014 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -32,8 +32,8 @@ @@ -32,8 +32,8 @@
32 #include "GModelTemporal.hpp" 32 #include "GModelTemporal.hpp"
33 33
34 /* __ Method name definitions ____________________________________________ */ 34 /* __ Method name definitions ____________________________________________ */
35 -#define G_ACCESS1 "GModelTemporal::operator[](int&)"  
36 -#define G_ACCESS2 "GModelTemporal::operator[](std::string&)" 35 +#define G_ACCESS "GModelTemporal::operator[](std::string&)"
  36 +#define G_AT "GModelPar& GModelTemporal::at(int&)"
37 37
38 /* __ Macros _____________________________________________________________ */ 38 /* __ Macros _____________________________________________________________ */
39 39
@@ -102,8 +102,9 @@ GModelTemporal::~GModelTemporal(void) @@ -102,8 +102,9 @@ GModelTemporal::~GModelTemporal(void)
102 * @brief Assignment operator 102 * @brief Assignment operator
103 * 103 *
104 * @param[in] model Temporal model. 104 * @param[in] model Temporal model.
  105 + * @return Temporal model.
105 ***************************************************************************/ 106 ***************************************************************************/
106 -GModelTemporal& GModelTemporal::operator= (const GModelTemporal& model) 107 +GModelTemporal& GModelTemporal::operator=(const GModelTemporal& model)
107 { 108 {
108 // Execute only if object is not identical 109 // Execute only if object is not identical
109 if (this != &model) { 110 if (this != &model) {
@@ -125,48 +126,6 @@ GModelTemporal&amp; GModelTemporal::operator= (const GModelTemporal&amp; model) @@ -125,48 +126,6 @@ GModelTemporal&amp; GModelTemporal::operator= (const GModelTemporal&amp; model)
125 126
126 127
127 /***********************************************************************//** 128 /***********************************************************************//**
128 - * @brief Returns model parameter  
129 - *  
130 - * @param[in] index Parameter index [0,...,size()-1].  
131 - *  
132 - * @exception GException::out_of_range  
133 - * Parameter index is out of range.  
134 - ***************************************************************************/  
135 -GModelPar& GModelTemporal::operator[](const int& index)  
136 -{  
137 - // Compile option: raise exception if index is out of range  
138 - #if defined(G_RANGE_CHECK)  
139 - if (index < 0 || index >= size())  
140 - throw GException::out_of_range(G_ACCESS1, index, 0, size()-1);  
141 - #endif  
142 -  
143 - // Return reference  
144 - return *(m_pars[index]);  
145 -}  
146 -  
147 -  
148 -/***********************************************************************//**  
149 - * @brief Returns model parameter (const version)  
150 - *  
151 - * @param[in] index Parameter index [0,...,size()-1].  
152 - *  
153 - * @exception GException::out_of_range  
154 - * Parameter index is out of range.  
155 - ***************************************************************************/  
156 -const GModelPar& GModelTemporal::operator[](const int& index) const  
157 -{  
158 - // Compile option: raise exception if index is out of range  
159 - #if defined(G_RANGE_CHECK)  
160 - if (index < 0 || index >= size())  
161 - throw GException::out_of_range(G_ACCESS1, index, 0, size()-1);  
162 - #endif  
163 -  
164 - // Return reference  
165 - return *(m_pars[index]);  
166 -}  
167 -  
168 -  
169 -/***********************************************************************//**  
170 * @brief Returns reference to model parameter 129 * @brief Returns reference to model parameter
171 * 130 *
172 * @param[in] name Parameter name. 131 * @param[in] name Parameter name.
@@ -185,7 +144,7 @@ GModelPar&amp; GModelTemporal::operator[](const std::string&amp; name) @@ -185,7 +144,7 @@ GModelPar&amp; GModelTemporal::operator[](const std::string&amp; name)
185 144
186 // Throw exception if parameter name was not found 145 // Throw exception if parameter name was not found
187 if (index >= size()) 146 if (index >= size())
188 - throw GException::par_not_found(G_ACCESS2, name); 147 + throw GException::par_not_found(G_ACCESS, name);
189 148
190 // Return reference 149 // Return reference
191 return *(m_pars[index]); 150 return *(m_pars[index]);
@@ -211,7 +170,7 @@ const GModelPar&amp; GModelTemporal::operator[](const std::string&amp; name) const @@ -211,7 +170,7 @@ const GModelPar&amp; GModelTemporal::operator[](const std::string&amp; name) const
211 170
212 // Throw exception if parameter name was not found 171 // Throw exception if parameter name was not found
213 if (index >= size()) 172 if (index >= size())
214 - throw GException::par_not_found(G_ACCESS2, name); 173 + throw GException::par_not_found(G_ACCESS, name);
215 174
216 // Return reference 175 // Return reference
217 return *(m_pars[index]); 176 return *(m_pars[index]);
@@ -225,16 +184,48 @@ const GModelPar&amp; GModelTemporal::operator[](const std::string&amp; name) const @@ -225,16 +184,48 @@ const GModelPar&amp; GModelTemporal::operator[](const std::string&amp; name) const
225 ==========================================================================*/ 184 ==========================================================================*/
226 185
227 /***********************************************************************//** 186 /***********************************************************************//**
228 - * @brief Return number of parameters 187 + * @brief Returns model parameter
  188 + *
  189 + * @param[in] index Parameter index [0,...,size()-1].
  190 + * @return Model parameter.
  191 + *
  192 + * @exception GException::out_of_range
  193 + * Parameter index is out of range.
  194 + *
  195 + * Returns model parameter with @p index range checking.
  196 + ***************************************************************************/
  197 +GModelPar& GModelTemporal::at(const int& index)
  198 +{
  199 + // Compile option: raise exception if index is out of range
  200 + if (index < 0 || index >= size()) {
  201 + throw GException::out_of_range(G_AT, index, 0, size()-1);
  202 + }
  203 +
  204 + // Return reference
  205 + return *(m_pars[index]);
  206 +}
  207 +
  208 +
  209 +/***********************************************************************//**
  210 + * @brief Returns model parameter (const version)
229 * 211 *
230 - * @return Number of parameters in temporal model component. 212 + * @param[in] index Parameter index [0,...,size()-1].
  213 + * @return Model parameter.
231 * 214 *
232 - * Returns the number of parameters in the temporal model component. 215 + * @exception GException::out_of_range
  216 + * Parameter index is out of range.
  217 + *
  218 + * Returns model parameter with @p index range checking.
233 ***************************************************************************/ 219 ***************************************************************************/
234 -int GModelTemporal::size(void) const 220 +const GModelPar& GModelTemporal::at(const int& index) const
235 { 221 {
236 - // Return number of parameters  
237 - return (m_pars.size()); 222 + // Compile option: raise exception if index is out of range
  223 + if (index < 0 || index >= size()) {
  224 + throw GException::out_of_range(G_AT, index, 0, size()-1);
  225 + }
  226 +
  227 + // Return reference
  228 + return *(m_pars[index]);
238 } 229 }
239 230
240 231