当前位置: 首页>>代码示例>>C++>>正文


C++ CmdLineParser类代码示例

本文整理汇总了C++中CmdLineParser的典型用法代码示例。如果您正苦于以下问题:C++ CmdLineParser类的具体用法?C++ CmdLineParser怎么用?C++ CmdLineParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CmdLineParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: param_map

/*!

 */
bool
Strategy::init( CmdLineParser & cmd_parser )
{
    ParamMap param_map( "HELIOS_base options" );

    // std::string fconf;
    //param_map.add()
    //    ( "fconf", "", &fconf, "another formation file." );

    //
    //
    //

    if ( cmd_parser.count( "help" ) > 0 )
    {
        param_map.printHelp( std::cout );
        return false;
    }

    //
    //
    //

    cmd_parser.parse( param_map );

    return true;
}
开发者ID:Aanal,项目名称:RobosoccerAttack-Athena,代码行数:30,代码来源:strategy.cpp

示例2: fprintf

// Parses options specified in the first line of the file with 'filename'.
// Returns: success?
// On success, public member variables shall contain interpreted program
// parameters.
bool Options::ParseConfigFile(string filename, bool validate /* = true */) {
	// avoid endless recursion!
	//printf("Parsing: '%s'...\n", filename.c_str());
	if (parsedConfigFiles.find(filename) != parsedConfigFiles.end()) {
		fprintf(stderr, "Cyclic list of configuration files is not allowed!\nStopping at file named: '%s'.\n", filename.c_str());
		return true;
	}

	const int MAX_LINE_LEN = 1024;
	char line[MAX_LINE_LEN+1] = {0};

	FILE* in = fopen(filename.c_str(), "r+t");
	if (!in) {
		fprintf(stderr, "Failed to open config file named: '%s'.\n", filename.c_str());
		return false;
	}
	fgets(line, MAX_LINE_LEN, in);
	fclose(in);

	// add this file to read config files set
	parsedConfigFiles.insert(filename);

	CmdLineParser cmdline = cmdline_prototype;
	if (!cmdline.Parse(line, true)) {
		fprintf(stderr, "Syntax error in config file: '%s'. \n", filename.c_str());
		return false;
	}
	Store(cmdline);

	return validate ? Validate() : true;
}
开发者ID:nadezhdin-ivan,项目名称:shdt,代码行数:35,代码来源:main.cpp

示例3:

/*!

 */
bool
SampleTrainer::initImpl( CmdLineParser & cmd_parser )
{
    bool result = TrainerAgent::initImpl( cmd_parser );

#if 0
    ParamMap my_params;

    std::string formation_conf;
    my_map.add()
        ( &conf_path, "fconf" )
        ;

    cmd_parser.parse( my_params );
#endif

    if ( cmd_parser.failed() )
    {
        std::cerr << "coach: ***WARNING*** detected unsupported options: ";
        cmd_parser.print( std::cerr );
        std::cerr << std::endl;
    }

    if ( ! result )
    {
        return false;
    }

    //////////////////////////////////////////////////////////////////
    // Add your code here.
    //////////////////////////////////////////////////////////////////

    return true;
}
开发者ID:Aanal,项目名称:RobosoccerAttack-Athena,代码行数:37,代码来源:sample_trainer.cpp

示例4: main

int main(int argc, char* argv[]) {
  CmdLineParser cmdp;
  if (false == cmdp.parse_cmd_line(argc, argv)) {
    cerr << "    error: " << cmdp.last_error << "\n";
    cmdp.print_help();
  } else {
    BaseCompressor* zip = cmdp.compression == CmdLineParser:: COMPR_HAFFMAN ?
      (BaseCompressor*) new Haffman() : (BaseCompressor*) new LZW();
    try {
      switch (cmdp.action) {
      case (CmdLineParser::ACT_COMPRESSION): {
        zip->compress(cmdp.files);
      } break;
      case (CmdLineParser::ACT_DECOMPRESSION): {
        zip->decompress(cmdp.files[0]);
      } break;
      case (CmdLineParser::ACT_PRINT_HELP):{
        cmdp.print_help();
      }
      }
    }
    catch (Error& e) {
      std::cerr << e.message();
    }
  }

  return 0;
}
开发者ID:vkevroletin,项目名称:Moroz,代码行数:28,代码来源:main.cpp

示例5: main

