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

📄 argumentparser.h

📁 Amis - A maximum entropy estimator 一个最大熵模型统计工具
💻 H
字号:
////////////////////////////////////////////////////////////////////////////  Copyright (c) 2000, Yusuke Miyao///  You may distribute under the terms of the Artistic License.//////  <id>$Id: ArgumentParser.h,v 1.2 2003/05/11 18:12:09 yusuke Exp $</id>///  <collection>Maximum Entropy Estimator</collection>///  <name>ArgumentParser.h</name>///  <overview>Parsing command-line arguments</overview>/////////////////////////////////////////////////////////////////////////#ifndef Amis_ArgumentParser_h_#define Amis_ArgumentParser_h_#include <amis/configure.h>#include <amis/ErrorBase.h>AMIS_NAMESPACE_BEGIN///////////////////////////////////////////////////////////////////////// <classdef>/// <name>IllegalArgumentError</name>/// <overview>Exception for illegal arguments</overview>/// <desc>/// The error is thrown when an illegal argument is specified to the program./// </desc>/// <body>class IllegalArgumentError : public ErrorBase { public:  IllegalArgumentError( const std::string& m ) : ErrorBase( m ) {}  /// Initialize with an error message  IllegalArgumentError( const char* m ) : ErrorBase( m ) {}  /// Initialize with an error message};/// </body>/// </classdef>///////////////////////////////////////////////////////////////////////// <classdef>/// <name>ArgumentParser</name>/// <overview>Parse command-line arguments</overview>/// <desc>A parser for command-line arguments</desc>/// <body>class ArgumentParser {private:  int argc;  const char** argv;  int i;public:  ArgumentParser( int c, const char** v ) {    argc = c;    argv = v;    i = 1;  }  virtual ~ArgumentParser() {}  bool empty( void ) {    return i == argc;  }  std::string nextArgument( const std::string& message ) {    if ( i < argc ) {      return argv[ i++ ];    } else {      throw IllegalArgumentError( message );    }  }    void windBack() {	  if ( i != 1 ) {		  i--;	  }  }    int nextArgumentInteger( const std::string& message ) {    if ( i < argc ) {      char* end_ptr;	  int num = static_cast< int >( strtol( argv[ i++ ], &end_ptr, 0 ) );	  if ( *end_ptr != '\0' ) {		  throw IllegalArgumentError( message );	  }	  return num;	} else {		throw IllegalArgumentError( message );	}  }    double nextArgumentDouble( const std::string& message ) {	  if ( i < argc ) {		  char* end_ptr;		  double num = static_cast< double >( strtod( argv[ i++ ], &end_ptr) );		  if ( *end_ptr != '\0' ) {			  throw IllegalArgumentError( message );		  }		  return num;	  } else {		  throw IllegalArgumentError( message );	  }  }};/// </body>/// </classdef>AMIS_NAMESPACE_END#endif // Amis_ArgumentParser_h_// end of ArgumentParser.h

⌨️ 快捷键说明

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