📄 builder.cpp
字号:
bool Builder::doBuildParam( const std::string& module_name, const std::string& param_name, double value, const std::string& name, int lineno ) { if( module_name == getModuleName() ) return doBuildParam( param_name, value, name, lineno ); return true; } bool Builder::doBuildParam( const std::string& module_name, const std::string& param_name, const std::string& value, const std::string& name, int lineno ) { if( module_name == getModuleName() ) return doBuildParam( param_name, value, name, lineno ); return true; } bool Builder::doBuildParam( const std::string& param_name, int value, const std::string& name, int lineno ) { IntMap::iterator int_iter = m_ints.find( param_name ); if( int_iter != m_ints.end() ) { return setParam( param_name, int_iter->second, value, name, lineno ); } BoolMap::iterator bool_iter = m_bools.find( param_name ); if( bool_iter != m_bools.end() ) { return setParam( param_name, bool_iter->second, value, name, lineno ); } DoubMap::iterator doub_iter = m_doubs.find( param_name ); if( doub_iter != m_doubs.end() ) { return setParam( param_name, doub_iter->second, value, name, lineno ); } StrMap::iterator str_iter = m_strs.find( param_name ); if( str_iter != m_strs.end() ) { return setParam( param_name, str_iter->second, value, name, lineno ); } buildError( m_module_name, param_name, "'" + m_module_name + "' has no parameter called '" + param_name + "'", name, lineno ); return false; } bool Builder::doBuildParam( const std::string& param_name, bool value, const std::string& name, int lineno ) { IntMap::iterator int_iter = m_ints.find( param_name ); if( int_iter != m_ints.end() ) { return setParam( param_name, int_iter->second, value, name, lineno ); } BoolMap::iterator bool_iter = m_bools.find( param_name ); if( bool_iter != m_bools.end() ) { return setParam( param_name, bool_iter->second, value, name, lineno ); } DoubMap::iterator doub_iter = m_doubs.find( param_name ); if( doub_iter != m_doubs.end() ) { return setParam( param_name, doub_iter->second, value, name, lineno ); } StrMap::iterator str_iter = m_strs.find( param_name ); if( str_iter != m_strs.end() ) { return setParam( param_name, str_iter->second, value, name, lineno ); } buildError( m_module_name, param_name, "'" + m_module_name + "' has no parameter called '" + param_name + "'", name, lineno ); return false; } bool Builder::doBuildParam( const std::string& param_name, double value, const std::string& name, int lineno ) { IntMap::iterator int_iter = m_ints.find( param_name ); if( int_iter != m_ints.end() ) { return setParam( param_name, int_iter->second, value, name, lineno ); } BoolMap::iterator bool_iter = m_bools.find( param_name ); if( bool_iter != m_bools.end() ) { return setParam( param_name, bool_iter->second, value, name, lineno ); } DoubMap::iterator doub_iter = m_doubs.find( param_name ); if( doub_iter != m_doubs.end() ) { return setParam( param_name, doub_iter->second, value, name, lineno ); } StrMap::iterator str_iter = m_strs.find( param_name ); if( str_iter != m_strs.end() ) { return setParam( param_name, str_iter->second, value, name, lineno ); } buildError( m_module_name, param_name, "'" + m_module_name + "' has no parameter called '" + param_name + "'", name, lineno ); return false; } bool Builder::doBuildParam( const std::string& param_name, const std::string& value, const std::string& name, int lineno ) { IntMap::iterator int_iter = m_ints.find( param_name ); if( int_iter != m_ints.end() ) { return setParam( param_name, int_iter->second, value, name, lineno ); } BoolMap::iterator bool_iter = m_bools.find( param_name ); if( bool_iter != m_bools.end() ) { return setParam( param_name, bool_iter->second, value, name, lineno ); } DoubMap::iterator doub_iter = m_doubs.find( param_name ); if( doub_iter != m_doubs.end() ) { return setParam( param_name, doub_iter->second, value, name, lineno ); } StrMap::iterator str_iter = m_strs.find( param_name ); if( str_iter != m_strs.end() ) { return setParam( param_name, str_iter->second, value, name, lineno ); } buildError( m_module_name, param_name, "'" + m_module_name + "' has no parameter called '" + param_name + "'", name, lineno ); return false; } void Builder::doCreateConfFile( std::ostream& conf ) { conf << "/* " << m_module_name << " Configuration file */\n\n"; for( IntMap::iterator iter = m_ints.begin(); iter != m_ints.end(); ++iter ) { createConfFileEntry( conf, m_module_name, iter->first, iter->second.get(), iter->second.desc() ); } for( BoolMap::iterator iter = m_bools.begin(); iter != m_bools.end(); ++iter ) { createConfFileEntry( conf, m_module_name, iter->first, iter->second.get(), iter->second.desc() ); } for( DoubMap::iterator iter = m_doubs.begin(); iter != m_doubs.end(); ++iter ) { createConfFileEntry( conf, m_module_name, iter->first, iter->second.get(), iter->second.desc() ); } for( StrMap::iterator iter = m_strs.begin(); iter != m_strs.end(); ++iter ) { createConfFileEntry( conf, m_module_name, iter->first, iter->second.get(), iter->second.desc() ); } }// template<>// bool// Builder::get< int >( const std::string& param,// int& value ) const// {// IntMap::const_iterator i = m_ints.find( param );// if( i == m_ints.end() )// return false; // value = i->second.get();// return true;// } // template<>// bool// Builder::get< bool >( const std::string& param,// bool& value ) const// {// BoolMap::const_iterator i = m_bools.find( param );// if( i == m_bools.end() )// return false;// value = i->second.get();// return true;// } // template<>// bool// Builder::get< double >( const std::string& param,// double& value ) const// {// DoubMap::const_iterator i = m_doubs.find( param );// if( i == m_doubs.end() )// return false;// value = i->second.get();// return true;// } // template<>// bool// Builder::get< std::string >( const std::string& param,// std::string& value ) const// {// StrMap::const_iterator i = m_strs.find( param );// if( i == m_strs.end() )// return false;// value = i->second.get();// return true;// }// template<>// void// Builder::addParam< int >( const std::string& name, // const ParamInfo< int >& info )// {// m_ints.insert( std::make_pair( name, info ) );// } // template<>// void// Builder::addParam< bool >( const std::string& name, // const ParamInfo< bool >& info )// {// m_bools.insert( std::make_pair( name, info ) );// } // template<>// void// Builder::addParam< double >( const std::string& name, // const ParamInfo< double >& info )// {// m_doubs.insert( std::make_pair( name, info ) );// } // template<>// void// Builder::addParam< std::string >( const std::string& name, // const ParamInfo< std::string >& info )// {// m_strs.insert( std::make_pair( name, info ) );// } bool Builder::setParam( const std::string&, ParamInfo< int > param, int value, const std::string&, int ) { param.set( value ); return true; } bool Builder::setParam( const std::string& param_name, ParamInfo< bool > param, int value, const std::string& name, int lineno ) { param.set( (bool)value ); if( value != 0 && value != 1 ) buildWarning( m_module_name, param_name, "casting from int to bool for parameter '" + param_name + "'", name, lineno ); return true; } bool Builder::setParam( const std::string&, ParamInfo< double > param, int value, const std::string&, int ) { param.set( value ); return true; } bool Builder::setParam( const std::string& param_name, ParamInfo< std::string >, int, const std::string& name, int lineno ) { buildError( m_module_name, param_name, "'" + m_module_name + "' has no numeric parameter called '" + param_name + "'", name, lineno ); return false; } bool Builder::setParam( const std::string& param_name, ParamInfo< int >, bool, const std::string& name, int lineno ) { buildError( m_module_name, param_name, "'" + m_module_name + "' has no boolean parameter called '" + param_name + "'", name, lineno ); return false; } bool Builder::setParam( const std::string&, ParamInfo< bool > param, bool value, const std::string&, int ) { param.set( value ); return true; } bool Builder::setParam( const std::string& param_name, ParamInfo< double >, bool, const std::string& name, int lineno ) { buildError( m_module_name, param_name, "'" + m_module_name + "' has no boolean parameter called '" + param_name + "'", name, lineno ); return false; } bool Builder::setParam( const std::string& param_name, ParamInfo< std::string >, bool, const std::string& name, int lineno ) { buildError( m_module_name, param_name, "'" + m_module_name + "' has no boolean parameter called '" + param_name + "'", name, lineno ); return false; } bool Builder::setParam( const std::string& param_name, ParamInfo< int > param, double value, const std::string& name, int lineno ) { param.set( (int)value ); if( value != (int)value ) buildWarning( m_module_name, param_name, "casting from floating point to integer for parameter '" + param_name + "'", name, lineno ); return false; } bool Builder::setParam( const std::string& param_name, ParamInfo< bool > param, double value, const std::string& name, int lineno ) { param.set( (bool)value ); if( value != 0 && value != 1 ) buildWarning( m_module_name, param_name, "casting from floating point to bool for parameter '" + param_name + "'", name, lineno ); return false; } bool Builder::setParam( const std::string&, ParamInfo< double > param, double value, const std::string&, int ) { param.set( value ); return true; } bool Builder::setParam( const std::string& param_name, ParamInfo< std::string >, double, const std::string& name, int lineno ) { buildError( m_module_name, param_name, "'" + m_module_name + "' has no numeric parameter called '" + param_name + "'", name, lineno ); return false; } bool Builder::setParam( const std::string& param_name, ParamInfo< int >, const std::string& value, const std::string& name, int lineno ) { buildError( m_module_name, param_name, "'" + m_module_name + "' has no string parameter (" + value + ") called '" + param_name + "'", name, lineno ); return false; } bool Builder::setParam( const std::string& param_name, ParamInfo< bool >, const std::string&, const std::string& name, int lineno ) { buildError( m_module_name, param_name, "'" + m_module_name + "' has no string parameter called '" + param_name + "'", name, lineno ); return false; } bool Builder::setParam( const std::string& param_name, ParamInfo< double >, const std::string&, const std::string& name, int lineno ) { buildError( m_module_name, param_name, "'" + m_module_name + "' has no string parameter called '" + param_name + "'", name, lineno ); return false; } bool Builder::setParam( const std::string&, ParamInfo< std::string > param, const std::string& value, const std::string&, int ) { param.set( value ); return true; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -