| [2eded3e] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
 | 4 |  * Copyright (C)  2017 Frederik Heber. All rights reserved.
 | 
|---|
 | 5 |  *
 | 
|---|
 | 6 |  *
 | 
|---|
 | 7 |  *   This file is part of MoleCuilder.
 | 
|---|
 | 8 |  *
 | 
|---|
 | 9 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
 | 10 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
 | 11 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
 | 12 |  *    (at your option) any later version.
 | 
|---|
 | 13 |  *
 | 
|---|
 | 14 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
 | 15 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
 | 16 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
 | 17 |  *    GNU General Public License for more details.
 | 
|---|
 | 18 |  *
 | 
|---|
 | 19 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
 | 20 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
 | 
|---|
 | 21 |  */
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 | /*
 | 
|---|
 | 24 |  * Parameter_vector.cpp
 | 
|---|
 | 25 |  *
 | 
|---|
 | 26 |  *  Created on: Mar 31, 2017
 | 
|---|
 | 27 |  *      Author: heber
 | 
|---|
 | 28 |  */
 | 
|---|
 | 29 | 
 | 
|---|
 | 30 | 
 | 
|---|
 | 31 | // include config.h
 | 
|---|
 | 32 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 33 | #include <config.h>
 | 
|---|
 | 34 | #endif
 | 
|---|
 | 35 | 
 | 
|---|
 | 36 | //#include "CodePatterns/MemDebug.hpp"
 | 
|---|
 | 37 | 
 | 
|---|
 | 38 | #include "Parameters/Specifics/Parameter_vector.hpp"
 | 
|---|
 | 39 | 
 | 
|---|
 | 40 | #include "Parameters/ParameterExceptions.hpp"
 | 
|---|
 | 41 | 
 | 
|---|
 | 42 | Parameter<Vector>::Parameter(const Parameter<Vector> &instance) :
 | 
|---|
 | 43 |   ParameterInterface(instance.getName()),
 | 
|---|
 | 44 |   value(instance.value.getValidator())
 | 
|---|
 | 45 | {
 | 
|---|
 | 46 |   value.setAsString(instance.value.getAsStringUnvalidated());
 | 
|---|
 | 47 | }
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 | /** Constructor for class Parameter.
 | 
|---|
 | 50 |  *
 | 
|---|
 | 51 |  */
 | 
|---|
 | 52 | Parameter<Vector>::Parameter() :
 | 
|---|
 | 53 |   ParameterInterface("__no_name__"),
 | 
|---|
 | 54 |   value()
 | 
|---|
 | 55 | {};
 | 
|---|
 | 56 | 
 | 
|---|
 | 57 | /** Constructor for class Parameter.
 | 
|---|
 | 58 |  *
 | 
|---|
 | 59 |  */
 | 
|---|
 | 60 | Parameter<Vector>::Parameter(const std::string &_name) :
 | 
|---|
 | 61 |   ParameterInterface(_name),
 | 
|---|
 | 62 |   value()
 | 
|---|
 | 63 | {};
 | 
|---|
 | 64 | 
 | 
|---|
 | 65 | /** Constructor for class Parameter.
 | 
|---|
 | 66 |  *
 | 
|---|
 | 67 |  * @param _name name of this parameter
 | 
|---|
 | 68 |  * @param _value initial value to set
 | 
|---|
 | 69 |  */
 | 
|---|
 | 70 | Parameter<Vector>::Parameter(const std::string &_name, const Vector &_value) :
 | 
|---|
 | 71 |   ParameterInterface(_name),
 | 
|---|
 | 72 |   value()
 | 
|---|
 | 73 | {
 | 
|---|
 | 74 |   value.set(_value);
 | 
|---|
 | 75 | };
 | 
|---|
 | 76 | 
 | 
|---|
 | 77 | /** Constructor for class Parameter.
 | 
|---|
 | 78 |  *
 | 
|---|
 | 79 |  * @param _name name of this parameter
 | 
|---|
 | 80 |  * @param _ValidRange valid range for this ContinuousValue
 | 
|---|
 | 81 |  */
 | 
|---|
 | 82 | Parameter<Vector>::Parameter(const std::string &_name, const Validator<Vector> &_Validator) :
 | 
|---|
 | 83 |   ParameterInterface(_name),
 | 
|---|
 | 84 |   value(_Validator)
 | 
|---|
 | 85 | {};
 | 
|---|
 | 86 | 
 | 
