options : getopt 的プログラムオプション解析
+ TODO: 例外安全性の強化
+
宣言:
struct options
{
// 指定された文字列でオプション解析オブジェクトを作る
// 文字列は基本的に getopt 互換、冒頭の : と - の動作のみ違う
- explicit options( const std::string& optstr, int argc, char* argv[] );
+ explicit options( int argc, char* argv[], const std::string& optstr );
// 実際にオプションを解析する
typedef int result_type;
if( argc < 2 ){ throw gintenlib::option_error("missing 'OPTSTR'"); }
// argv[1] は特別な引数
- gintenlib::options opt( argv[1], argc, argv );
+ gintenlib::options opt( argc, argv, argv[1] );
// なので解析させない
opt.set_optind( 2 );
}
}
- // 解æ\9e\90çµ\82äº\86ã\80\82ä½\99ã\81£ã\81\9fã\82ªã\83\97ã\82·ã\83§ã\83³ã\81¯ argv[opt.optind()] ã\80\9c argv[argc-1] に集められる
+ // 解æ\9e\90çµ\82äº\86ã\80\82ä½\99ã\81£ã\81\9fã\82ªã\83\97ã\82·ã\83§ã\83³ã\81¯ argv[opt.optind()] ã\81\8bã\82\89 argv[argc-1] に集められる
// デフォルトでは、オプション引数が非オプション引数の後にある場合、 argv の順序を入れ替える
// この動作を避けたい場合は、コンストラクタの引数を '+' で始めればよい
cout << "\nextra options are:\n";
struct options
{
// optstr で示されるフォーマットのオプションを解析する
- explicit options( const std::string& optstr, int argc_, char* argv_[] )
+ explicit options( int argc_, char* argv_[], const std::string& optstr )
: argc(argc_), argv(argv_), index(1), index_max(argc), next_char(0), opt('?'),
posixly_correct(false), throws_on_error(true)
{
if( argc < 2 ){ throw gintenlib::option_error("missing 'OPTSTR'"); }
// argv[1] は特別な引数
- gintenlib::options opt( argv[1], argc, argv );
+ gintenlib::options opt( argc, argv, argv[1] );
// なので解析させない
opt.set_optind( 2 );
}
}
- // 解æ\9e\90çµ\82äº\86ã\80\82ä½\99ã\81£ã\81\9fã\82ªã\83\97ã\82·ã\83§ã\83³ã\81¯ argv[opt.optind()] ã\80\9c argv[argc-1] に集められる
+ // 解æ\9e\90çµ\82äº\86ã\80\82ä½\99ã\81£ã\81\9fã\82ªã\83\97ã\82·ã\83§ã\83³ã\81¯ argv[opt.optind()] ã\81\8bã\82\89 argv[argc-1] に集められる
// デフォルトでは、オプション引数が非オプション引数の後にある場合、 argv の順序を入れ替える
// この動作を避けたい場合は、コンストラクタの引数を '+' で始めればよい
cout << "\nextra options are:\n";