00001 /*************************************************************************** 00002 * GModelSpectral.cpp - Abstract spectral model base class * 00003 * ----------------------------------------------------------------------- * 00004 * copyright (C) 2009-2016 by Juergen Knoedlseder * 00005 * ----------------------------------------------------------------------- * 00006 * * 00007 * This program is free software: you can redistribute it and/or modify * 00008 * it under the terms of the GNU General Public License as published by * 00009 * the Free Software Foundation, either version 3 of the License, or * 00010 * (at your option) any later version. * 00011 * * 00012 * This program is distributed in the hope that it will be useful, * 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00015 * GNU General Public License for more details. * 00016 * * 00017 * You should have received a copy of the GNU General Public License * 00018 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 00019 * * 00020 ***************************************************************************/ 00021 /** 00022 * @file GModelSpectral.cpp 00023 * @brief Abstract spectral model base class implementation 00024 * @author Juergen Knoedlseder 00025 */ 00026 00027 /* __ Includes ___________________________________________________________ */ 00028 #ifdef HAVE_CONFIG_H 00029 #include <config.h> 00030 #endif 00031 #include "GException.hpp" 00032 #include "GModelSpectral.hpp" 00033 #include "GModelPar.hpp" 00034 00035 /* __ Method name definitions ____________________________________________ */ 00036 #define G_ACCESS "GModelSpectral::operator[](std::string&)" 00037 #define G_AT "GModelPar& GModelSpectral::at(int&)" 00038 00039 /* __ Macros _____________________________________________________________ */ 00040 00041 /* __ Coding definitions _________________________________________________ */ 00042 00043 /* __ Debug definitions __________________________________________________ */ 00044 00045 00046 /*========================================================================== 00047 = = 00048 = Constructors/destructors = 00049 = = 00050 ==========================================================================*/ 00051 00052 /***********************************************************************//** 00053 * @brief Void constructor 00054 ***************************************************************************/ 00055 GModelSpectral::GModelSpectral(void) 00056 { 00057 // Initialise members 00058 init_members(); 00059 00060 // Return 00061 return; 00062 } 00063 00064 00065 /***********************************************************************//** 00066 * @brief Copy constructor 00067 * 00068 * @param[in] model Spectral model. 00069 ***************************************************************************/ 00070 GModelSpectral::GModelSpectral(const GModelSpectral& model) 00071 { 00072 // Initialise members 00073 init_members(); 00074 00075 // Copy members 00076 copy_members(model); 00077 00078 // Return 00079 return; 00080 } 00081 00082 00083 /***********************************************************************//** 00084 * @brief Destructor 00085 ***************************************************************************/ 00086 GModelSpectral::~GModelSpectral(void) 00087 { 00088 // Free members 00089 free_members(); 00090 00091 // Return 00092 return; 00093 } 00094 00095 00096 /*========================================================================== 00097 = = 00098 = Operators = 00099 = = 00100 ==========================================================================*/ 00101 00102 /***********************************************************************//** 00103 * @brief Assignment operator 00104 * 00105 * @param[in] model Spectral model. 00106 * @return Spectral model. 00107 ***************************************************************************/ 00108 GModelSpectral& GModelSpectral::operator=(const GModelSpectral& model) 00109 { 00110 // Execute only if object is not identical 00111 if (this != &model) { 00112 00113 // Free members 00114 free_members(); 00115 00116 // Initialise private members for clean destruction 00117 init_members(); 00118 00119 // Copy members 00120 copy_members(model); 00121 00122 } // endif: object was not identical 00123 00124 // Return 00125 return *this; 00126 } 00127 00128 00129 /***********************************************************************//** 00130 * @brief Returns reference to model parameter 00131 * 00132 * @param[in] name Parameter name. 00133 * 00134 * @exception GException::par_not_found 00135 * Parameter with specified name not found in container. 00136 ***************************************************************************/ 00137 GModelPar& GModelSpectral::operator[](const std::string& name) 00138 { 00139 // Get parameter index 00140 int index = 0; 00141 for (; index < size(); ++index) { 00142 if (m_pars[index]->name() == name) { 00143 break; 00144 } 00145 } 00146 00147 // Throw exception if parameter name was not found 00148 if (index >= size()) { 00149 throw GException::par_not_found(G_ACCESS, name); 00150 } 00151 00152 // Return reference 00153 return *(m_pars[index]); 00154 } 00155 00156 00157 /***********************************************************************//** 00158 * @brief Returns reference to model parameter (const version) 00159 * 00160 * @param[in] name Parameter name. 00161 * 00162 * @exception GException::par_not_found 00163 * Parameter with specified name not found in container. 00164 ***************************************************************************/ 00165 const GModelPar& GModelSpectral::operator[](const std::string& name) const 00166 { 00167 // Get parameter index 00168 int index = 0; 00169 for (; index < size(); ++index) { 00170 if (m_pars[index]->name() == name) { 00171 break; 00172 } 00173 } 00174 00175 // Throw exception if parameter name was not found 00176 if (index >= size()) { 00177 throw GException::par_not_found(G_ACCESS, name); 00178 } 00179 00180 // Return reference 00181 return *(m_pars[index]); 00182 } 00183 00184 00185 /*========================================================================== 00186 = = 00187 = Public methods = 00188 = = 00189 ==========================================================================*/ 00190 00191 /***********************************************************************//** 00192 * @brief Returns model parameter 00193 * 00194 * @param[in] index Parameter index [0,...,size()-1]. 00195 * @return Model parameter. 00196 * 00197 * @exception GException::out_of_range 00198 * Parameter index is out of range. 00199 * 00200 * Returns model parameter with @p index range checking. 00201 ***************************************************************************/ 00202 GModelPar& GModelSpectral::at(const int& index) 00203 { 00204 // Compile option: raise exception if index is out of range 00205 if (index < 0 || index >= size()) { 00206 throw GException::out_of_range(G_AT, index, 0, size()-1); 00207 } 00208 00209 // Return reference 00210 return *(m_pars[index]); 00211 } 00212 00213 00214 /***********************************************************************//** 00215 * @brief Returns model parameter (const version) 00216 * 00217 * @param[in] index Parameter index [0,...,size()-1]. 00218 * @return Model parameter. 00219 * 00220 * @exception GException::out_of_range 00221 * Parameter index is out of range. 00222 * 00223 * Returns model parameter with @p index range checking. 00224 ***************************************************************************/ 00225 const GModelPar& GModelSpectral::at(const int& index) const 00226 { 00227 // Compile option: raise exception if index is out of range 00228 if (index < 0 || index >= size()) { 00229 throw GException::out_of_range(G_AT, index, 0, size()-1); 00230 } 00231 00232 // Return reference 00233 return *(m_pars[index]); 00234 } 00235 00236 00237 /***********************************************************************//** 00238 * @brief Checks if parameter name exists 00239 * 00240 * @param[in] name Parameter name. 00241 * @return True if parameter with specified @p name exists. 00242 * 00243 * Searches all parameter names for a match with the specified @p name. If 00244 * the specified name has been found, true is returned. 00245 ***************************************************************************/ 00246 bool GModelSpectral::has_par(const std::string& name) const 00247 { 00248 // Default found flag to false 00249 bool found = false; 00250 00251 // Search for parameter name 00252 for (int i = 0; i < size(); ++i) { 00253 if (m_pars[i]->name() == name) { 00254 found = true; 00255 break; 00256 } 00257 } 00258 00259 // Return 00260 return found; 00261 } 00262 00263 00264 /***********************************************************************//** 00265 * @brief Autoscale parameters 00266 * 00267 * Sets the scale factors for all parameters so that the values are unity. 00268 ***************************************************************************/ 00269 void GModelSpectral::autoscale(void) 00270 { 00271 // Loop over all parameters 00272 for (int i = 0; i < m_pars.size(); ++i) { 00273 if (m_pars[i] != NULL) { 00274 m_pars[i]->autoscale(); 00275 } 00276 } 00277 00278 // Return 00279 return; 00280 } 00281 00282 00283 /*========================================================================== 00284 = = 00285 = Private methods = 00286 = = 00287 ==========================================================================*/ 00288 00289 /***********************************************************************//** 00290 * @brief Initialise class members 00291 ***************************************************************************/ 00292 void GModelSpectral::init_members(void) 00293 { 00294 // Initialise members 00295 m_pars.clear(); 00296 00297 // Return 00298 return; 00299 } 00300 00301 00302 /***********************************************************************//** 00303 * @brief Copy class members 00304 * 00305 * @param[in] model Spectral model. 00306 ***************************************************************************/ 00307 void GModelSpectral::copy_members(const GModelSpectral& model) 00308 { 00309 // Copy members 00310 m_pars = model.m_pars; 00311 00312 // Return 00313 return; 00314 } 00315 00316 00317 /***********************************************************************//** 00318 * @brief Delete class members 00319 ***************************************************************************/ 00320 void GModelSpectral::free_members(void) 00321 { 00322 // Return 00323 return; 00324 }