|---|
 | 87 | /** Constructor for class Parameter.
 | 
|---|
 | 88 |  *
 | 
|---|
 | 89 |  * @param _name name of this parameter
 | 
|---|
 | 90 |  * @param _ValidRange valid range for this ContinuousValue
 | 
|---|
 | 91 |  * @param _value initial value to set
 | 
|---|
 | 92 |  */
 | 
|---|
 | 93 | Parameter<Vector>::Parameter(const std::string &_name, const Validator<Vector> &_Validator, const Vector &_value) :
 | 
|---|
 | 94 |   ParameterInterface(_name),
 | 
|---|
 | 95 |   value(_Validator)
 | 
|---|
 | 96 | {
 | 
|---|
 | 97 |   value.set(_value);
 | 
|---|
 | 98 | };
 | 
|---|
 | 99 | 
 | 
|---|
 | 100 | /** Constructor for class Parameter.
 | 
|---|
 | 101 |  *
 | 
|---|
 | 102 |  * @param _name name of this parameter
 | 
|---|
 | 103 |  * @param _ValidRange valid range for this ContinuousValue
 | 
|---|
 | 104 |  */
 | 
|---|
 | 105 | Parameter<Vector>::Parameter(const std::string &_name, const std::vector<Vector> &_ValidValues) :
 | 
|---|
 | 106 |   ParameterInterface(_name),
 | 
|---|
 | 107 |   value(_ValidValues)
 | 
|---|
 | 108 | {};
 | 
|---|
 | 109 | 
 | 
|---|
 | 110 | /** Constructor for class Parameter.
 | 
|---|
 | 111 |  *
 | 
|---|
 | 112 |  * @param _name name of this parameter
 | 
|---|
 | 113 |  * @param _ValidRange valid range for this ContinuousValue
 | 
|---|
 | 114 |  * @param _value initial value to set
 | 
|---|
 | 115 |  */
 | 
|---|
 | 116 | Parameter<Vector>::Parameter(const std::string &_name, const std::vector<Vector> &_ValidValues, const Vector &_value) :
 | 
|---|
 | 117 |   ParameterInterface(_name),
 | 
|---|
 | 118 |   value(_ValidValues)
 | 
|---|
 | 119 | {
 | 
|---|
 | 120 |   value.set(_value);
 | 
|---|
 | 121 | };
 | 
|---|
 | 122 | 
 | 
|---|
 | 123 | /** Constructor for class Parameter.
 | 
|---|
 | 124 |  *
 | 
|---|
 | 125 |  * @param _name name of this parameter
 | 
|---|
 | 126 |  * @param _ValidRange valid range for this ContinuousValue
 | 
|---|
 | 127 |  */
 | 
|---|
 | 128 | Parameter<Vector>::Parameter(const std::string &_name, const range<Vector> &_ValidRange) :
 | 
|---|
 | 129 |   ParameterInterface(_name),
 | 
|---|
 | 130 |   value(_ValidRange)
 | 
|---|
 | 131 | {};
 | 
|---|
 | 132 | 
 | 
|---|
 | 133 | /** Constructor for class Parameter.
 | 
|---|
 | 134 |  *
 | 
|---|
 | 135 |  * @param _name name of this parameter
 | 
|---|
 | 136 |  * @param _ValidRange valid range for this ContinuousValue
 | 
|---|
 | 137 |  * @param _value initial value to set
 | 
|---|
 | 138 |  */
 | 
|---|
 | 139 | Parameter<Vector>::Parameter(const std::string &_name, const range<Vector> &_ValidRange, const Vector &_value) :
 | 
|---|
 | 140 |   ParameterInterface(_name),
 | 
|---|
 | 141 |   value(_ValidRange)
 | 
|---|
 | 142 | {
 | 
|---|
 | 143 |   value.set(_value);
 | 
|---|
 | 144 | };
 | 
|---|
 | 145 | 
 | 
|---|
 | 146 | /** Destructor for class Parameter.
 | 
|---|
 | 147 |  *
 | 
|---|
 | 148 |  */
 | 
|---|
 | 149 | Parameter<Vector>::~Parameter()
 | 
|---|
 | 150 | {};
 | 
|---|
 | 151 | 
 | 
|---|
 | 152 | /** Catch call to value.isValidAsString() to add exception information.
 | 
|---|
 | 153 |  *
 | 
|---|
 | 154 |  * @param _value value to set to
 | 
|---|
 | 155 |  */
 | 
