OSDN Git Service

options のコンストラクタを getopt に合わせて変更
authorSubaruG <subaru_g@users.sourceforge.jp>
Fri, 22 Jan 2010 15:26:40 +0000 (00:26 +0900)
committerSubaruG <subaru_g@users.sourceforge.jp>
Fri, 22 Jan 2010 15:26:40 +0000 (00:26 +0900)
gintenlib/options/options.hpp
tests/list_format.cc
tests/options.cc

index a362cd7..74fe7c0 100644 (file)
@@ -6,12 +6,14 @@
 
   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;
@@ -66,7 +68,7 @@
         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";
@@ -157,7 +159,7 @@ namespace gintenlib
   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)
     {
index 9ee56e3..e55ad08 100644 (file)
@@ -9,6 +9,7 @@
 using namespace std;
 
 // 空のコンテナに対するテスト
+// 空コンテナに対しては何も出力されない
 template<typename T>
 bool is_empty( const T& x )
 {
index acf4779..1a8e995 100644 (file)
@@ -21,7 +21,7 @@ int main( int argc, char* argv[] )
     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 );
     
@@ -58,7 +58,7 @@ int main( int argc, char* argv[] )
       }
     }
     
-    // è§£æ\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";