RuntimeOption.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**
  2. * RuntimeOption.h
  3. * Copyright (C) 2010-2012 kbinani, HAL
  4. *
  5. * This files is a part of v.Connect.
  6. * runtimeOptions contains data that is necessary in v.Connect.
  7. *
  8. * These files are distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. */
  13. #ifndef __RuntimeOption_h__
  14. #define __RuntimeOption_h__
  15. #include <string>
  16. #include <iostream>
  17. namespace vconnect
  18. {
  19. using namespace std;
  20. /**
  21. * vConnectでの合成時のオプション
  22. */
  23. class RuntimeOption{
  24. private:
  25. string encodingOtoIni;
  26. string encodingVsqText;
  27. string encodingVowelTable;
  28. string encodingVoiceTexture;
  29. string pathInput;
  30. string pathOutput;
  31. bool convert;
  32. bool transcribe;
  33. bool printCodesetList;
  34. public:
  35. RuntimeOption()
  36. {
  37. this->fillDefault();
  38. }
  39. RuntimeOption( int argc, char *argv[] )
  40. {
  41. this->fillDefault();
  42. // 引数を読み取る
  43. string current_parse = ""; // いま読んでるオプション(-i, -o等)
  44. for( int i = 1; i < argc; i++ ){
  45. string s = argv[i];
  46. if( s.substr( 0, 1 ) == "-" ){
  47. // "-"で始まるので
  48. if( s == "-c" ){
  49. this->convert = true;
  50. this->transcribe = false;
  51. current_parse = "";
  52. }else if( s == "-t" ){
  53. this->transcribe = true;
  54. this->convert = false;
  55. current_parse = "";
  56. }else if( s == "-list-charset" ){
  57. this->printCodesetList = true;
  58. current_parse = "";
  59. }else{
  60. // 次の引数で、オプションsの項目を設定するよ
  61. current_parse = s;
  62. }
  63. }else{
  64. // "-"以外で始まる
  65. if( current_parse == "-i" ){
  66. this->pathInput = s;
  67. }else if( current_parse == "-o" ){
  68. this->pathOutput = s;
  69. }else if( current_parse == "-charset-otoini" ){
  70. this->encodingOtoIni = s;
  71. }else if( current_parse == "-charset-vxt" ){
  72. this->encodingVsqText = s;
  73. }else{
  74. cout << "unknown argument: " << s << endl;
  75. }
  76. current_parse = "";
  77. }
  78. }
  79. // 引数の読み取りでin,outファイル指定が存在しなかった場合
  80. if( this->pathInput == "" || this->pathOutput == "" ){
  81. // 引数の個数がちょうど3だったらば、引数の順番依存とみなして。
  82. if( argc == 3 ){
  83. this->pathInput = argv[1];
  84. this->pathOutput = argv[2];
  85. }
  86. }
  87. }
  88. /**
  89. * 音源の変換モードで起動されたかどうか
  90. */
  91. bool isConvert()
  92. {
  93. return this->convert;
  94. }
  95. /**
  96. * 多段化みたいな
  97. */
  98. bool isTranscribe()
  99. {
  100. return this->transcribe;
  101. }
  102. /**
  103. * oto.ini ファイルを読み込む際のテキストエンコーディングを取得する
  104. */
  105. string getEncodingOtoIni()
  106. {
  107. return this->encodingOtoIni;
  108. }
  109. /**
  110. * メタテキストファイルを読み込む際のテキストエンコーディング指定を取得する
  111. */
  112. string getEncodingVsqText()
  113. {
  114. return this->encodingVsqText;
  115. }
  116. /**
  117. * 入力ファイルまたはディレクトリのパスを取得する
  118. */
  119. string getInputPath()
  120. {
  121. return this->pathInput;
  122. }
  123. /**
  124. * 出力ファイルまたはディレクトリのパスを取得する
  125. */
  126. string getOutputPath()
  127. {
  128. return this->pathOutput;
  129. }
  130. /**
  131. * サポートするコードセットのリストを出力するかどうか
  132. */
  133. bool isPrintCodeset()
  134. {
  135. return this->printCodesetList;
  136. }
  137. private:
  138. void fillDefault()
  139. {
  140. this->convert = false;
  141. this->transcribe = false;
  142. this->printCodesetList = false;
  143. this->encodingOtoIni = "Shift_JIS";
  144. this->encodingVsqText = "Shift_JIS";
  145. this->encodingVowelTable = "Shift_JIS";
  146. this->encodingVoiceTexture = "Shift_JIS";
  147. this->pathInput = "";
  148. this->pathOutput = "";
  149. }
  150. };
  151. }
  152. #endif