source: anotherchoice/tags/jsp-1.4.4-full-UTF8/cfg/base/option.h@ 26

Last change on this file since 26 was 26, checked in by ykominami, 12 years ago

initial

File size: 7.8 KB
Line 
1/*
2 * TOPPERS/JSP Kernel
3 * Toyohashi Open Platform for Embedded Real-Time Systems/
4 * Just Standard Profile Kernel
5 *
6 * Copyright (C) 2003 by Embedded and Real-Time Systems Laboratory
7 * Toyohashi Univ. of Technology, JAPAN
8 *
9 * 上記著作権者
10は,以下の (1)〜(4) の条件か,Free Software Foundation
11 * によってå…
12¬è¡¨ã•ã‚Œã¦ã„ã‚‹ GNU General Public License の Version 2 に記
13 * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
14 * を改変したものを含む.以下同じ)を使用・複製・改変・再é…
15å¸ƒï¼ˆä»¥ä¸‹ï¼Œ
16 * 利用と呼ぶ)することを無償で許諾する.
17 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
18 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
19 * スコード中に含まれていること.
20 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
21 * 用できる形で再é…
22å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
23å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨
24 * 者
25マニュアルなど)に,上記の著作権表示,この利用条件および下記
26 * の無保証規定を掲載すること.
27 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
28 * 用できない形で再é…
29å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®ã„ずれかの条件を満たすこ
30 * と.
31 * (a) 再é…
32å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
33マニュアルなど)に,上記の著
34 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
35 * (b) 再é…
36å¸ƒã®å½¢æ…
37‹ã‚’,別に定める方法によって,TOPPERSプロジェクトに
38 * 報告すること.
39 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
40 * 害からも,上記著作権者
41およびTOPPERSプロジェクトをå…
42è²¬ã™ã‚‹ã“と.
43 *
44 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者
45お
46 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
47 * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
48 * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
49 *
50 * @(#) $Id: option.h,v 1.5 2003/12/20 06:51:58 takayuki Exp $
51 */
52
53// $Header: /home/CVS/configurator/base/option.h,v 1.5 2003/12/20 06:51:58 takayuki Exp $
54
55#ifndef OPTION_H
56#define OPTION_H
57
58#include "base/testsuite.h"
59#include "base/singleton.h"
60
61#include <string>
62#include <vector>
63#include <map>
64
65#define DEFAULT_PARAMETER "#default"
66
67using namespace std;
68
69/*
70 * オプションパラメータを管理するクラス
71 */
72class OptionParameter
73{
74public:
75 class OptionItem : public std::string
76 {
77 protected:
78 bool checked; //使用したかどうか
79 std::vector<std::string> param; //オプション
80
81 public:
82 //コンストラクタ
83 OptionItem(void) throw() : string(DEFAULT_PARAMETER), checked(false) {}
84 OptionItem(const std::string & name) throw() : string(name), checked(false) {}
85 OptionItem(const OptionItem & src) throw() : string(src), checked(src.checked), param(src.param) {}
86
87 //オプションパラメータを解析してOptionItemを生成する
88 static bool createItem(OptionItem & item, string & argv);
89
90 //別のOptionItemが持つパラメータを自分に追加する
91 void mergeItem(const OptionItem & src);
92
93 //パラメータの追加
94 inline void addParameter(const std::string & src) throw()
95 { param.push_back(src); }
96
97 //パラメータ数の取得
98 inline size_t countParameter(void) const throw()
99 { return param.size(); }
100
101 //パラメータを持っているかどうか
102 inline bool hasParameter(void) const throw()
103 { return countParameter() != 0; }
104
105 //位置を指定してパラメータを参ç…
106§ (無効な位置だと空文字)
107 inline std::string operator[](std::vector<std::string>::size_type offset) const throw()
108 {
109 string result;
110
111 if(offset < countParameter())
112 result = param[offset];
113
114 return result;
115 }
116
117 //このオプションを使用したことを記す (OptionParameterを介しての利用のみなので "_" をつけておく)
118 inline void _check(void) throw()
119 { checked = true; }
120
121 //このオプションに触ったかどうか
122 inline bool isChecked(void) const throw()
123 { return checked; }
124
125 //有効かどうか (ななしは無効)
126 inline bool isValid(void) const throw()
127 { return !empty(); }
128
129 //無効なオプションアイテムの生成
130 static OptionItem createInvalidItem(void) throw();
131
132 //å…
133¨ã¦ã®ãƒ‘ラメータ結合したものを取得
134 std::string getParameters(std::string punctuator = " ") const throw();
135
136 //パラメータの個数をチェック
137 bool checkParameterCount(size_t count, bool allow_zero = false) const throw();
138
139 TESTSUITE_PROTOTYPE(main)
140 };
141
142protected:
143 //オプションを格納する変数
144 std::map<std::string, OptionItem> container; //set::begin()はconst_iteratorしか返さないので仕方なくmapに変える (実装
145を考えれば当然か...)
146
147 //プログラム名称
148 std::string program_name;
149
150 //コマンドラインに渡された引数そのもの
151 std::string cmdline;
152
153 //デフォルトコンストラクタ (テスト用)
154 OptionParameter(void) throw() {}
155
156 //要素の検出
157 std::map<std::string, OptionItem>::iterator _find(const std::string & name, bool check = true) throw();
158
159public:
160
161 //シングルトンコンストラクタ
162 SINGLETON_CONSTRUCTOR(OptionParameter) throw() {}
163
164 //オプションパラメータのパース
165 bool parseOption(int _argc, char const * const * _argv, char const * _default = NULL) throw();
166
167 //å…
168¨ã¦ã®ã‚ªãƒ—ションが使用されたかどうかの確認
169 bool validateOption(void) const throw();
170
171 //使用されなかったオプション列を取得
172 std::string getInvalidOptions(void) const throw();
173
174 //アイテムの数を数える
175 inline size_t countItem(void) const throw()
176 { return container.size(); }
177
178 //オプションアイテムの参ç…
179§
180 OptionItem get(const std::string & name, bool check = true) throw();
181
182 inline OptionItem operator [] (const std::string & name) throw()
183 { return get(name); }
184
185 inline OptionItem operator [] (const char * name) throw()
186 { return get(string(name)); }
187
188 //オプションの有無の検出
189 inline bool find(std::string name) throw()
190 { return get(name).isValid(); }
191
192
193 //参ç…
194§ãƒžãƒ¼ã‚¯ã‚’つける
195 inline bool check(const std::string & name) throw()
196 { return _find(name) != container.end(); }
197
198 inline bool check(const char * name) throw()
199 { return check(string(name)); }
200
201 //プログラム名を取得する
202 inline const std::string & getProgramName(void) const throw()
203 { return program_name; }
204
205 //引数列をそのまま取得する (プログラム名は含まず)
206 inline const std::string & getCommandLine(void) const throw()
207 { return cmdline; }
208
209 TESTSUITE_PROTOTYPE(main)
210};
211
212 /* システム内
213で単一のOptionParameterを取るための関数 */
214inline OptionParameter & getOptionParameter(void) throw()
215{ return *Singleton<OptionParameter>::getInstance(); }
216
217#endif
218
219
Note: See TracBrowser for help on using the repository browser.