int main(int argc, char** argv)
{
   cout << SectorVersionString << endl;

   SlaveConf global_conf;

   CmdLineParser clp;
   clp.parse(argc, argv);

   for (map<string, string>::const_iterator i = clp.m_mDFlags.begin(); i != clp.m_mDFlags.end(); ++ i)
   {
      if (i->first == "mh")
         global_conf.m_strMasterHost = i->second;
      else if (i->first == "mp")
         global_conf.m_iMasterPort = atoi(i->second.c_str());
      else if (i->first == "h")
      {
         global_conf.m_strHomeDir = i->second;
      }
      else if (i->first == "ds")
         global_conf.m_llMaxDataSize = atoll(i->second.c_str()) * 1024 * 1024;
      else if (i->first == "log")
         global_conf.m_iLogLevel = atoi(i->second.c_str());
      else
      {
         cout << "warning: unrecognized flag " << i->first << endl;
         help();
      }
   }

   string base = "";
   if (clp.m_vParams.size() == 1)
      base = clp.m_vParams.front();
   else if (clp.m_vParams.size() > 1)
      cout << "warning: wrong parameters ignored.\n";

   Slave s;

   if (s.init(&base, &global_conf) < 0)
   {
      cout << "error: failed to initialize the slave. check slave configurations.\n";
      return-1;
   }

   if (s.connect() < 0)
   {
      cout << "error: failed to connect to the master, or the connection request is rejected.\n";
      return -1;
   }

   s.run();

   s.close();

   return 0;
}
开发者ID:norouzi4d,项目名称:sector,代码行数:56,代码来源:start_slave.cpp

示例6: get_cmd_line_parser

 /**
  * Creates a command line parser initialized with default values.
  * @return a command line parser initialized with default values.
  */
 CmdLineParser get_cmd_line_parser() {
   CmdLineParser parser;
   parser.add_legal("-h --help -L --list -v --verbose -V --version -a --all -f --conformity --conformity-format --max-time");
   const int argc = 3;
   const char *defaults[argc] = {
     "--conformity-format=*Test|test_*|*",
     "-f=%p::%n - %m (%ts)%N(Registered at %f:%l)",
     "--max-time=1e+10",
   };
   parser.parse(argc, defaults);
   CPUNIT_ITRACE("EntryPoint - Default arguments:"<<parser.to_string());
   return parser;
 }
开发者ID:JioCloudCompute,项目名称:jcs_cpp_sdk,代码行数:17,代码来源:cpunit_EntryPoint.cpp

示例7: parseCommandLine

bool parseCommandLine(int argc, char **argv, CmdLineParser &clp, ConfigInput &config)
{
  if(!clp.parseCmdLine(argc, argv))
  {
    clp.printUsage();
    return false;
  }

  config.listenPort = ((CmdLineOptionInt*)  clp.getCmdLineOption(ARG_LISTEN_PORT))->getValue();
  config.isVerbose =  ((CmdLineOptionFlag*) clp.getCmdLineOption(ARG_VERBOSE))->getValue();

  return true;
}
开发者ID:KerryLiang,项目名称:SocketServer,代码行数:13,代码来源:exampleMainTcp.cpp

示例8: main

  /**
   * If you have extra command line parameters, you may use this method to start CPUnit
   * after you have done your own. You should use {@link #get_cmd_line_parser()} to obtain
   * a parser which is already set up to accept the CPUnit specific command line parameters,
   * and then use CmdLineParser.add_legal to specify the arguments you expect in addition.
   * 
   * @param parser A parser contaiing the command line arguments, excluding the program name.
   *               I.e. from main(int& argc,char** args), the parser would be called as
   *               {@link CmdLineParser#parse(const int, const char**) parser.parse(arcg-1,args+1)}.
   * @return 0 if all tests succeed, and >0 elsewise.
  */
  int main(const CmdLineParser &parser) {

    AutoDisposer ad;
    try {
      CPUNIT_ITRACE("EntryPoint - Actual arguments:"<<parser.to_string());

      std::vector<std::string> patterns = parser.program_input();
      if (patterns.size() == 0) { 
	patterns.push_back("*");
      }
      
      if(parser.has_one_of("-h --help")) {
	usage();
	return 0;
      }
      if(parser.has_one_of("-L --list")) {
	list_tests(patterns);
	return 0;
      }
      if(parser.has_one_of("-V --version")) {
	print_version_info();
	return 0;
      }
      
      const bool verbose    = parser.has("-v") || parser.has("--verbose");
      const bool robust     = parser.has("-a") || parser.has("--all");
      const bool conformity = parser.has("--conformity");
      
      CPUNIT_ITRACE("EntryPoint - verbose="<<verbose<<" robust="<<robust<<" conformity="<<conformity);
      
      bool conform = true;
      if (conformity) {
	std::vector<std::string> conf_patterns = get_conformity_format(parser);
	const int num_conformity_breaches = conformity_report(patterns, conf_patterns[0], conf_patterns[1], conf_patterns[2], verbose, std::cout);
	std::cout<<"There where "<<num_conformity_breaches<<" conformity breaches."<<std::endl;
	conform = num_conformity_breaches == 0;
      }

      const std::string report_format = parser.value_of<std::string>(error_format_token);
      const double max_time = parser.value_of<double>(max_time_token);
      const std::vector<cpunit::ExecutionReport> result = cpunit::TestExecutionFacade().execute(patterns, max_time, verbose, robust);
      bool all_well = report_result(result, report_format, std::cout);
      
      int exit_value = 0;
      if (!all_well) {
	exit_value |= 0x1;
      }
      if(!conform) {
	exit_value |= 0x2;
      }
      return exit_value;
    } catch (AssertionException &e) {
      std::cout<<"Terminated due to AssertionException: "<<std::endl<<e.what()<<std::endl;
      return 1;
    }
  }
