1 | /*
|
---|
2 | * TOPPERS/JSP Kernel
|
---|
3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
4 | * Just Standard Profile Kernel
|
---|
5 | *
|
---|
6 | * Copyright (C) 2000-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: directorymap.h,v 1.9 2003/12/15 07:32:13 takayuki Exp $
|
---|
51 | */
|
---|
52 |
|
---|
53 | // $Header: /home/CVS/configurator/base/directorymap.h,v 1.9 2003/12/15 07:32:13 takayuki Exp $
|
---|
54 |
|
---|
55 | #ifndef DIRECTORYMAP_H
|
---|
56 | #define DIRECTORYMAP_H
|
---|
57 |
|
---|
58 | #ifdef _MSC_VER
|
---|
59 | #pragma warning(disable:4786)
|
---|
60 | #endif
|
---|
61 |
|
---|
62 | #include "base/message.h"
|
---|
63 | #include "base/garbage.h"
|
---|
64 | #include "base/singleton.h"
|
---|
65 |
|
---|
66 | //MSVC6.0ã <cstdio> ãã¦ãstdã«å
|
---|
67 | ¥ãã¦ãããªãã®ã§
|
---|
68 | #include <stdio.h>
|
---|
69 |
|
---|
70 | #include <string>
|
---|
71 | #include <map>
|
---|
72 | #include <iostream>
|
---|
73 | #include <cstring>
|
---|
74 |
|
---|
75 | class Directory : public std::map<std::string, Directory *>
|
---|
76 | {
|
---|
77 | private:
|
---|
78 | /*
|
---|
79 | * Directoryã¯ã©ã¹ : è¨è¨ã¡ã¢
|
---|
80 | *
|
---|
81 | * ã»è¦ªåãã¼ãéã®é¢ä¿
|
---|
82 | * çæ : 親ã åãç´æ¥ããã£ã¦ãªã³ã¯ãå¼µã
|
---|
83 | * ç ´æ£ : åã 親ããã®ç¬ç«ãä¾é ¼ãã (親ãã䏿¹çã«åå½ããªã)
|
---|
84 | *
|
---|
85 | * ã»NULLã»ã¼ãå®è£
|
---|
86 |
|
---|
87 | * ä¸é¨ã®é¢æ°ã¯ this != NULL ãä»®å®ããªãã§å®è£
|
---|
88 | ãã (èªåã¸ã®å©ä¾¿æ§åä¸)
|
---|
89 | * - addChild
|
---|
90 | * - findChild, openChild (findNode()
|
---|
91 | * - erase(void)
|
---|
92 | * - getFirstChild, getLastChild, getNext, getPrev
|
---|
93 | */
|
---|
94 |
|
---|
95 | public:
|
---|
96 | enum tagtype
|
---|
97 | {
|
---|
98 | UNKNOWN,
|
---|
99 | POINTER,
|
---|
100 | INTEGER,
|
---|
101 | LITERAL,
|
---|
102 | CONSTLITERAL,
|
---|
103 | OBJECT
|
---|
104 | };
|
---|
105 |
|
---|
106 | enum tagflag
|
---|
107 | {
|
---|
108 | NOTHING = 0,
|
---|
109 | DESTRUCT = 1,
|
---|
110 | UNSIGNED = 2
|
---|
111 | };
|
---|
112 |
|
---|
113 | enum tagmode
|
---|
114 | {
|
---|
115 | PTRPREFIX = 1
|
---|
116 | };
|
---|
117 |
|
---|
118 | protected:
|
---|
119 | static int defaultflag;
|
---|
120 |
|
---|
121 | enum tagtype type;
|
---|
122 | int flag;
|
---|
123 |
|
---|
124 | Directory * parent;
|
---|
125 | std::map<std::string, Directory *>::iterator myself;
|
---|
126 |
|
---|
127 | union
|
---|
128 | {
|
---|
129 | void * pointer;
|
---|
130 | long value;
|
---|
131 | const char * const_literal;
|
---|
132 | std::string * literal;
|
---|
133 | class Garbage * instance;
|
---|
134 | } content;
|
---|
135 |
|
---|
136 | Directory(const Directory &);
|
---|
137 | void initialize(void);
|
---|
138 | void clearContent(void);
|
---|
139 |
|
---|
140 | Directory * findNode(bool, const std::string &);
|
---|
141 | Directory * findNode(bool automatic_creation, const char * key, va_list vl);
|
---|
142 |
|
---|
143 | public:
|
---|
144 | SINGLETON_CONSTRUCTOR(Directory) { initialize(); }
|
---|
145 |
|
---|
146 | Directory(void);
|
---|
147 | Directory(int);
|
---|
148 | Directory(long);
|
---|
149 | Directory(const std::string &);
|
---|
150 | Directory(void *);
|
---|
151 | explicit Directory(const char *);
|
---|
152 | explicit Directory(Garbage *);
|
---|
153 | ~Directory(void);
|
---|
154 |
|
---|
155 | Directory & operator =(void *);
|
---|
156 | Directory & operator =(long);
|
---|
157 | Directory & operator =(const char *);
|
---|
158 | Directory & operator =(const std::string &);
|
---|
159 | Directory & operator =(Garbage *);
|
---|
160 |
|
---|
161 | bool operator == (enum tagtype cmptype)
|
---|
162 | { return type == cmptype; };
|
---|
163 |
|
---|
164 | Directory * operator ()(const std::string & src)
|
---|
165 | { return findChild(src); };
|
---|
166 | Directory * operator ()(const char * src)
|
---|
167 | { return findChild(src); };
|
---|
168 |
|
---|
169 | Directory & operator [](const std::string & src)
|
---|
170 | { return *openChild(src); };
|
---|
171 | Directory & operator [](const char * src)
|
---|
172 | { return *openChild(std::string(src)); };
|
---|
173 |
|
---|
174 | enum tagtype getType(void) const { return type; };
|
---|
175 | Directory * getParent(void) const { return parent; };
|
---|
176 | Directory * getParent(int) const;
|
---|
177 | Directory * getNext(void) const;
|
---|
178 | Directory * getPrev(void) const;
|
---|
179 | Directory * getFirstChild(void) const;
|
---|
180 | Directory * getLastChild(void) const;
|
---|
181 | Directory * findChild(const std::string &);
|
---|
182 | Directory * findChild(const char *);
|
---|
183 | Directory * findChild(const char *, const char * , ... );
|
---|
184 | Directory * findDescandant(const std::string &, unsigned int = 0xffffffff) const;
|
---|
185 | Directory * openChild(const std::string &);
|
---|
186 | Directory * openChild(const char *);
|
---|
187 | Directory * openChild(const char *, const char *, ... );
|
---|
188 |
|
---|
189 | void * operator new(size_t);
|
---|
190 | void * operator new(size_t, std::nothrow_t);
|
---|
191 | void * operator * (void) const;
|
---|
192 |
|
---|
193 | operator const long (void) const;
|
---|
194 | operator const unsigned long (void) const;
|
---|
195 | operator const int (void) const;
|
---|
196 | operator const unsigned int (void) const;
|
---|
197 | operator const char (void) const;
|
---|
198 | operator const unsigned char (void) const;
|
---|
199 | operator const char * (void);
|
---|
200 | operator const std::string & (void) const;
|
---|
201 | operator const Garbage * (void) const;
|
---|
202 | operator const void * (void) const;
|
---|
203 |
|
---|
204 | void * toPointer(const void * default_value = 0) const;
|
---|
205 | long toInteger(const long default_value = 0) const;
|
---|
206 | std::string toString(const std::string & default_value = "") const;
|
---|
207 |
|
---|
208 | bool operator == (int) const;
|
---|
209 | bool operator == (const std::string &) const;
|
---|
210 | bool operator == (const char *) const;
|
---|
211 |
|
---|
212 | template<class T>
|
---|
213 | bool operator != (T src) const
|
---|
214 | { return !(this->operator ==(src)); };
|
---|
215 |
|
---|
216 |
|
---|
217 | Directory * addChild(const std::string &, Directory * = 0);
|
---|
218 | Directory * addChild(const char *, Directory * = 0);
|
---|
219 | Directory * addChild(const std::string &, Directory &);
|
---|
220 | Directory * addChild(const char *, Directory &);
|
---|
221 | Directory * addChild(Directory &);
|
---|
222 | Directory * addChild(Directory * = 0);
|
---|
223 |
|
---|
224 | void erase(void);
|
---|
225 | iterator erase(iterator);
|
---|
226 | void disconnect(void);
|
---|
227 | void copyTo(Directory *, int = 0x7fffffff);
|
---|
228 | void dropValue(void);
|
---|
229 | std::map<std::string, Directory *>::size_type size(std::map<std::string, Directory *>::size_type = 0) const;
|
---|
230 |
|
---|
231 | const std::string getKey(void) const;
|
---|
232 | bool changeKey(const std::string &);
|
---|
233 | bool changeKey(const char *);
|
---|
234 |
|
---|
235 | void Load(std::istream *);
|
---|
236 | void Store(std::ostream *);
|
---|
237 |
|
---|
238 | void drawTree(std::ostream * = &std::cerr, int = 0, std::string * = 0);
|
---|
239 | void drawTree_byXML(std::ostream * = &std::cerr, int = 0);
|
---|
240 |
|
---|
241 | std::string format(const char *, int mode = 0);
|
---|
242 | std::string format(const std::string &, int mode = 0);
|
---|
243 | };
|
---|
244 |
|
---|
245 |
|
---|
246 | //------
|
---|
247 |
|
---|
248 | inline void Directory::initialize(void)
|
---|
249 | {
|
---|
250 | parent = 0;
|
---|
251 | type = UNKNOWN;
|
---|
252 | flag = defaultflag;
|
---|
253 | content.pointer = 0;
|
---|
254 | defaultflag &= ~DESTRUCT;
|
---|
255 | }
|
---|
256 |
|
---|
257 | inline Directory::Directory(void)
|
---|
258 | { initialize(); }
|
---|
259 |
|
---|
260 | inline Directory::Directory(long val)
|
---|
261 | {
|
---|
262 | initialize();
|
---|
263 | *this = val;
|
---|
264 | }
|
---|
265 |
|
---|
266 | inline Directory::Directory(int val)
|
---|
267 | {
|
---|
268 | initialize();
|
---|
269 | *this = (long)val;
|
---|
270 | }
|
---|
271 |
|
---|
272 | inline Directory::Directory(void * val)
|
---|
273 | {
|
---|
274 | initialize();
|
---|
275 | *this = val;
|
---|
276 | }
|
---|
277 |
|
---|
278 | inline Directory::Directory(const std::string & val)
|
---|
279 | {
|
---|
280 | initialize();
|
---|
281 | *this = val;
|
---|
282 | }
|
---|
283 |
|
---|
284 | inline Directory::Directory(const char * val)
|
---|
285 | {
|
---|
286 | initialize();
|
---|
287 | *this = val;
|
---|
288 | }
|
---|
289 |
|
---|
290 | inline Directory::Directory(Garbage * val)
|
---|
291 | {
|
---|
292 | initialize();
|
---|
293 | *this = val;
|
---|
294 | }
|
---|
295 |
|
---|
296 | inline Directory * Directory::addChild(const char * key, Directory * node)
|
---|
297 | { return addChild(std::string(key), node); }
|
---|
298 |
|
---|
299 | inline Directory * Directory::addChild(const std::string & key, Directory & node)
|
---|
300 | { return addChild(key, &node); }
|
---|
301 |
|
---|
302 | inline Directory * Directory::addChild(const char * key, Directory & node)
|
---|
303 | { return addChild(std::string(key), &node); }
|
---|
304 |
|
---|
305 | inline Directory * Directory::addChild(Directory & node)
|
---|
306 | { return addChild(&node); }
|
---|
307 |
|
---|
308 | //ãã®addChildã§è¿½å ããè¦ç´ ã¯ã䏿¬åé¤ããããæ¶ãã¦ã¯ãããªã
|
---|
309 | inline Directory * Directory::addChild(Directory * node)
|
---|
310 | {
|
---|
311 | char buffer[32];
|
---|
312 | sprintf(buffer,"%03d", (int)size());
|
---|
313 | return addChild(buffer, node);
|
---|
314 | }
|
---|
315 |
|
---|
316 | inline bool Directory::changeKey(const char * key)
|
---|
317 | { return changeKey(std::string(key)); }
|
---|
318 |
|
---|
319 | inline const std::string Directory::getKey(void) const
|
---|
320 | {
|
---|
321 | if(parent == 0)
|
---|
322 | return std::string("/");
|
---|
323 | return (*myself).first;
|
---|
324 | }
|
---|
325 |
|
---|
326 | inline Directory::operator const unsigned long (void) const
|
---|
327 | { return static_cast<const unsigned long>(this->operator const long()); }
|
---|
328 |
|
---|
329 | inline Directory::operator const int (void) const
|
---|
330 | { return static_cast<const int>(this->operator const long()); }
|
---|
331 |
|
---|
332 | inline Directory::operator const unsigned int (void) const
|
---|
333 | { return static_cast<const unsigned int>(this->operator const long()); }
|
---|
334 |
|
---|
335 | inline Directory::operator const char (void) const
|
---|
336 | { return static_cast<const char>(this->operator const long()); }
|
---|
337 |
|
---|
338 | inline Directory::operator const unsigned char (void) const
|
---|
339 | { return static_cast<const unsigned char>(this->operator const long()); }
|
---|
340 |
|
---|
341 | inline Directory::operator const char * (void)
|
---|
342 | {
|
---|
343 | if(type == CONSTLITERAL)
|
---|
344 | return content.const_literal;
|
---|
345 | if(type == LITERAL)
|
---|
346 | return content.literal->c_str();
|
---|
347 | ExceptionMessage("Bad cast exception raised","䏿£ãã£ã¹ãä¾å¤").throwException();
|
---|
348 | return 0;
|
---|
349 | }
|
---|
350 |
|
---|
351 | inline Directory::operator const std::string &(void) const
|
---|
352 | {
|
---|
353 | if(type == LITERAL)
|
---|
354 | return *content.literal;
|
---|
355 | ExceptionMessage("Bad cast exception raised","䏿£ãã£ã¹ãä¾å¤").throwException();
|
---|
356 | return *(std::string *)0;
|
---|
357 | }
|
---|
358 |
|
---|
359 | inline Directory::operator const Garbage * (void) const
|
---|
360 | {
|
---|
361 | if(type == OBJECT)
|
---|
362 | return content.instance;
|
---|
363 | ExceptionMessage("Bad cast exception raised","䏿£ãã£ã¹ãä¾å¤").throwException();
|
---|
364 | return 0;
|
---|
365 | }
|
---|
366 |
|
---|
367 | inline Directory::operator const void * (void) const
|
---|
368 | { return **this; }
|
---|
369 |
|
---|
370 | inline Directory * Directory::findChild(const std::string & path)
|
---|
371 | { return findNode(false, path); }
|
---|
372 |
|
---|
373 | inline Directory * Directory::openChild(const std::string & path)
|
---|
374 | { return findNode(true, path); }
|
---|
375 |
|
---|
376 | inline Directory * Directory::getParent(int level) const
|
---|
377 | {
|
---|
378 | const Directory * node = this;
|
---|
379 | while(level-- > 0 && node != 0)
|
---|
380 | node = node->parent;
|
---|
381 | return const_cast<Directory *>(node);
|
---|
382 | }
|
---|
383 |
|
---|
384 | inline Directory * Directory::getFirstChild(void) const
|
---|
385 | {
|
---|
386 | if(this == 0 || size()== 0)
|
---|
387 | return 0;
|
---|
388 | return (*begin()).second;
|
---|
389 | }
|
---|
390 |
|
---|
391 | inline Directory * Directory::getLastChild(void) const
|
---|
392 | {
|
---|
393 | if(this == 0 || size()== 0)
|
---|
394 | return 0;
|
---|
395 | return (*rbegin()).second;
|
---|
396 | }
|
---|
397 |
|
---|
398 | inline bool Directory::operator == (int src) const
|
---|
399 | { return type == INTEGER && content.value == src; }
|
---|
400 |
|
---|
401 | inline bool Directory::operator == (const std::string & src) const
|
---|
402 | { return (type == LITERAL && src.compare(*content.literal) == 0) || (type == CONSTLITERAL && src.compare(content.const_literal) == 0); }
|
---|
403 |
|
---|
404 | inline bool Directory::operator == (const char * src) const
|
---|
405 | { return (type == LITERAL && content.literal->compare(src) == 0) || (type == CONSTLITERAL && strcmp(content.const_literal, src)== 0); }
|
---|
406 |
|
---|
407 | inline std::string Directory::format(const char * src, int mode)
|
---|
408 | { return format(std::string(src), mode); }
|
---|
409 |
|
---|
410 | inline void Directory::dropValue(void)
|
---|
411 | { clearContent(); }
|
---|
412 |
|
---|
413 | #endif
|
---|
414 |
|
---|