|---|
 | 156 | bool Parameter<Vector>::isValidAsString(const std::string &_value) const throw(ParameterValidatorException)
 | 
|---|
 | 157 | {
 | 
|---|
 | 158 |   try {
 | 
|---|
 | 159 |     return value.isValidAsString(_value);
 | 
|---|
 | 160 |   } catch(ParameterException &e) {
 | 
|---|
 | 161 |     e << ParameterName(ParameterInterface::getName());
 | 
|---|
 | 162 |     throw;
 | 
|---|
 | 163 |   }
 | 
|---|
 | 164 | }
 | 
|---|
 | 165 | 
 | 
|---|
 | 166 | 
 | 
|---|
 | 167 | /** Catch call to value.getAsString() to add exception information.
 | 
|---|
 | 168 |  *
 | 
|---|
 | 169 |  * @return parameter value as string
 | 
|---|
 | 170 |  */
 | 
|---|
 | 171 | const std::string Parameter<Vector>::getAsString() const throw(ParameterValueException)
 | 
|---|
 | 172 | {
 | 
|---|
 | 173 |   try {
 | 
|---|
 | 174 |     return value.getAsString();
 | 
|---|
 | 175 |   } catch(ParameterException &e) {
 | 
|---|
 | 176 |     e << ParameterName(ParameterInterface::getName());
 | 
|---|
 | 177 |     throw;
 | 
|---|
 | 178 |   }
 | 
|---|
 | 179 | }
 | 
|---|
 | 180 | 
 | 
|---|
 | 181 | /** Catch call to value.getAsStringUnvalidated() to add exception information.
 | 
|---|
 | 182 |  *
 | 
|---|
 | 183 |  * @return parameter value as string
 | 
|---|
 | 184 |  */
 | 
|---|
 | 185 | const std::string Parameter<Vector>::getAsStringUnvalidated() const throw(ParameterValueException)
 | 
|---|
 | 186 | {
 | 
|---|
 | 187 |   try {
 | 
|---|
 | 188 |     return value.getAsStringUnvalidated();
 | 
|---|
 | 189 |   } catch(ParameterException &e) {
 | 
|---|
 | 190 |     e << ParameterName(ParameterInterface::getName());
 | 
|---|
 | 191 |     throw;
 | 
|---|
 | 192 |   }
 | 
|---|
 | 193 | }
 | 
|---|
 | 194 | 
 | 
|---|
 | 195 | /** Catch call to value.isValid() to add exception information.
 | 
|---|
 | 196 |  *
 | 
|---|
 | 197 |  * @return parameter value as string
 | 
|---|
 | 198 |  */
 | 
|---|
 | 199 | bool Parameter<Vector>::isValid(const Vector &_value) const throw(ParameterValidatorException)
 | 
|---|
 | 200 | {
 | 
|---|
 | 201 |   try {
 | 
|---|
 | 202 |     return value.isValid(_value);
 | 
|---|
 | 203 |   } catch(ParameterException &e) {
 | 
|---|
 | 204 |     e << ParameterName(ParameterInterface::getName());
 | 
|---|
 | 205 |     throw;
 | 
|---|
 | 206 |   }
 | 
|---|
 | 207 | }
 | 
|---|
 | 208 | 
 | 
|---|
 | 209 | 
 | 
|---|
 | 210 | /** Catch call to value.getUnvalidated() to add exception information.
 | 
|---|
 | 211 |  *
 | 
|---|
 | 212 |  * @return parameter value as string
 | 
|---|
 | 213 |  */
 | 
|---|
 | 214 | const Vector & Parameter<Vector>::getUnvalidated() const throw(ParameterValueException)
 | 
|---|
 | 215 | {
 | 
|---|
 | 216 |   try {
 | 
|---|
 | 217 |     return value.getUnvalidated();
 | 
|---|
 | 218 |   } catch(ParameterException &e) {
 | 
|---|
 | 219 |     e << ParameterName(ParameterInterface::getName());
 | 
|---|
 | 220 |     throw;
 | 
|---|
 | 221 |   }
 | 
|---|
 | 222 | }
 | 
|---|
 | 223 | 
 | 
|---|
 | 224 | /** Catch call to value.get() to add exception information.
 | 
|---|
 | 225 |  *
 | 
|---|
 | 226 |  * @return parameter value as string
 | 
|---|
 | 227 |  */
 | 
|---|
 | 228 | const Vector & Parameter<Vector>::get() const throw(ParameterValueException)
 | 
|---|
 | 229 | {
 | 
|---|
 | 230 |   try {
 | 
|---|
 | 231 |     return value.get();
 | 
|---|
 | 232 |   } catch(ParameterException &e) {
 | 
|---|
 | 233 |     e << ParameterName(ParameterInterface::getName());
 | 
|---|
 | 234 |     throw;
 | 
|---|
 | 235 |   }
 | 
|---|
 | 236 | }
 | 
|---|
 | 237 | 
 | 
|---|
 | 238 | /** Catch call to value.set() to add exception information.
 | 
|---|
 | 239 |  *
 | 
|---|
 | 240 |  * @param _value value to set to
 | 
|---|
 | 241 |  */
 | 
|---|
 | 242 | void Parameter<Vector>::set(const Vector & _value) throw(ParameterValueException)
 | 
|---|
 | 243 | {
 | 
|---|
 | 244 |   try {
 | 
|---|
 | 245 |     value.set(_value);
 | 
|---|
 | 246 |   } catch(ParameterException &e) {
 | 
|---|
 | 247 |     e << ParameterName(ParameterInterface::getName());
 | 
|---|
 | 248 |     throw;
 | 
|---|
 | 249 |   }
 | 
|---|
 | 250 | }
 | 
|---|
 | 251 | 
 | 
|---|
 | 252 | /** Catch call to value.set() to add exception information.
 | 
|---|
 | 253 |  *
 | 
|---|
 | 254 |  * @param _value value to set to
 | 
|---|
 | 255 |  */
 | 
|---|
 | 256 | void Parameter<Vector>::setAsString(const std::string &_value) throw(ParameterValueException)
 | 
|---|
 | 257 | {
 | 
|---|
 | 258 |   try {
 | 
|---|
 | 259 |     value.setAsString(_value);
 | 
|---|
 | 260 |   } catch(ParameterException &e) {
 | 
|---|
 | 261 |     e << ParameterName(ParameterInterface::getName());
 | 
|---|
 | 262 |     throw;
 | 
|---|
 | 263 |   }
 | 
|---|
 | 264 | }
 | 
|---|
 | 265 | 
 | 
|---|
 | 266 | /** Compares this continuous value against another \a _instance.
 | 
|---|
 | 267 |  *
 | 
|---|
 | 268 |  * @param _instance other value to compare to
 | 
|---|
 | 269 |  * @return true - if contained ContinuousValue and name are the same, false - else
 | 
|---|
 | 270 |  */
 | 
|---|
 | 271 | bool Parameter<Vector>::operator==(const Parameter<Vector> &_instance) const throw(ParameterException)
 | 
|---|
 | 272 | {
 | 
|---|
 | 273 |   bool status = true;
 | 
|---|
 | 274 |   try {
 | 
|---|
 | 275 |     status = status &&
 | 
|---|
 | 276 |         (getUnvalidated() == _instance.getUnvalidated());
 | 
|---|
 | 277 |     status = status && (ParameterInterface::getName() == _instance.ParameterInterface::getName());
 | 
|---|
 | 278 |   } catch(ParameterException &e) {
 | 
|---|
 | 279 |     e << ParameterName(ParameterInterface::getName());
 | 
|---|
 | 280 |     throw;
 | 
|---|
 | 281 |   }
 | 
|---|
 | 282 |   return status;
 | 
|---|
 | 283 | }
 | 
|---|
 | 284 | 
 | 
|---|
 | 285 | /** Creates a clone of this Parameter instance.
 | 
|---|
 | 286 |  *
 | 
|---|
 | 287 |  * @return cloned instance
 | 
|---|
 | 288 |  */
 | 
|---|
 | 289 | ParameterInterface* Parameter<Vector>::clone() const
 | 
|---|
 | 290 | {
 | 
|---|
 | 291 |   Parameter<Vector> *instance = new Parameter<Vector>(ParameterInterface::getName(), value.getValidator());
 | 
|---|
 | 292 |   // do not use get, we do not check for validity here
 | 
|---|
 | 293 |   if (value.isSet())
 | 
|---|
 | 294 |     instance->setAsString(value.getAsStringUnvalidated());
 | 
|---|
 | 295 |   return instance;
 | 
|---|
 | 296 | }
 | 
|---|
 | 297 | 
 | 
|---|