⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 builder.hpp

📁 2009 ROBOCUP 仿真2DSERVER 源码
💻 HPP
📖 第 1 页 / 共 2 页
字号:
// -*-c++-*-/***************************************************************************                               builder.hpp                Interface for building config parameter                             -------------------    begin                : 14-MAY-2003    copyright            : (C) 2003 by The RoboCup Soccer Server                           Maintenance Group.    email                : sserver-admin@lists.sourceforge.net***************************************************************************//*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU LGPL as published by the Free Software  * *   Foundation; either version 2 of the License, or (at your option) any  * *   later version.                                                        * *                                                                         * ***************************************************************************/#ifndef BUILDER_HPP#define BUILDER_HPP#include "paramsetter.hpp"#include "paramgetter.hpp"#include <string>#include <list>#include <map>#include <iostream>namespace rcss {namespace conf {class StatusHandler;class Parser;class Builder {public:    Builder( const std::string & progname,             const std::string & version,             const std::string & module_name );    Builder( Builder * parent,             const std::string & version,             const std::string & module_name );    virtual    ~Builder();    template< typename V >    bool buildParam( const std::string & module_name,                     const std::string & param_name,                     V value,                     const std::string & name,                     int lineno );    void createConfFile( std::ostream & conf,                         const std::string & module_name );    void displayHelp();    /// removeHandler must be called before the handler is destroyed    void addHandler( StatusHandler & handler );    void removeHandler( StatusHandler & handler );    /// sets the specified parameter to the specified value    template< typename P >    bool set( const std::string & param,              P value )      {          return doBuildParam( param, value, "none", 0 );      }    /// gets the value of the specified parameter    template< typename P >    bool get( const std::string & param,              P & value ) const;    bool genericHelpRequested() const;    bool detailedHelpRequested() const;    Parser * parser();    template< typename V >    void addParam( const std::string & name,                   const Setter< V > & setter,                   const Getter< V > & getter,                   const std::string & desc )      {          addParam( name, ParamInfo< V >( setter, getter, desc ) );      }    template< typename V >    void addParam( const std::string & name,                   V & param,                   const std::string & desc )      {          addParam( name,                    makeSetter( param ),                    makeGetter( param ),                    desc );      }    const    std::string & getModuleName() const;    const    std::string & version() const;    const    std::string & parsedVersion() const;private:    friend class Parser;    friend class ParseErrorHandler;    void addChild( Builder & child );    void removeChild( Builder & child );    template< typename V >    void createConfFileEntry( std::ostream & conf,                              const std::string & module_name,                              const std::string & param_name,                              V value,                              const std::string & desc );    template< typename V >    void displayHelpEntry( std::ostream & out,                           const std::string & module_name,                           const std::string & param_name,                           V value,                           const std::string & desc );    void displayHelpEntry( std::ostream & out,                           const std::string & module_name,                           const std::string & param_name,                           const std::string & desc );    void displayHelpEntry( std::ostream & out,                           const std::string & param_name,                           const std::string & desc );    template< typename V >    void writeConfValue( std::ostream & conf,                         V value );    template< typename V >    void writeConfType( std::ostream & conf,                        V value );    void parseError( const std::string & curr,                     const std::string & err,                     const std::string & name,                     int lineno );    void buildError( const std::string & module,                     const std::string & param,                     const std::string & err,                     const std::string & name,                     int lineno );    void buildWarning( const std::string & module,                       const std::string & param,                       const std::string & warn,                       const std::string & name,                       int lineno );    void creatingConfFile( const std::string & conf_name );    void createdConfFile( const std::string & conf_name );    void confCreationFailed( const std::string & conf_name,                             int error );    void includeFailed( const std::string & filename,                        const std::string & error,                        const std::string & name,                        int lineno );    bool success() const;    void reset();    const    std::string & progName() const;    void requestGenericHelp();    void requestDetailedHelp();    void requestDetailedHelp( const std::string & module_name );    void requestDetailedHelpX( const char * begin,                               const char * end )      {          requestDetailedHelp( std::string( begin, end ) );      }    void addedToParser( Parser & p );    void removedFromParser();    // does not take ownership    Parser * m_parser;    std::list< StatusHandler * > m_handlers;    std::list< Builder * > m_children;    bool m_err;    std::string m_progname;    const std::string m_version;    std::string m_parsed_version;    Builder* m_parent;    bool m_generic_help_requested;    bool m_detailed_help_requested;    template< typename V >    class ParamInfo {    public:        ParamInfo( const Setter< V > & setter,                   const Getter< V > & getter,                   const std::string & desc )            : m_setter( setter ),              m_getter( getter ),              m_desc( desc )          { }        void set( V value )          {              m_setter( value );          }        V get() const          {              return m_getter();          }        const        std::string & desc() const          {              return m_desc;          }    private:        Setter< V > m_setter;        Getter< V > m_getter;        const std::string m_desc;    };    typedef std::map< std::string, ParamInfo< int > > IntMap;    typedef std::map< std::string, ParamInfo< bool > > BoolMap;    typedef std::map< std::string, ParamInfo< double > > DoubMap;    typedef std::map< std::string, ParamInfo< std::string > > StrMap;    virtual    void doRequestDetailedHelp( const std::string & module_name );    virtual    void displayUsage( const std::string & progname );    virtual    void displayGenericHelp();    virtual    void displayDetailedHelp();    virtual    bool doBuildParam( const std::string & module_name,                       const std::string & param_name,                       int value,                       const std::string & name,                       int lineno );    virtual    bool doBuildParam( const std::string & module_name,                       const std::string & param_name,                       bool value,                       const std::string & name,                       int lineno );    virtual    bool doBuildParam( const std::string & module_name,                       const std::string & param_name,                       double value,                       const std::string & name,                       int lineno );    virtual    bool doBuildParam( const std::string & module_name,                       const std::string & param_name,                       const std::string & value,                       const std::string & name,                       int lineno );    virtual    void doCreateConfFile( std::ostream & conf );    template< typename V >    void addParam( const std::string & name,                   const ParamInfo< V > & info );    bool doBuildParam( const std::string & param_name,                       int value,                       const std::string & name,                       int lineno );    bool doBuildParam( const std::string & param_name,                       bool value,                       const std::string & name,                       int lineno );    bool doBuildParam( const std::string & param_name,                       double value,                       const std::string & name,                       int lineno );    bool doBuildParam( const std::string & param_name,                       const std::string & value,                       const std::string & name,                       int lineno );    bool setParam( const std::string & param_name,                   ParamInfo< int > param,                   int value,                   const std::string & name,                   int lineno );    bool setParam( const std::string & param_name,                   ParamInfo< int > param,                   bool value,                   const std::string & name,                   int lineno );    bool setParam( const std::string & param_name,                   ParamInfo< int > param,                   double value,                   const std::string & name,                   int lineno );    bool setParam( const std::string & param_name,                   ParamInfo< int > param,                   const std::string & value,                   const std::string & name,                   int lineno );    bool setParam( const std::string & param_name,                   ParamInfo< bool > param,                   int value,                   const std::string & name,                   int lineno );    bool setParam( const std::string & param_name,                   ParamInfo< bool > param,                   bool value,                   const std::string & name,                   int lineno );    bool setParam( const std::string & param_name,                   ParamInfo< bool > param,                   double value,                   const std::string & name,                   int lineno );    bool setParam( const std::string & param_name,                   ParamInfo< bool > param,                   const std::string & value,                   const std::string & name,                   int lineno );    bool setParam( const std::string & param_name,                   ParamInfo< double > param,                   int value,                   const std::string & name,                   int lineno );    bool setParam( const std::string & param_name,                   ParamInfo< double > param,                   bool value,                   const std::string & name,                   int lineno );    bool setParam( const std::string & param_name,                   ParamInfo< double > param,                   double value,                   const std::string & name,                   int lineno );    bool setParam( const std::string & param_name,                   ParamInfo< double > param,                   const std::string & value,                   const std::string & name,                   int lineno );    bool setParam( const std::string & param_name,                   ParamInfo< std::string > param,                   int value,                   const std::string & name,                   int lineno );    bool setParam( const std::string & param_name,                   ParamInfo< std::string > param,                   bool value,                   const std::string & name,                   int lineno );    bool setParam( const std::string & param_name,                   ParamInfo< std::string > param,                   double value,                   const std::string & name,                   int lineno );    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<>inlineboolBuilder::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;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -