source: src/Parameters/Specifics/Parameter_vector.cpp@ ef8667

ForceAnnealing_oldresults IndependentFragmentGrids_IntegrationTest
Last change on this file since ef8667 was 2eded3e, checked in by Frederik Heber <frederik.heber@…>, 8 years ago

Added specific Value and Parameter implemenations for Vector.

  • for the CommandLineParser the values are get parsed immediately (prior to executing any Action). Hence, names of geometry objects that first need to be created by an action cannot yet be present in the registry and thus the Action will fail.
  • we need to postpone the replacement of the geometry name by its stored vector components until the Parameter<>::get() call. This is possible as the value is validated only on get(), not on set(), i.e. giving illegal values is ok, only the Action will fail.
  • therefore, we override the specialize the template Value for Vector to allow storing of a string instead of a Vector and to allow putting the actual parsing of the string in front.
  • the Parameter overriding becomes necessary in order to override clone() and copy cstor(), there using string setters.
  • ContinuousValueTest now needs lib..Parameters, lib..Geometry.
  • static functions parseAsVector and setFromVector for convenience, e.g. QtUI needs to convert from string and to Vector.
  • TESTS: Marked dryrun store-session again as XFAIL, removed XFAIL from load- session python.
  • Property mode set to 100644
File size: 7.7 KB
Line 
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
42Parameter<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 */
52Parameter<Vector>::Parameter() :
53 ParameterInterface("__no_name__"),
54 value()
55{};
56
57/** Constructor for class Parameter.
58 *
59 */
60Parameter<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 */
70Parameter<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 */
82Parameter<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 */
93Parameter<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 */
105Parameter<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 */
116Parameter<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 */
128Parameter<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 */
139Parameter<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 */
149Parameter<Vector>::~Parameter()
150{};
151
152/** Catch call to value.isValidAsString() to add exception information.
153 *
154 * @param _value value to set to
155 */
156bool 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 */
171const 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 */
185const 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 */
199bool 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 */
214const 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 */
228const 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 */
242void 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 */
256void 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 */
271bool 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 */
289ParameterInterface* 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
Note: See TracBrowser for help on using the repository browser.