开发者ID:JioCloudCompute,项目名称:jcs_cpp_sdk,代码行数:67,代码来源:cpunit_EntryPoint.cpp

示例9: my_params

/*!

 */
bool
SamplePlayer::initImpl( CmdLineParser & cmd_parser )
{
    bool result = PlayerAgent::initImpl( cmd_parser );

    // read additional options
    result &= Strategy::instance().init( cmd_parser );

    rcsc::ParamMap my_params( "Additional options" );
#if 0
    std::string param_file_path = "params";
    param_map.add()
    ( "param-file", "", &param_file_path, "specified parameter file" );
#endif

    cmd_parser.parse( my_params );

    if ( cmd_parser.count( "help" ) > 0 )
    {
        my_params.printHelp( std::cout );
        return false;
    }

    if ( cmd_parser.failed() )
    {
        std::cerr << "player: ***WARNING*** detected unsuppprted options: ";
        cmd_parser.print( std::cerr );
        std::cerr << std::endl;
    }

    if ( ! result )
    {
        return false;
    }

    if ( ! Strategy::instance().read( config().configDir() ) )
    {
        std::cerr << "***ERROR*** Failed to read team strategy." << std::endl;
        return false;
    }

    if ( KickTable::instance().read( config().configDir() + "/kick-table" ) )
    {
        std::cerr << "Loaded the kick table: ["
                  << config().configDir() << "/kick-table]"
                  << std::endl;
    }

    return true;
}
开发者ID:4SkyNet,项目名称:HFO,代码行数:53,代码来源:sample_player.cpp

示例10: main

int main(int argc, char** argv)
{
   cout << SectorVersionString << endl;

   Sector client;
   if (Utility::login(client) < 0)
      return -1;

   bool address = false;

   CmdLineParser clp;
   if (clp.parse(argc, argv) < 0)
   {
      help();
      return -1;
   }

   for (map<string, string>::const_iterator i = clp.m_mDFlags.begin(); i != clp.m_mDFlags.end(); ++ i)
   {
      if (i->first == "a")
         address = true;
      else
      {
         help();
         return -1;
      }
   }

   for (vector<string>::const_iterator i = clp.m_vSFlags.begin(); i != clp.m_vSFlags.end(); ++ i)
   {
      if (*i == "a")
         address = true;
      else
      {
         help();
         return -1;
      }
   }

   SysStat sys;
   int result = client.sysinfo(sys);
   if (result >= 0)
      print(sys, address);
   else
      Utility::print_error(result);

   Utility::logout(client);

   return result;
}
开发者ID:norouzi4d,项目名称:sector,代码行数:50,代码来源:sysinfo.cpp

示例11: loadCmdLine

void loadCmdLine(CmdLineParser &clp)
{
  clp.setMainHelpText("A simple Echo Server");

  // All options are optional
     // Number of Threads
  clp.addCmdLineOption(new CmdLineOptionInt(ARG_LISTEN_PORT,
                                            string("TCP port to listen on"),
                                            3868));
     // Verbosity
  clp.addCmdLineOption(new CmdLineOptionFlag(ARG_VERBOSE,
                                             string("Turn on verbosity"),
                                             false));
}
开发者ID:KerryLiang,项目名称:SocketServer,代码行数:14,代码来源:exampleMainTcp.cpp

示例12: main

