Bug: Now should read detect correctly needrestart/mustexist.

This commit is contained in:
Jean-Paul Chaput 2011-02-24 15:37:50 +00:00
parent 4c2f16a4fe
commit 86d5f4e94f
10 changed files with 251 additions and 187 deletions

View File

@ -19,6 +19,7 @@
set ( includes vlsisapd/configuration/Parameter.h set ( includes vlsisapd/configuration/Parameter.h
vlsisapd/configuration/LayoutDescription.h vlsisapd/configuration/LayoutDescription.h
vlsisapd/configuration/Configuration.h vlsisapd/configuration/Configuration.h
vlsisapd/configuration/BoostPythonStlWrappers.h
) )
set ( cpps Parameter.cpp set ( cpps Parameter.cpp
LayoutDescription.cpp LayoutDescription.cpp

View File

@ -91,10 +91,10 @@ int main ( int argc, char* argv[] )
conf->readFromFile ( dotConfPath.string() ); conf->readFromFile ( dotConfPath.string() );
} }
cout << "misc.catchCore: " << conf->getParameter("misc.catchCore" )->asBool() << endl; //cout << "misc.catchCore: " << conf->getParameter("misc.catchCore" )->asBool() << endl;
cout << "kite.eventsLimit: " << conf->getParameter("kite.eventsLimit")->asInt () << endl; //cout << "kite.eventsLimit: " << conf->getParameter("kite.eventsLimit")->asInt () << endl;
bfs::path pyDotConfPath ( "./.coriolis2.init.py" ); bfs::path pyDotConfPath ( "./.coriolis2.configuration.py" );
if ( bfs::exists(pyDotConfPath) ) { if ( bfs::exists(pyDotConfPath) ) {
cout << "Reading python dot configuration: <" << pyDotConfPath.string() << ">." << endl; cout << "Reading python dot configuration: <" << pyDotConfPath.string() << ">." << endl;
Py_Initialize (); Py_Initialize ();

View File

@ -87,8 +87,8 @@ namespace Cfg {
cout << "Saving configuration file: <" << dotConfigFile << ">."<< endl; cout << "Saving configuration file: <" << dotConfigFile << ">."<< endl;
//Configuration::get()->writeToStream ( file, 0, ";misc;kite;;mauka;;" ); //Configuration::get()->writeToStream ( file, 0, ";misc;kite;;mauka;;" );
Configuration::get()->writeToStream ( file, Configuration::DriveValues|Configuration::DriveLayout, "misc" ); //Configuration::get()->writeToStream ( file, Configuration::DriveValues|Configuration::DriveLayout, "misc" );
//Configuration::get()->writeToStream ( file, 0 ); Configuration::get()->writeToStream ( file, 0 );
//Configuration::get()->writeToStream ( file, Configuration::DriveValues|Configuration::DriveLayout ); //Configuration::get()->writeToStream ( file, Configuration::DriveValues|Configuration::DriveLayout );
file.close (); file.close ();
} }

View File

@ -147,6 +147,7 @@ namespace {
); );
} else { } else {
_parameter->setString ( _getAttributeValue("value") _parameter->setString ( _getAttributeValue("value")
, Configuration::getDefaultPriority()
, (Parameter::AllRequirements | Parameter::FromString) , (Parameter::AllRequirements | Parameter::FromString)
& ~Parameter::TypeCheck & ~Parameter::TypeCheck
); );

View File

@ -140,7 +140,7 @@ namespace Cfg {
{ {
ParameterWidget* pw = find(parameter); ParameterWidget* pw = find(parameter);
if ( pw != NULL ) { if ( pw != NULL ) {
cerr << "[ERROR] Parameter <" << parameter->getId() << "> already added." << endl; cerr << "[ERROR] ParameterWidget for <" << parameter->getId() << "> already added." << endl;
return pw; return pw;
} }

View File

@ -129,6 +129,9 @@ namespace Cfg {
case WidgetDescription::Parameter: case WidgetDescription::Parameter:
Parameter* parameter = _configuration->getParameter ( widgets[iwidget]->getId() ); Parameter* parameter = _configuration->getParameter ( widgets[iwidget]->getId() );
if ( parameter ) { if ( parameter ) {
// cerr << "WidgetDescription::Parameter: " << (void*)widgets[iwidget]
// << " " << widgets[iwidget]->getId()
// << " " << (void*)parameter << endl;
cw->addParameter ( _tabs[itab]->getName() cw->addParameter ( _tabs[itab]->getName()
, parameter , parameter
, widgets[iwidget]->getLabel() , widgets[iwidget]->getLabel()

View File

@ -100,7 +100,7 @@ namespace Cfg {
} }
if ( priority == UseDefault ) _priority = getDefaultPriority(); if ( priority == UseDefault ) _priority = getDefaultPriority();
//cerr << "New " << typeToString(_type) << " parameter " << _id << " value:" << _value << endl; //cerr << "New " << (void*)this << " " << typeToString(_type) << " parameter " << _id << " value:" << _value << endl;
} }
@ -162,10 +162,11 @@ namespace Cfg {
} }
bool Parameter::setString ( const std::string& s, unsigned int flags, Priority priority ) bool Parameter::setString ( const std::string& s, Priority priority, unsigned int flags )
{ {
if ( not _updatePriority(priority) ) return false; if ( not _updatePriority(priority) ) return false;
flags |= _flags;
if ( (flags & TypeCheck) and (_type != String) ) if ( (flags & TypeCheck) and (_type != String) )
cerr << "[ERROR] Parameter::setString(): Setting " << Parameter::typeToString(_type) cerr << "[ERROR] Parameter::setString(): Setting " << Parameter::typeToString(_type)
<< " parameter <" << _id << " parameter <" << _id
@ -184,7 +185,7 @@ namespace Cfg {
<< " parameter <" << _id << " parameter <" << _id
<< "> as " << Parameter::typeToString(Bool)<< " (type mismatch)." << endl; << "> as " << Parameter::typeToString(Bool)<< " (type mismatch)." << endl;
return _doChange ( AllRequirements, "", b, 0, 0.0 ); return _doChange ( _flags, "", b, 0, 0.0 );
} }
@ -197,7 +198,7 @@ namespace Cfg {
<< " parameter <" << _id << " parameter <" << _id
<< "> as " << Parameter::typeToString(Int)<< " (type mismatch)." << endl; << "> as " << Parameter::typeToString(Int)<< " (type mismatch)." << endl;
return _doChange ( AllRequirements, "", false, i, 0.0 ); return _doChange ( _flags, "", false, i, 0.0 );
} }
@ -210,7 +211,7 @@ namespace Cfg {
<< " parameter <" << _id << " parameter <" << _id
<< "> as " << Parameter::typeToString(Double)<< " (type mismatch)." << endl; << "> as " << Parameter::typeToString(Double)<< " (type mismatch)." << endl;
return _doChange ( AllRequirements, "", false, 0, d ); return _doChange ( _flags, "", false, 0, d );
} }
@ -223,7 +224,7 @@ namespace Cfg {
<< " parameter <" << _id << " parameter <" << _id
<< "> as " << Parameter::typeToString(Double)<< " (type mismatch)." << endl; << "> as " << Parameter::typeToString(Double)<< " (type mismatch)." << endl;
return _doChange ( AllRequirements, "", false, 0, d ); return _doChange ( _flags, "", false, 0, d );
} }
@ -255,7 +256,8 @@ namespace Cfg {
bool Parameter::_doChange ( unsigned int flags, const string& s, bool b, int i, double d ) bool Parameter::_doChange ( unsigned int flags, const string& s, bool b, int i, double d )
{ {
//cerr << "_doChange: " << _id << ":" << _value << " -> \"" << s << "\"|" << b << "|" << i << "|" << d; //cerr << "_doChange: " << _id << ":" << _value << " -> \"" << s << "\"|" << b << "|" << i << "|" << d
// << " [" << _flags << "]";
Configuration* configuration = Configuration::get(); Configuration* configuration = Configuration::get();
ostringstream svalue; ostringstream svalue;
@ -296,15 +298,17 @@ namespace Cfg {
} }
if ( (flags & NeedRestart) and hasFlags(NeedRestart) ) { if ( (flags & NeedRestart) and hasFlags(NeedRestart) ) {
//cerr << " needrestart";
configuration->addLog ( Configuration::LogRestart, _id ); configuration->addLog ( Configuration::LogRestart, _id );
} }
if ( (flags & MustExist) and hasFlags(MustExist) ) { if ( (flags & MustExist) and hasFlags(MustExist) ) {
if ( _type == String ) { if ( _type == String ) {
bfs::path filePath = ( svalue.str() ); bfs::path filePath = ( svalue.str() );
if ( not bfs::exists(filePath) ) if ( not bfs::exists(filePath) ) {
//cerr << " needrestart" << _id << endl;
configuration->addLog ( Configuration::LogNeedExist, _id ); configuration->addLog ( Configuration::LogNeedExist, _id );
else } else
configuration->removeLog ( Configuration::LogNeedExist, _id ); configuration->removeLog ( Configuration::LogNeedExist, _id );
} }
} }

View File

@ -19,103 +19,143 @@
// +-----------------------------------------------------------------+ // +-----------------------------------------------------------------+
#include <boost/python.hpp> #include <sstream>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp> #include "vlsisapd/configuration/BoostPythonStlWrappers.h"
#include "vlsisapd/configuration/Configuration.h"
#include "vlsisapd/configuration/ParameterWidget.h"
using namespace boost::python; using namespace boost::python;
#include "vlsisapd/openChams/PySTLMapWrapper.h"
using OpenChams::map_item;
#include "vlsisapd/configuration/Configuration.h"
namespace { namespace {
using namespace Cfg; using namespace Cfg;
template<typename EnumType>
struct EnumToInt {
static PyObject* convert ( EnumType& type )
{ return incref ( object((int)type).ptr() ); }
};
// Thin wrappers for function members overloads. // Thin wrappers for function members overloads.
void parameterSetMinInt1 ( Parameter& self, int min ) { self.setMin(min); } bool paramSetString1 ( Parameter& self, const std::string& value )
void parameterSetMinDouble1 ( Parameter& self, double min ) { self.setMin(min); } { return self.setString(value); }
void parameterSetMaxInt1 ( Parameter& self, int max ) { self.setMax(max); }
void parameterSetMaxDouble1 ( Parameter& self, double max ) { self.setMax(max); }
// STL map wrapper for boost::python. bool paramSetString2 ( Parameter& self, const std::string& value, unsigned int flags )
template<typename Map> { return self.setString(value,Configuration::getDefaultPriority(),flags); }
class MapWrapper {
public:
typedef typename Map::key_type Key;
typedef typename Map::mapped_type Value;
public:
static Value& get ( Map&, const Key& );
static void set ( Map&, const Key&, const Value& );
static void del ( Map&, const Key& );
static bool in ( Map&, const Key& );
static list keys ( Map& );
static list values ( Map& );
static list items ( Map& );
};
bool paramSetString3 ( Parameter& self, const std::string& value, unsigned int flags, Parameter::Priority pri )
{ return self.setString(value,pri,flags); }
inline void KeyError () { PyErr_SetString(PyExc_KeyError, "Key not found"); } bool paramSetBool1 ( Parameter& self, bool value ) { return self.setBool(value); }
bool paramSetInt1 ( Parameter& self, int value ) { return self.setInt(value); }
bool paramSetDouble1 ( Parameter& self, double value ) { return self.setDouble(value); }
bool paramSetPercentage1 ( Parameter& self, double value ) { return self.setPercentage(value); }
bool paramSetBool2 ( Parameter& self, bool value, Parameter::Priority pri ) { return self.setBool(value,pri); }
bool paramSetInt2 ( Parameter& self, int value, Parameter::Priority pri ) { return self.setInt(value,pri); }
bool paramSetDouble2 ( Parameter& self, double value, Parameter::Priority pri ) { return self.setDouble(value,pri); }
bool paramSetPercentage2 ( Parameter& self, double value, Parameter::Priority pri ) { return self.setPercentage(value,pri); }
template<typename Map> void paramSetMinInt1 ( Parameter& self, int min ) { self.setMin(min); }
typename MapWrapper<Map>::Value& MapWrapper<Map>::get ( Map& m, const typename MapWrapper<Map>::Key& k ) void paramSetMinDouble1 ( Parameter& self, double min ) { self.setMin(min); }
void paramSetMaxInt1 ( Parameter& self, int max ) { self.setMax(max); }
void paramSetMaxDouble1 ( Parameter& self, double max ) { self.setMax(max); }
std::string reprParameter ( const Parameter* p )
{ {
static Value notFound; std::ostringstream repr;
if( m.find(k) != m.end() ) return m[k]; repr << "<Parameter id=\"" << p->getId()
KeyError (); << "\" type=\"" << Parameter::typeToString(p->getType())
return notFound; << "\" value=\"";
if ( p->getType() == Parameter::Percentage ) repr << p->asPercentageString();
else repr << p->asString();
repr << "\">";
return repr.str();
} }
template<typename Map>
void MapWrapper<Map>::set ( Map& m, const MapWrapper<Map>::Key& k, const typename MapWrapper<Map>::Value& v )
{ m[k] = v; }
template<typename Map> void layoutAddTab ( LayoutDescription& self
void MapWrapper<Map>::del ( Map& m, const typename MapWrapper<Map>::Key& k) , const std::string& tabName
{ , const std::string& id
if( m.find(k) != m.end() ) m.erase(k); )
else KeyError (); { self.addTab(tabName,id); }
}
template<typename Map>
bool MapWrapper<Map>::in ( Map& m, const typename MapWrapper<Map>::Key& k )
{ return m.find(k) != m.end(); }
template<typename Map> void layoutAddSection2 ( LayoutDescription& self
list MapWrapper<Map>::keys ( Map& m ) , const std::string& tabName
{ , const std::string& section
list l; )
for(typename Map::iterator it = m.begin() ; it != m.end() ; ++it ) { self.addSection(tabName,section); };
l.append ( it->first );
return l;
}
template<typename Map>
list MapWrapper<Map>::values ( Map& m)
{
list l;
for( typename Map::iterator it=m.begin(); it != m.end() ; ++it )
l.append ( it->second );
return l;
}
template<typename Map> void layoutAddSection3 ( LayoutDescription& self
list MapWrapper<Map>::items ( Map& m ) { , const std::string& tabName
list l; , const std::string& section
for( typename Map::iterator it=m.begin(); it!=m.end(); ++it ) , int column
l.append( make_tuple(it->first,it->second) ); )
return l; { self.addSection(tabName,section,column); };
}
void layoutAddParameter3 ( LayoutDescription& self
, const std::string& tabName
, const std::string& id
, const std::string& label
)
{ self.addParameter(tabName,id,label); };
void layoutAddParameter4 ( LayoutDescription& self
, const std::string& tabName
, const std::string& id
, const std::string& label
, int column
)
{ self.addParameter(tabName,id,label,column); };
void layoutAddParameter5 ( LayoutDescription& self
, const std::string& tabName
, const std::string& id
, const std::string& label
, int column
, int span
)
{ self.addParameter(tabName,id,label,column,span); };
void layoutAddParameter6 ( LayoutDescription& self
, const std::string& tabName
, const std::string& id
, const std::string& label
, int column
, int span
, unsigned int flags
)
{ self.addParameter(tabName,id,label,column,span,flags); };
Parameter* cfgGetParameter1 ( const Configuration& self, const std::string& id )
{ return self.getParameter(id); }
Parameter* cfgGetParameter2 ( const Configuration& self, const std::string& id, Parameter::Type type )
{ return self.getParameter(id,type); }
Parameter* cfgAddParameter2 ( Configuration& self, const std::string& id, Parameter::Type type, const std::string& value )
{ return self.addParameter(id,type,value); }
Parameter* cfgAddParameter3 ( Configuration& self, const std::string& id, Parameter::Type type, const std::string& value, Parameter::Priority pri )
{ return self.addParameter(id,type,value,pri); }
Parameter* getParamString1 ( const std::string& id ) { return getParamString(id); }
Parameter* getParamBool1 ( const std::string& id ) { return getParamBool(id); }
Parameter* getParamInt1 ( const std::string& id ) { return getParamInt(id); }
Parameter* getParamEnumerate1 ( const std::string& id ) { return getParamEnumerate(id); }
Parameter* getParamDouble1 ( const std::string& id ) { return getParamDouble(id); }
Parameter* getParamPercentage1 ( const std::string& id ) { return getParamPercentage(id); }
Parameter* getParamString2 ( const std::string& id, const std::string& value ) { return getParamString(id,value); }
Parameter* getParamInt2 ( const std::string& id, int value ) { return getParamInt(id,value); }
Parameter* getParamEnumerate2 ( const std::string& id, int value ) { return getParamEnumerate(id,value); }
Parameter* getParamBool2 ( const std::string& id, bool value ) { return getParamBool(id,value); }
Parameter* getParamDouble2 ( const std::string& id, double value ) { return getParamDouble(id,value); }
Parameter* getParamPercentage2 ( const std::string& id, double value ) { return getParamPercentage(id,value); }
} // End of anonymous namespace. } // End of anonymous namespace.
@ -126,6 +166,9 @@ namespace Cfg {
BOOST_PYTHON_MODULE(Cfg) { BOOST_PYTHON_MODULE(Cfg) {
VectorWrapper< std::vector<std::string> >::wrap ( "StringVector" );
VectorWrapper< std::vector<Parameter::EnumValue> >::wrap ( "EnumValueVector" );
typedef void (Parameter::* VoidIntPrioritySign )(int ,Parameter::Priority) ; typedef void (Parameter::* VoidIntPrioritySign )(int ,Parameter::Priority) ;
typedef void (Parameter::* VoidDoublePrioritySign )(double,Parameter::Priority) ; typedef void (Parameter::* VoidDoublePrioritySign )(double,Parameter::Priority) ;
typedef void (Parameter::* VoidIntSign )(int ); typedef void (Parameter::* VoidIntSign )(int );
@ -141,73 +184,74 @@ namespace Cfg {
// Parameter overloaded function members. // Parameter overloaded function members.
BoolIntConstSign paramCheckValueInt = (BoolIntConstSign) &Parameter::checkValue; BoolIntConstSign paramCheckValueInt = (BoolIntConstSign) &Parameter::checkValue;
BoolDoubleConstSign paramCheckValueDouble = (BoolDoubleConstSign)&Parameter::checkValue; BoolDoubleConstSign paramCheckValueDouble = (BoolDoubleConstSign)&Parameter::checkValue;
BoolStringSign paramSetString1 = (BoolStringSign) &Parameter::setString;
BoolStringFlagsSign paramSetString2 = (BoolStringFlagsSign)&Parameter::setString;
BoolBoolSign paramSetBool1 = (BoolBoolSign) &Parameter::setBool;
BoolIntSign paramSetInt1 = (BoolIntSign) &Parameter::setInt;
BoolDoubleSign paramSetDouble1 = (BoolDoubleSign) &Parameter::setDouble;
BoolDoubleSign paramSetPercentage1 = (BoolDoubleSign) &Parameter::setPercentage;
implicitly_convertible<Parameter::Type ,int>(); implicitly_convertible<Parameter::Type ,int>();
implicitly_convertible<Parameter::Flags ,int>(); implicitly_convertible<Parameter::Flags ,int>();
implicitly_convertible<Parameter::Priority,int>(); implicitly_convertible<Parameter::Priority,int>();
//to_python_converter<const Parameter::Type ,EnumToInt<const Parameter::Type> >(); //to_python_converter<const Parameter::Type,EnumToInt<const Parameter::Type> >();
{ {
scope paramScope scope paramScope
( class_<Parameter>("Parameter", init<const std::string&, Parameter::Type, const std::string& ( class_<Parameter>("Parameter", init<const std::string&, Parameter::Type, const std::string&
,optional<Parameter::Priority> >()) ,optional<Parameter::Priority> >())
.def("isFile" , &Parameter::isFile) .def("__repr__" , reprParameter)
.def("isPath" , &Parameter::isPath) .def("isFile" , &Parameter::isFile)
.def("hasMin" , &Parameter::hasMin) .def("isPath" , &Parameter::isPath)
.def("hasMax" , &Parameter::hasMax) .def("hasMin" , &Parameter::hasMin)
.def("hasNeedRestart" , &Parameter::hasNeedRestart) .def("hasMax" , &Parameter::hasMax)
.def("hasMustExist" , &Parameter::hasMustExist) .def("hasNeedRestart" , &Parameter::hasNeedRestart)
//.def("hasFlags" , &Parameter::hasFlags) .def("hasMustExist" , &Parameter::hasMustExist)
.def("getId" , &Parameter::getId, return_value_policy<reference_existing_object>()) .def("hasFlags" , &Parameter::hasFlags)
.def("getMinInt" , &Parameter::getMinInt) .def("getId" , &Parameter::getId, return_value_policy<copy_const_reference>())
.def("getMaxInt" , &Parameter::getMaxInt) .def("getMinInt" , &Parameter::getMinInt)
.def("getMinDouble" , &Parameter::getMinDouble) .def("getMaxInt" , &Parameter::getMaxInt)
.def("getMaxDouble" , &Parameter::getMaxDouble) .def("getMinDouble" , &Parameter::getMinDouble)
.def("checkValue" , paramCheckValueInt) .def("getMaxDouble" , &Parameter::getMaxDouble)
.def("checkValue" , paramCheckValueDouble) .def("checkValue" , paramCheckValueInt)
.def("asString" , &Parameter::asString, return_value_policy<reference_existing_object>()) .def("checkValue" , paramCheckValueDouble)
.def("asPercentageString", &Parameter::asPercentageString) .def("asString" , &Parameter::asString, return_value_policy<copy_const_reference>())
.def("asBool" , &Parameter::asBool) .def("asPercentageString", &Parameter::asPercentageString)
.def("asInt" , &Parameter::asInt) .def("asBool" , &Parameter::asBool)
.def("asPercentage" , &Parameter::asPercentage) .def("asInt" , &Parameter::asInt)
.def("addValue" , &Parameter::addValue) .def("asPercentage" , &Parameter::asPercentage)
.def("addSlave" , &Parameter::addSlave) .def("getSlaves" , &Parameter::getSlaves, return_value_policy<reference_existing_object>())
.def("setPriority" , &Parameter::setPriority) .def("getValues" , &Parameter::getValues, return_value_policy<reference_existing_object>())
.def("setString" , &Parameter::setString) .def("addValue" , &Parameter::addValue)
.def("setString" , paramSetString1) .def("addSlave" , &Parameter::addSlave)
.def("setString" , paramSetString2) .def("setPriority" , &Parameter::setPriority)
.def("setBool" , &Parameter::setBool) .def("setString" , paramSetString1)
.def("setBool" , paramSetBool1) .def("setString" , paramSetString2)
.def("setInt" , &Parameter::setInt) .def("setString" , paramSetString3)
.def("setInt" , paramSetInt1) .def("setBool" , paramSetBool1)
.def("setDouble" , &Parameter::setDouble) .def("setBool" , paramSetBool2)
.def("setDouble" , paramSetDouble1) .def("setInt" , paramSetInt1)
.def("setPercentage" , &Parameter::setPercentage) .def("setInt" , paramSetInt2)
.def("setPercentage" , paramSetPercentage1) .def("setDouble" , paramSetDouble1)
.def("setMin" , &parameterSetMinInt1) .def("setDouble" , paramSetDouble2)
.def("setMin" , &parameterSetMinDouble1) .def("setPercentage" , paramSetPercentage1)
.def("setMax" , &parameterSetMaxInt1) .def("setPercentage" , paramSetPercentage2)
.def("setMax" , &parameterSetMaxDouble1) .def("setMin" , paramSetMinInt1)
.def("setMin" , paramSetMinDouble1)
.def("setMax" , paramSetMaxInt1)
.def("setMax" , paramSetMaxDouble1)
.add_property("flags", &Parameter::getFlags, &Parameter::setFlags)
.add_property("type" , &Parameter::getType)
);
//.add_property("flags", &Parameter::getFlags, &Parameter::setFlags) class_<Parameter::EnumValue>("Parameter::EnumValue",init<std::string,int>())
.add_property("type" , &Parameter::getType) .def_readonly("label",&Parameter::EnumValue::_label)
); .def_readonly("value",&Parameter::EnumValue::_value)
;
enum_<Parameter::Type>("Type") enum_<Parameter::Type>("Type")
.value("Unknown" ,Parameter::Unknown) .value("Unknown" ,Parameter::Unknown)
.value("String" ,Parameter::String) .value("String" ,Parameter::String)
.value("Bool" ,Parameter::Bool) .value("Bool" ,Parameter::Bool)
.value("Int" ,Parameter::Int) .value("Int" ,Parameter::Int)
.value("Enumerate" ,Parameter::Enumerate) .value("Enumerate" ,Parameter::Enumerate)
.value("Double" ,Parameter::Double) .value("Double" ,Parameter::Double)
.value("Percentage",Parameter::Percentage) .value("Percentage",Parameter::Percentage)
; ;
enum_<Parameter::Priority>("Priority") enum_<Parameter::Priority>("Priority")
@ -231,40 +275,45 @@ namespace Cfg {
; ;
} }
{
scope layoutScope
( class_<LayoutDescription>("LayoutDescription", no_init)
.def("addTab" , layoutAddTab)
.def("addRule" , &LayoutDescription::addRule)
.def("addTitle" , &LayoutDescription::addTitle)
.def("addSection" , layoutAddSection2)
.def("addSection" , layoutAddSection3)
.def("addParameter", layoutAddParameter3)
.def("addParameter", layoutAddParameter4)
.def("addParameter", layoutAddParameter5)
.def("addParameter", layoutAddParameter6)
);
}
typedef std::map <const std::string,Parameter*> ParametersMap; typedef std::map <const std::string,Parameter*> ParametersMap;
typedef std::pair<const std::string,Parameter*> ParametersPair; typedef std::pair<const std::string,Parameter*> ParametersPair;
class_<ParametersPair>("ParametersPair") PairWrapper<ParametersPair>::wrap ( "ParametersPair", "key", "value" );
.def_readonly ("key" , &ParametersPair::first ) MapWrapper <ParametersMap >::wrap ( "ParametersMap" );
.def_readwrite("value", &ParametersPair::second)
;
class_<ParametersMap>("ParametersMap")
.def("__len__" , &ParametersMap::size)
.def("clear" , &ParametersMap::clear)
.def("__getitem__" , &MapWrapper<ParametersMap>::get, return_value_policy<reference_existing_object>())
.def("__setitem__" , &MapWrapper<ParametersMap>::set, return_value_policy<reference_existing_object>())
.def("__delitem__" , &MapWrapper<ParametersMap>::del)
.def("__contains__" , &MapWrapper<ParametersMap>::in )
.def("has_key" , &MapWrapper<ParametersMap>::in )
.def("keys" , &MapWrapper<ParametersMap>::keys )
.def("values" , &MapWrapper<ParametersMap>::values )
.def("items" , &MapWrapper<ParametersMap>::items )
;
// Configuration overloaded function members. // Configuration overloaded function members.
Parameter* (Configuration::*CfgGetParameter1) ( const std::string& ) const = (Parameter* (Configuration:: *)(const std::string&) const) &Configuration::getParameter; typedef LayoutDescription& (Configuration::* LayoutVoidSign )();
Parameter* (Configuration::*CfgGetParameter2) ( const std::string&, Parameter::Type ) const = (Parameter* (Configuration:: *)(const std::string&,Parameter::Type) const)&Configuration::getParameter;
LayoutVoidSign CfgGetLayout0 = (LayoutVoidSign)&Configuration::getLayout;
{ {
scope confScope scope confScope
( class_<Configuration>("Configuration", no_init) ( class_<Configuration>("Configuration", no_init)
.def("get" , &Configuration::get , return_value_policy<reference_existing_object>()) .def("get" , &Configuration::get , return_value_policy<reference_existing_object>())
.def("getParameter" , CfgGetParameter1 , return_value_policy<reference_existing_object>()) .def("getParameter" , cfgGetParameter1 , return_value_policy<reference_existing_object>())
.def("getParameter" , CfgGetParameter2 , return_value_policy<reference_existing_object>()) .def("getParameter" , cfgGetParameter2 , return_value_policy<reference_existing_object>())
.def("addParameter" , cfgAddParameter2 , return_value_policy<reference_existing_object>())
.def("addParameter" , cfgAddParameter3 , return_value_policy<reference_existing_object>())
.def("pushDefaultPriority", &Configuration::pushDefaultPriority) .def("pushDefaultPriority", &Configuration::pushDefaultPriority)
.def("popDefaultPriority" , &Configuration::popDefaultPriority ) .def("popDefaultPriority" , &Configuration::popDefaultPriority )
.def("getDefaultPriority" , &Configuration::getDefaultPriority ) .def("getDefaultPriority" , &Configuration::getDefaultPriority )
.def("getParameters" , &Configuration::getParameters , return_value_policy<reference_existing_object>()) .def("getParameters" , &Configuration::getParameters , return_value_policy<reference_existing_object>())
.def("getLayout" , CfgGetLayout0 , return_value_policy<reference_existing_object>())
.staticmethod("get") .staticmethod("get")
.staticmethod("pushDefaultPriority") .staticmethod("pushDefaultPriority")
.staticmethod("popDefaultPriority") .staticmethod("popDefaultPriority")
@ -280,27 +329,6 @@ namespace Cfg {
; ;
} }
// Configuration overloaded functions.
typedef Parameter* (*ParamStringSign )(const std::string&);
typedef Parameter* (*ParamStringBoolSign )(const std::string&, bool);
typedef Parameter* (*ParamStringIntSign )(const std::string&, int);
typedef Parameter* (*ParamStringDoubleSign)(const std::string&, double);
typedef Parameter* (*ParamStringStringSign)(const std::string&, const std::string&);
ParamStringSign getParamString1 = (ParamStringSign )getParamString;
ParamStringStringSign getParamString2 = (ParamStringStringSign)getParamString;
ParamStringSign getParamBool1 = (ParamStringSign )getParamBool;
ParamStringBoolSign getParamBool2 = (ParamStringBoolSign )getParamBool;
ParamStringSign getParamInt1 = (ParamStringSign )getParamInt;
ParamStringIntSign getParamInt2 = (ParamStringIntSign )getParamInt;
ParamStringSign getParamEnumerate1 = (ParamStringSign )getParamEnumerate;
ParamStringIntSign getParamEnumerate2 = (ParamStringIntSign )getParamEnumerate;
ParamStringSign getParamDouble1 = (ParamStringSign )getParamDouble;
ParamStringDoubleSign getParamDouble2 = (ParamStringDoubleSign)getParamDouble;
ParamStringSign getParamPercentage1 = (ParamStringSign )getParamPercentage;
ParamStringDoubleSign getParamPercentage2 = (ParamStringDoubleSign)getParamPercentage;
def("getParamString" , getParamString1 , return_value_policy<reference_existing_object>()); def("getParamString" , getParamString1 , return_value_policy<reference_existing_object>());
def("getParamString" , getParamString2 , return_value_policy<reference_existing_object>()); def("getParamString" , getParamString2 , return_value_policy<reference_existing_object>());
def("getParamBool" , getParamBool1 , return_value_policy<reference_existing_object>()); def("getParamBool" , getParamBool1 , return_value_policy<reference_existing_object>());
@ -314,6 +342,30 @@ namespace Cfg {
def("getParamPercentage", getParamPercentage1, return_value_policy<reference_existing_object>()); def("getParamPercentage", getParamPercentage1, return_value_policy<reference_existing_object>());
def("getParamPercentage", getParamPercentage2, return_value_policy<reference_existing_object>()); def("getParamPercentage", getParamPercentage2, return_value_policy<reference_existing_object>());
enum_<ParameterWidget::Flags>("ParameterWidgetFlags")
.value("UseSpinBox",ParameterWidget::UseSpinBox)
.value("IsFileName",ParameterWidget::IsFileName)
.value("IsPathName",ParameterWidget::IsPathName)
;
// {
// scope parameterWidgetScope
// ( class_<ParameterWidget>("ParameterWidget", no_init)
// .def("getParameter", &ParameterWidget::getParameter, return_value_policy<reference_existing_object>())
// .def("hasFlags" , &ParameterWidget::hasFlags )
// .def("unsetFlags" , &ParameterWidget::unsetFlags )
// .add_property("flags", &ParameterWidget::getFlags, &ParameterWidget::setFlags)
// );
// implicitly_convertible<ParameterWidget::Flags,int>();
// enum_<ParameterWidget::Flags>("Flags")
// .value("UseSpinBox",ParameterWidget::UseSpinBox)
// .value("IsFileName",ParameterWidget::IsFileName)
// .value("IsPathName",ParameterWidget::IsPathName)
// ;
// }
} // End of Configuration BOOST_PYTHON_MODULE. } // End of Configuration BOOST_PYTHON_MODULE.

View File

@ -162,6 +162,8 @@ namespace Cfg {
inline Parameter* getParamInt ( const std::string& id, int value=0 ) inline Parameter* getParamInt ( const std::string& id, int value=0 )
{ {
//std::cerr << "getParamInt() " << id << " value:" << value << std::endl;
Parameter* parameter = Configuration::get()->getParameter(id,Parameter::Int); Parameter* parameter = Configuration::get()->getParameter(id,Parameter::Int);
if ( parameter == NULL ) { if ( parameter == NULL ) {
parameter = Configuration::get()->addParameter ( id, Parameter::Int, "0" ); parameter = Configuration::get()->addParameter ( id, Parameter::Int, "0" );
@ -221,6 +223,7 @@ namespace Cfg {
{ {
Parameter* parameter = Configuration::get()->getParameter(_id); Parameter* parameter = Configuration::get()->getParameter(_id);
if ( parameter != NULL ) parameter->setString ( _valid if ( parameter != NULL ) parameter->setString ( _valid
, Configuration::getDefaultPriority()
, (Parameter::AllRequirements | Parameter::FromString) , (Parameter::AllRequirements | Parameter::FromString)
& ~Parameter::TypeCheck & ~Parameter::TypeCheck
); );

View File

@ -109,8 +109,8 @@ namespace Cfg {
inline void setFlags ( int mask ); inline void setFlags ( int mask );
inline void unsetFlags ( int mask ); inline void unsetFlags ( int mask );
bool setString ( const std::string& bool setString ( const std::string&
, unsigned int flags =AllRequirements
, Priority priority=UseDefault , Priority priority=UseDefault
, unsigned int flags =AllRequirements
); );
bool setBool ( bool , Priority priority=UseDefault ); bool setBool ( bool , Priority priority=UseDefault );
bool setInt ( int , Priority priority=UseDefault ); bool setInt ( int , Priority priority=UseDefault );