00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PARAMETER_SETTABLE_H
00021 #define PARAMETER_SETTABLE_H
00022
00023 #include "configurationconfig.h"
00024 #include "runtimeparametersetters.h"
00025 #include <QFlags>
00026 #include <cmath>
00027 #include <limits>
00028
00029 namespace farsa {
00030
00031 class ConfigurationHelper;
00032 class ConfigurationParameters;
00033
00048 class FARSA_CONF_API ParameterSettable
00049 {
00050 public:
00057 enum Property {
00059 Default = 0x0000,
00061 IsList = 0x0001,
00063 IsMandatory = 0x0002,
00068 AllowMultiple = 0x0004
00069 };
00070 Q_DECLARE_FLAGS( Properties, Property )
00071
00072
00073 static const double Infinity;
00075 static const int MaxInteger;
00077 static const int MinInteger;
00078
00082 ParameterSettable()
00083 {
00084 }
00085
00089 virtual ~ParameterSettable()
00090 {
00091 }
00092
00102 virtual void save(ConfigurationParameters& params, QString prefix) = 0;
00103
00104
00115 static void describe( QString type ) { addTypeDescription( type, "Describe is missing" ); };
00116
00124 virtual void postConfigureInitialization()
00125 {
00126 }
00136 void setRuntimeParameter( QString paramFullPath, int newvalue );
00146 void setRuntimeParameter( QString paramFullPath, unsigned int newvalue );
00156 void setRuntimeParameter( QString paramFullPath, double newvalue );
00166 void setRuntimeParameter( QString paramFullPath, float newvalue );
00176 void setRuntimeParameter( QString paramFullPath, bool newvalue );
00178 QList<RuntimeParameterSetter*> runtimeParameterList();
00179
00180 protected:
00189 void markParameterAsRuntime( QString paramName, int* paramPointer );
00198 void markParameterAsRuntime( QString paramName, unsigned int* paramPointer );
00207 void markParameterAsRuntime( QString paramName, double* paramPointer );
00216 void markParameterAsRuntime( QString paramName, bool* paramPointer );
00228 template<class T>
00229 void markParameterAsRuntime( QString paramName, T* paramOwner, void (T::*setterMethod)(int), int (T::*getterMethod)()const ) {
00230 markParameterAsRuntime( new MethodSetter<T, int>( paramOwner, setterMethod, getterMethod, paramName ) );
00231 };
00243 template<class T>
00244 void markParameterAsRuntime( QString paramName, T* paramOwner, void (T::*setterMethod)(unsigned int), unsigned int (T::*getterMethod)()const ) {
00245 markParameterAsRuntime( new MethodSetter<T, unsigned int>( paramOwner, setterMethod, getterMethod, paramName ) );
00246 };
00258 template<class T>
00259 void markParameterAsRuntime( QString paramName, T* paramOwner, void (T::*setterMethod)(double), double (T::*getterMethod)()const ) {
00260 markParameterAsRuntime( new MethodSetter<T, double>( paramOwner, setterMethod, getterMethod, paramName ) );
00261 };
00273 template<class T>
00274 void markParameterAsRuntime( QString paramName, T* paramOwner, void (T::*setterMethod)(float), float (T::*getterMethod)()const ) {
00275 markParameterAsRuntime( new MethodSetter<T, float>( paramOwner, setterMethod, getterMethod, paramName ) );
00276 };
00288 template<class T>
00289 void markParameterAsRuntime( QString paramName, T* paramOwner, void (T::*setterMethod)(bool), bool (T::*getterMethod)()const ) {
00290 markParameterAsRuntime( new MethodSetter<T, bool>( paramOwner, setterMethod, getterMethod, paramName ) );
00291 };
00292
00295 class FARSA_CONF_API StringDescriptor {
00296 public:
00300 StringDescriptor( QString paramPath );
00302 StringDescriptor& def( QString defaultValue );
00304 StringDescriptor& props( Properties properties );
00313 StringDescriptor& help( QString shortHelp, QString longHelp=QString("") );
00314 private:
00316 QString paramPath;
00317 };
00318
00321 class FARSA_CONF_API IntDescriptor {
00322 public:
00326 IntDescriptor( QString paramPath );
00328 IntDescriptor& def( int defaultValue );
00330 IntDescriptor& props( Properties properties );
00337 IntDescriptor& limits( int lower_bound, int upper_bound );
00346 IntDescriptor& help( QString shortHelp, QString longHelp=QString("") );
00347 private:
00349 QString paramPath;
00350 };
00351
00354 class FARSA_CONF_API RealDescriptor {
00355 public:
00359 RealDescriptor( QString paramPath );
00361 RealDescriptor& def( double defaultValue );
00363 RealDescriptor& props( Properties properties );
00370 RealDescriptor& limits( double lower_bound, double upper_bound );
00379 RealDescriptor& help( QString shortHelp, QString longHelp=QString("") );
00380 private:
00382 QString paramPath;
00383 };
00384
00387 class FARSA_CONF_API BoolDescriptor {
00388 public:
00392 BoolDescriptor( QString paramPath );
00394 BoolDescriptor& def( bool defaultValue );
00396 BoolDescriptor& props( Properties properties );
00405 BoolDescriptor& help( QString shortHelp, QString longHelp=QString("") );
00406 private:
00408 QString paramPath;
00409 };
00410
00413 class FARSA_CONF_API EnumDescriptor {
00414 public:
00418 EnumDescriptor( QString paramPath );
00420 EnumDescriptor& def( QString defaultValue );
00422 EnumDescriptor& props( Properties properties );
00424 EnumDescriptor& values( QStringList allValues );
00433 EnumDescriptor& help( QString shortHelp, QString longHelp=QString("") );
00434 private:
00436 QString paramPath;
00437 };
00438
00441 class FARSA_CONF_API ObjectDescriptor {
00442 public:
00446 ObjectDescriptor( QString paramPath );
00448 ObjectDescriptor& props( Properties properties );
00450 ObjectDescriptor& type( QString className );
00459 ObjectDescriptor& help( QString shortHelp, QString longHelp=QString("") );
00460 private:
00462 QString paramPath;
00463 };
00464
00467 class FARSA_CONF_API SubgroupDescriptor {
00468 public:
00472 SubgroupDescriptor( QString paramPath );
00474 SubgroupDescriptor& props( Properties properties );
00476 SubgroupDescriptor& type( QString className );
00485 SubgroupDescriptor& help( QString shortHelp, QString longHelp=QString("") );
00495 StringDescriptor describeString( QString parameter );
00505 IntDescriptor describeInt( QString parameter );
00515 RealDescriptor describeReal( QString parameter );
00525 BoolDescriptor describeBool( QString parameter );
00535 EnumDescriptor describeEnum( QString parameter );
00545 ObjectDescriptor describeObject( QString parameter );
00555 SubgroupDescriptor describeSubgroup( QString subgroup );
00556 private:
00558 QString subgroupPath;
00559 };
00560
00563 class FARSA_CONF_API Descriptor {
00564 public:
00572 Descriptor( QString type, QString shortHelp, QString longHelp );
00584 StringDescriptor describeString( QString parameter );
00596 IntDescriptor describeInt( QString parameter );
00608 RealDescriptor describeReal( QString parameter );
00620 BoolDescriptor describeBool( QString parameter );
00632 EnumDescriptor describeEnum( QString parameter );
00644 ObjectDescriptor describeObject( QString parameter );
00656 SubgroupDescriptor describeSubgroup( QString subgroup );
00657 private:
00659 QString type;
00660 };
00661
00676 static Descriptor addTypeDescription( QString type, QString shortHelp, QString longHelp=QString("") );
00677
00678 private:
00690 void markParameterAsRuntime( RuntimeParameterSetter* setter );
00691
00693 QMap<QString, RuntimeParameterSetter*> runtimeParameters;
00694 };
00695
00706 class FARSA_CONF_TEMPLATE ParameterSettableInConstructor : public ParameterSettable
00707 {
00708 public:
00715 ParameterSettableInConstructor()
00716 {
00717 }
00718
00732 ParameterSettableInConstructor(ConfigurationParameters& , QString )
00733 {
00734 }
00735
00739 virtual ~ParameterSettableInConstructor()
00740 {
00741 }
00742 };
00743
00754 class FARSA_CONF_TEMPLATE ParameterSettableWithConfigureFunction : public ParameterSettable
00755 {
00756 public:
00760 ParameterSettableWithConfigureFunction()
00761 {
00762 }
00763
00767 virtual ~ParameterSettableWithConfigureFunction()
00768 {
00769 }
00770
00781 virtual void configure(ConfigurationParameters& params, QString prefix) = 0;
00782 };
00783
00784 }
00785
00786 Q_DECLARE_OPERATORS_FOR_FLAGS( farsa::ParameterSettable::Properties )
00787
00788 #endif