runtimeparametersetters.cpp
1 /***************************************************************************
2  * Copyright (C) 2008-2012 by Tomassino Ferrauto *
3  * t_ferrauto@yahoo.it *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
21 #include "runtimeparametersetters.h"
22 #include "configurationexceptions.h"
23 #include "factory.h"
24 #include "configurationhelper.h"
25 
26 namespace farsa {
27 
28 QString RuntimeParameterSetter::set( ParameterSettable*, QString newvalue ) {
29  QString type = ConfigurationHelper::getString( Factory::getTypeDescriptions(), descrPath+"/type", "missing type declaration" );
30  throw TypeMismatchOnSettingRuntimeModifiableParameter( name.toLatin1().data(), type.toLatin1().data(), "QString" );
31  return newvalue;
32 }
33 
35  QString type = ConfigurationHelper::getString( Factory::getTypeDescriptions(), descrPath+"/type", "missing type declaration" );
36  throw TypeMismatchOnSettingRuntimeModifiableParameter( name.toLatin1().data(), type.toLatin1().data(), "Int" );
37  return newvalue;
38 }
39 
40 unsigned int RuntimeParameterSetter::set( ParameterSettable*, unsigned int newvalue ) {
41  QString type = ConfigurationHelper::getString( Factory::getTypeDescriptions(), descrPath+"/type", "missing type declaration" );
42  throw TypeMismatchOnSettingRuntimeModifiableParameter( name.toLatin1().data(), type.toLatin1().data(), "Unsigned Int" );
43  return newvalue;
44 }
45 
46 double RuntimeParameterSetter::set( ParameterSettable*, double newvalue ) {
47  QString type = ConfigurationHelper::getString( Factory::getTypeDescriptions(), descrPath+"/type", "missing type declaration" );
48  throw TypeMismatchOnSettingRuntimeModifiableParameter( name.toLatin1().data(), type.toLatin1().data(), "Double" );
49  return newvalue;
50 }
51 
53  QString type = ConfigurationHelper::getString( Factory::getTypeDescriptions(), descrPath+"/type", "missing type declaration" );
54  throw TypeMismatchOnSettingRuntimeModifiableParameter( name.toLatin1().data(), type.toLatin1().data(), "Float" );
55  return newvalue;
56 }
57 
59  QString type = ConfigurationHelper::getString( Factory::getTypeDescriptions(), descrPath+"/type", "missing type declaration" );
60  throw TypeMismatchOnSettingRuntimeModifiableParameter( name.toLatin1().data(), type.toLatin1().data(), "Bool" );
61  return newvalue;
62 }
63 
65  QString type = ConfigurationHelper::getString( Factory::getTypeDescriptions(), descrPath+"/type", "missing type declaration" );
66  throw TypeMismatchOnSettingRuntimeModifiableParameter( name.toLatin1().data(), type.toLatin1().data(), "QString" );
67 }
68 
70  QString type = ConfigurationHelper::getString( Factory::getTypeDescriptions(), descrPath+"/type", "missing type declaration" );
71  throw TypeMismatchOnSettingRuntimeModifiableParameter( name.toLatin1().data(), type.toLatin1().data(), "int" );
72 }
73 
75  QString type = ConfigurationHelper::getString( Factory::getTypeDescriptions(), descrPath+"/type", "missing type declaration" );
76  throw TypeMismatchOnSettingRuntimeModifiableParameter( name.toLatin1().data(), type.toLatin1().data(), "unsigned int" );
77 }
78 
80  QString type = ConfigurationHelper::getString( Factory::getTypeDescriptions(), descrPath+"/type", "missing type declaration" );
81  throw TypeMismatchOnSettingRuntimeModifiableParameter( name.toLatin1().data(), type.toLatin1().data(), "double" );
82 }
83 
85  QString type = ConfigurationHelper::getString( Factory::getTypeDescriptions(), descrPath+"/type", "missing type declaration" );
86  throw TypeMismatchOnSettingRuntimeModifiableParameter( name.toLatin1().data(), type.toLatin1().data(), "float" );
87 }
88 
90  QString type = ConfigurationHelper::getString( Factory::getTypeDescriptions(), descrPath+"/type", "missing type declaration" );
91  throw TypeMismatchOnSettingRuntimeModifiableParameter( name.toLatin1().data(), type.toLatin1().data(), "bool" );
92 }
93 
94 } // end namespace farsa
95 
static ConfigurationParameters & getTypeDescriptions()
Returns the only instance of the typeDescriptions object.
Definition: factory.cpp:34
QString name
the name of the runtime modifiable parameter
static QString getString(ConfigurationParameters &params, QString paramPath, QString def=QString())
Return the value of parameter as QString, if the parameter has not been setted, it will return the de...
virtual void get(ParameterSettable *object, QString &ret)
Return the value of the object's parameter supposing that the parameter's type is QString...
The base for classes that can be configured/saved using a ConfigurationParameters object...
QString descrPath
the full path to the description of this parameter
The exception thrown when the type mismatch on the requested runtime modification of a parameter...
virtual QString set(ParameterSettable *object, QString newvalue)
Set the value of the object's parameter supposing that the parameter's type is QString.