int main(int argc, char** argv)
{
   string sector_home;
   if (ConfLocation::locate(sector_home) < 0)
   {
      cerr << "no Sector information located; nothing to stop.\n";
      return -1;
   }

   string slaves_list = sector_home + "/conf/slaves.list";
   bool force = false;

   CmdLineParser clp;
   clp.parse(argc, argv);
   for (map<string, string>::const_iterator i = clp.m_mDFlags.begin(); i != clp.m_mDFlags.end(); ++ i)
   {
      if (i->first == "s")
         slaves_list = i->second;
      else
      {
         help();
         return 0;
      }
   }
   for (vector<string>::const_iterator i = clp.m_vSFlags.begin(); i != clp.m_vSFlags.end(); ++ i)
   {
      if ((*i == "f") || (*i == "force"))
         force = true;
      else
      {
         help();
         return 0;
      }
   }

   cout << "This will stop this master and all slave nodes by brutal forces. If you need a graceful shutdown, use ./tools/sector_shutdown.\n";

   if (!force)
   {
      cout << "Do you want to continue? Y/N:";
      char answer;
      cin >> answer;
      if ((answer != 'Y') && (answer != 'y'))
      {
         cout << "aborted.\n";
         return -1;
      }
   }
开发者ID:norouzi4d,项目名称:sector,代码行数:48,代码来源:stop_all.cpp

示例13: synchronizeDocs

bool synchronizeDocs(QHelpEngineCore &collection,
                     QHelpEngineCore &cachedCollection,
                     CmdLineParser &cmd)
{
    TRACE_OBJ
    const QDateTime &lastCollectionRegisterTime =
        CollectionConfiguration::lastRegisterTime(collection);
    if (!lastCollectionRegisterTime.isValid() || lastCollectionRegisterTime
        < CollectionConfiguration::lastRegisterTime(cachedCollection))
        return true;

    const QStringList &docs = collection.registeredDocumentations();
    const QStringList &cachedDocs = cachedCollection.registeredDocumentations();

    /*
     * Ensure that the cached collection contains all docs that
     * the collection contains.
     */
    foreach (const QString &doc, docs) {
        if (!cachedDocs.contains(doc)) {
            const QString &docFile = collection.documentationFileName(doc);
            if (!cachedCollection.registerDocumentation(docFile)) {
                cmd.showMessage(QCoreApplication::translate("Assistant",
                                    "Error registering documentation file '%1': %2").
                                arg(docFile).arg(cachedCollection.error()), true);
                return false;
            }
        }
    }

    CollectionConfiguration::updateLastRegisterTime(cachedCollection);

    return true;
}
开发者ID:Drakey83,项目名称:steamlink-sdk,代码行数:34,代码来源:main.cpp

示例14: main

int main(int argc, char** argv)
{
   CmdLineParser clp;
   if (clp.parse(argc, argv) <= 0)
   {
      help();
      return -1;
   }

   int32_t id = 0;
   string addr;
   int32_t code = 0;
   for (map<string, string>::iterator i = clp.m_mDFlags.begin(); i != clp.m_mDFlags.end(); ++ i)
   {
      if (i->first == "i")
         id = atoi(i->second.c_str());
      else if (i->first == "d")
         addr = i->second;
      else if (i->first == "c")
         code = atoi(i->second.c_str());
      else
      {
         help();
         return -1;
      }
   }

   if (((id == 0) && (addr.c_str()[0] == 0))|| (code == 0))
   {
      help();
      return -1;
   }

   Session s;
   s.loadInfo("../conf/client.conf");

   Client c;
   if (c.init(s.m_ClientConf.m_strMasterIP, s.m_ClientConf.m_iMasterPort) < 0)
      return -1;

   string passwd = s.m_ClientConf.m_strPassword;
   if (s.m_ClientConf.m_strUserName != "root")
   {
      cout << "please input root password:";
      cin >> passwd;
   }
开发者ID:deniskin82,项目名称:sector-sphere,代码行数:46,代码来源:send_dbg_cmd.cpp

示例15: config

/*!

 */
bool
SampleCoach::initImpl( CmdLineParser & cmd_parser )
{
    bool result =CoachAgent::initImpl( cmd_parser );

#if 0
    ParamMap my_params;
    if ( cmd_parser.count( "help" ) )
    {
       my_params.printHelp( std::cout );
       return false;
    }
    cmd_parser.parse( my_params );
#endif

    if ( cmd_parser.failed() )
    {
        std::cerr << "coach: ***WARNING*** detected unsupported options: ";
        cmd_parser.print( std::cerr );
        std::cerr << std::endl;
    }

    if ( ! result )
    {
        return false;
    }

    //////////////////////////////////////////////////////////////////
    // Add your code here.
    //////////////////////////////////////////////////////////////////

    if ( config().useTeamGraphic() )
    {
        if ( config().teamGraphicFile().empty() )
        {
            M_team_graphic.createXpmTiles( team_logo_xpm );
        }
        else
        {
            M_team_graphic.readXpmFile( config().teamGraphicFile().c_str() );
        }
    }

    return true;
}
开发者ID:UNiQ10,项目名称:HFO,代码行数:48,代码来源:sample_coach.cpp


注:本文中的CmdLineParser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。