📄 builder.hpp
字号:
ParamInfo< double > param, bool value, const std::string& name, int lineno ); RCSSBASE_API bool setParam( const std::string& param_name, ParamInfo< double > param, double value, const std::string& name, int lineno ); RCSSBASE_API bool setParam( const std::string& param_name, ParamInfo< double > param, const std::string& value, const std::string& name, int lineno ); RCSSBASE_API bool setParam( const std::string& param_name, ParamInfo< std::string > param, int value, const std::string& name, int lineno ); RCSSBASE_API bool setParam( const std::string& param_name, ParamInfo< std::string > param, bool value, const std::string& name, int lineno ); RCSSBASE_API bool setParam( const std::string& param_name, ParamInfo< std::string > param, double value, const std::string& name, int lineno ); RCSSBASE_API bool setParam( const std::string& param_name, ParamInfo< std::string > param, const std::string& value, const std::string& name, int lineno ); const std::string m_module_name; IntMap m_ints; BoolMap m_bools; DoubMap m_doubs; StrMap m_strs; }; template<> inline// RCSSBASE_API 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<> inline// RCSSBASE_API 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<> inline// RCSSBASE_API 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<> inline// RCSSBASE_API 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<> inline// RCSSBASE_API void Builder::addParam< int >( const std::string& name, const ParamInfo< int >& info ) { m_ints.insert( std::make_pair( name, info ) ); } template<> inline// RCSSBASE_API void Builder::addParam< bool >( const std::string& name, const ParamInfo< bool >& info ) { m_bools.insert( std::make_pair( name, info ) ); } template<> inline// RCSSBASE_API void Builder::addParam< double >( const std::string& name, const ParamInfo< double >& info ) { m_doubs.insert( std::make_pair( name, info ) ); } template<> inline// RCSSBASE_API void Builder::addParam< std::string >( const std::string& name, const ParamInfo< std::string >& info ) { m_strs.insert( std::make_pair( name, info ) ); } template< typename V > inline bool Builder::buildParam( const std::string& module_name, const std::string& param_name, V value, const std::string& name, int lineno ) { bool rval = doBuildParam( module_name, param_name, value, name, lineno ); for( std::list< Builder* >::iterator i = m_children.begin(); i != m_children.end(); ++i ) { rval = (*i)->buildParam( module_name, param_name, value, name, lineno ) && rval; } return rval; } template< typename V > inline void Builder::createConfFileEntry( std::ostream& conf, const std::string& module_name, const std::string& param_name, V value, const std::string& desc ) { conf << "# " << module_name << "::" << param_name << std::endl; if( !desc.empty() ) { conf << "/* "; int count = 3; std::string::const_iterator start = desc.begin(); std::string::const_iterator end = desc.begin(); for( std::string::const_iterator i = desc.begin(); i != desc.end(); ++i, ++count ) { switch( *i ) { case '\n': end = i; conf << std::string( start, end ) << std::endl; count = 0; start = end = i+1; break; case ' ': case '\t': end = i; break; default: if( count > 70 ) { conf << std::string( start, end ) << std::endl; for( std::string::const_iterator j = end; j != i; ++j ) { if( *j == ' ' || *j == '\t' ) ++end; else break; } count = std::distance( end, i ); start = end; } break; } } conf << std::string( start, desc.end() ) << " */\n"; } conf << module_name << "::" << param_name << " = "; writeConfValue( conf, value ); conf << std::endl << std::endl; } template< typename V > inline void Builder::displayHelpEntry( std::ostream& conf, const std::string& module_name, const std::string& param_name, V value, const std::string& desc ) { conf << "\t" << module_name << "::" << param_name << "="; writeConfType( conf, value ); conf << std::endl; if( !desc.empty() ) { conf << "\t\t"; int count = 3; std::string::const_iterator start = desc.begin(); std::string::const_iterator end = desc.begin(); for( std::string::const_iterator i = desc.begin(); i != desc.end(); ++i, ++count ) { switch( *i ) { case '\n': end = i; conf << std::string( start, end ) << std::endl << "\t\t"; count = 0; start = end = i+1; break; case ' ': case '\t': end = i; break; default: if( count > 62 ) { conf << std::string( start, end ) << std::endl << "\t\t"; for( std::string::const_iterator j = end; j != i; ++j ) { if( *j == ' ' || *j == '\t' ) ++end; else break; } count = std::distance( end, i ); start = end; } break; } } conf << std::string( start, desc.end() ) << "\n\n"; } conf << "\t\tcurrent value: "; writeConfValue( conf, value ); conf << std::endl << std::endl; } inline void Builder::displayHelpEntry( std::ostream& strm, const std::string& module_name, const std::string& param_name, const std::string& desc ) { strm << "\t" << module_name << "::" << param_name; strm << std::endl; if( !desc.empty() ) { strm << "\t\t"; int count = 3; std::string::const_iterator start = desc.begin(); std::string::const_iterator end = desc.begin(); for( std::string::const_iterator i = desc.begin(); i != desc.end(); ++i, ++count ) { switch( *i ) { case '\n': end = i; strm << std::string( start, end ) << std::endl << "\t\t"; count = 0; start = end = i+1; break; case ' ': case '\t': end = i; break; default: if( count > 62 ) { strm << std::string( start, end ) << std::endl << "\t\t"; for( std::string::const_iterator j = end; j != i; ++j ) { if( *j == ' ' || *j == '\t' ) ++end; else break; } count = std::distance( end, i ); start = end; } break; } } strm << std::string( start, desc.end() ) << "\n\n"; } } inline void Builder::displayHelpEntry( std::ostream& conf, const std::string& param_name, const std::string& desc ) { conf << "\t" << param_name; conf << std::endl;; if( !desc.empty() ) { conf << "\t\t"; int count = 3; std::string::const_iterator start = desc.begin(); std::string::const_iterator end = desc.begin(); for( std::string::const_iterator i = desc.begin(); i != desc.end(); ++i, ++count ) { switch( *i ) { case '\n': end = i; conf << std::string( start, end ) << std::endl << "\t\t"; count = 0; start = end = i+1; break; case ' ': case '\t': end = i; break; default: if( count > 62 ) { conf << std::string( start, end ) << std::endl << "\t\t"; for( std::string::const_iterator j = end; j != i; ++j ) { if( *j == ' ' || *j == '\t' ) ++end; else break; } count = std::distance( end, i ); start = end; } break; } } conf << std::string( start, desc.end() ) << "\n\n"; conf.flush(); } } template< typename V > inline void Builder::writeConfValue( std::ostream& conf, V value ) { conf << value; } template<> inline void Builder::writeConfValue< bool >( std::ostream& conf, bool value ) { if( value ) conf << "true"; else conf << "false"; } template<> inline void Builder::writeConfValue< const bool& >( std::ostream& conf, const bool& value ) { if( value ) conf << "true"; else conf << "false"; } template<> inline void Builder::writeConfValue< const std::string& >( std::ostream& conf, const std::string& value ) { conf << '\'' << value << '\''; } template<> inline void Builder::writeConfValue< std::string >( std::ostream& conf, std::string value ) { conf << '\'' << value << '\''; } template< typename V > inline void Builder::writeConfType( std::ostream& conf, V value ) { conf << "<VALUE>"; } template<> inline void Builder::writeConfType< bool >( std::ostream& conf, bool ) { conf << "<on|off|true|false|1|0|>"; } template<> inline void Builder::writeConfType< int >( std::ostream& conf, int ) { conf << "<INTEGER>"; } template<> inline void Builder::writeConfType< double >( std::ostream& conf, double ) { conf << "<REAL>"; } template<> inline void Builder::writeConfType< const std::string& >( std::ostream& conf, const std::string& ) { conf << "'<STRING>'"; } template<> inline void Builder::writeConfType< std::string >( std::ostream& conf, std::string ) { conf << "'<STRING>'"; } }}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -