📄 builder.hpp
字号:
template<>inlineboolBuilder::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<>inlineboolBuilder::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<>inlineboolBuilder::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<>inlinevoidBuilder::addParam< int >( const std::string & name, const ParamInfo< int > & info ){ m_ints.insert( std::make_pair( name, info ) );}template<>inlinevoidBuilder::addParam< bool >( const std::string & name, const ParamInfo< bool > & info ){ m_bools.insert( std::make_pair( name, info ) );}template<>inlinevoidBuilder::addParam< double >( const std::string & name, const ParamInfo< double > & info ){ m_doubs.insert( std::make_pair( name, info ) );}template<>inlinevoidBuilder::addParam< std::string >( const std::string & name, const ParamInfo< std::string > & info ){ m_strs.insert( std::make_pair( name, info ) );}template< typename V >inlineboolBuilder::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 >inlinevoidBuilder::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 >inlinevoidBuilder::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;}inlinevoidBuilder::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"; }}inlinevoidBuilder::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 >inlinevoidBuilder::writeConfValue( std::ostream & conf, V value ){ conf << value;}template<>inlinevoidBuilder::writeConfValue< bool >( std::ostream & conf, bool value ){ if ( value ) { conf << "true"; } else { conf << "false"; }}template<>inlinevoidBuilder::writeConfValue< const bool& >( std::ostream & conf, const bool & value ){ if ( value ) { conf << "true"; } else { conf << "false"; }}template<>inlinevoidBuilder::writeConfValue< const std::string & >( std::ostream & conf, const std::string & value ){ conf << '\'' << value << '\'';}template<>inlinevoidBuilder::writeConfValue< std::string >( std::ostream & conf, std::string value ){ conf << '\'' << value << '\'';}template< typename V >inlinevoidBuilder::writeConfType( std::ostream & conf, V value ){ conf << "<VALUE>";}template<>inlinevoidBuilder::writeConfType< bool >( std::ostream & conf, bool ){ conf << "<on|off|true|false|1|0|>";}template<>inlinevoidBuilder::writeConfType< int >( std::ostream & conf, int ){ conf << "<INTEGER>";}template<>inlinevoidBuilder::writeConfType< double >( std::ostream& conf, double ){ conf << "<REAL>";}template<>inlinevoidBuilder::writeConfType< const std::string & >( std::ostream & conf, const std::string & ){ conf << "'<STRING>'";}template<>inlinevoidBuilder::writeConfType< std::string >( std::ostream & conf, std::string ){ conf << "'<STRING>'";}}}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -