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 |
|
---|
67 | using namespace std;
|
---|
68 |
|
---|
69 | /*
|
---|
70 | * ãªãã·ã§ã³ãã©ã¡ã¼ã¿ã管çããã¯ã©ã¹
|
---|
71 | */
|
---|
72 | class OptionParameter
|
---|
73 | {
|
---|
74 | public:
|
---|
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 |
|
---|
142 | protected:
|
---|
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 |
|
---|
159 | public:
|
---|
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ãåãããã®é¢æ° */
|
---|
214 | inline OptionParameter & getOptionParameter(void) throw()
|
---|
215 | { return *Singleton<OptionParameter>::getInstance(); }
|
---|
216 |
|
---|
217 | #endif
|
---|
218 |
|
---|
219 |
|
---|