source: cfg_oil/trunk/toppers/oil/oil_object.hpp@ 8

Last change on this file since 8 was 8, checked in by msugi, 13 years ago

ディレクトリ構造の作成,ソース一式とReleaseビルドのコミット.

File size: 26.2 KB
Line 
1/*
2 * TOPPERS Software
3 * Toyohashi Open Platform for Embedded Real-Time Systems
4 *
5 * Copyright (C) 2010 by Meika Sugimoto
6 *
7 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
8 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
9 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
10 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
11 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
12 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
13 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
14 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
15ƒƒ“ƒgi—˜—p
16 * ŽÒƒ}ƒjƒ…
17ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
18 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
19 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
20 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
21 * ‚ƁD
22 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
23ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
24ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
25 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
26 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
27 * •ñ‚·‚邱‚ƁD
28 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
29 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
30 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
31 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
32 * –Ɛӂ·‚邱‚ƁD
33 *
34 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
35 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
36 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
37 * ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
38 * ‚̐ӔC‚𕉂í‚È‚¢D
39 *
40 */
41
42#ifndef OIL_OBJECT_H
43#define OIL_OBJECT_H
44
45#include <string.h>
46#include <vector>
47#include <map>
48#include <algorithm>
49#include <boost/regex.hpp>
50#include <boost/lexical_cast.hpp>
51
52#include "toppers/diagnostics.hpp"
53
54using namespace std;
55
56namespace toppers
57{
58 namespace oil
59 {
60 extern void dump(boost::smatch *r);
61
62 namespace oil_definition
63 {
64 // ƒNƒ‰ƒX‚Ì‘O•ûéŒ¾
65 class object_parameter_def;
66 class object_definition;
67 }
68
69 // ƒpƒ‰ƒ[ƒ^ƒ^ƒCƒv
70 enum PARAMETER_TYPE
71 {
72 TYPE_UINT = 1 ,
73 TYPE_INT ,
74 TYPE_FLOAT ,
75 TYPE_STRING ,
76 TYPE_BOOLEAN ,
77 TYPE_ENUM ,
78 TYPE_REF ,
79 TYPE_UNKNOWN
80 };
81
82 typedef struct
83 {
84 string obj_type;
85 string obj_name;
86 } object_ref;
87
88 namespace oil_implementation
89 {
90
91 // ƒNƒ‰ƒX‚Ì‘O•ûéŒ¾
92 class object_parameter_impl;
93
94 class oil_object_impl
95 {
96 public:
97 oil_object_impl(string object_name)
98 {
99 name = object_name;
100 }
101 ~oil_object_impl();
102 int add_parameter(string param_name , string parameter_descripition);
103 bool validate_object_configuration
104 (oil_definition::object_definition* obj_def , std::vector<object_ref> *references);
105 void display_implementation(void);
106 private:
107 bool oil_object_impl::validate_object_parameter
108 (oil_definition::object_parameter_def *obj_param , bool *multiple ,
109 std::vector<object_ref> *references);
110 string name;
111 std::vector<object_parameter_impl*> params;
112 };
113
114 // ’l§ŒÀ‚ÌŽí—Þ
115 enum VALUE_LIMIT_TYPE
116 {
117 LIMIT_RANGE = 1 ,
118 LIMIT_LIST ,
119 LIMIT_NONE
120 };
121 // ƒfƒtƒHƒ‹ƒg’l‚ÌŽí—Þ
122 enum DEFAULT_TYPE
123 {
124 NO_DEFAULT = 1 ,
125 AUTO ,
126 HAVE_DEFAULT ,
127 HAVE_NOT_DEFINE
128 };
129
130 class object_parameter_impl
131 {
132 public:
133 object_parameter_impl(string param_name)
134 {
135 name = param_name;
136 }
137 object_parameter_impl(string param_name , string parameter_description)
138 {
139 name = param_name;
140
141 // AUTO‘®«‚̉ðÍ
142 if(parameter_description.find("WITH_AUTO") != string::npos)
143 {
144 assign_auto = true;
145 }
146 else
147 {
148 assign_auto = false;
149 }
150
151 /// ENUM‚Ì‚Æ‚«‚É–â‘è‚ ‚è
152 // •¡”’è‹`—L–³‚̉ðÍ
153 boost::regex brace("\\[\\s*\\]\\s*(=.+)?;");
154 if(boost::regex_search(parameter_description , brace))
155 {
156 multiple = true;
157 }
158 else
159 {
160 multiple = false;
161 }
162
163 // ƒfƒtƒHƒ‹ƒg’l‚̉ðÍ
164 boost::regex default_value("=\\s+(\\S+)\\s*;");
165 boost::smatch result;
166 string::const_iterator start = parameter_description.begin();
167 string::const_iterator end = parameter_description.end();
168 if(boost::regex_search(start , end , result , default_value))
169 {
170 default_description = result.str(1);
171 if(default_description == "AUTO")
172 {
173 default_type = AUTO;
174 }
175 else if(default_description == "NO_DEFAULT")
176 {
177 default_type = NO_DEFAULT;
178 }
179 else
180 {
181 default_type = HAVE_DEFAULT;
182 }
183 }
184 else
185 {
186 default_type = HAVE_NOT_DEFINE;
187 default_description.erase(0);
188 }
189 }
190
191 string get_name(void)
192 {
193 return name;
194 }
195
196 DEFAULT_TYPE get_default(string *str)
197 {
198 if((default_type == HAVE_DEFAULT)
199 || (default_type == AUTO))
200 {
201 *str = default_description;
202 }
203
204 return default_type;
205 }
206
207 virtual void display_implementation(void)
208 {
209 cout << "Parameter Name : " << name << endl;
210 cout << "Multilple : " << ((multiple == true)? "Yes" : "No") << endl;
211 cout << "Auto Assignment : " << ((assign_auto == true)? "Yes" : "No") << endl;
212 cout << "Default Value : ";
213 if(default_type == NO_DEFAULT)
214 {
215 cout << "NO_DEFAULT";
216 }
217 else if(default_type == AUTO)
218 {
219 cout << "AUTO";
220 }
221 else
222 {
223 cout << "HAVE_DEFAULT";
224 }
225 cout << endl;
226 }
227
228 virtual bool validate_parameter_name(string param_name)
229 {
230 if(name == param_name)
231 {
232 return true;
233 }
234 else
235 {
236 return false;
237 }
238 }
239
240 bool validate_object_parameter
241 (oil_definition::object_parameter_def *obj , bool *auto_param);
242 virtual bool object_parameter_impl::validate_object_parameter
243 (oil_definition::object_parameter_def *obj)
244 {
245 return false;
246 }
247 virtual void set_parameter_type(oil_definition::object_parameter_def *obj);
248
249 bool get_multiple(void)
250 {
251 return multiple;
252 }
253 protected:
254 inline const char* return_format(double x , int type)
255 {
256 return "%lf";
257 }
258
259 inline const char* return_format(__int64 x , int type)
260 {
261 if(type == 0)
262 {
263 return "%I64x";
264 }
265 else
266 {
267 return "%I64d";
268 }
269 }
270
271 inline const char* return_format(unsigned __int64 x , int type)
272 {
273 if(type == 0)
274 {
275 return "%I64x";
276 }
277 else
278 {
279 return "%I64u";
280 }
281 }
282
283 template <typename T>
284 T str2val(const char *str , T dummy)
285 {
286 T temp;
287 T zero = 0 , one = 1;
288 if((str[0] == '0') && ((str[1] == 'x') || (str[1] == 'X')))
289 {
290 sscanf_s(&str[2] , return_format(zero , 0) , &temp);
291 }
292 else
293 {
294 sscanf_s(&str[0] , return_format(zero , 1) , &temp);
295 }
296 return temp;
297 }
298
299 template <typename T>
300 void split_number_list(const char *str , std::vector<T> *list)
301 {
302 const char *p = str;
303 char val[32];
304 int i;
305 T zero = 0;
306
307 // ƒŠƒXƒg‚ð‰ðÍ
308 do
309 {
310 i = 0;
311 // ƒXƒy[ƒX‚ð‚Ƃ΂·
312 while(*p == ' ')
313 {
314 p++;
315 }
316 // ”’l•”•ª‚̉ðÍ
317 while(*p != ' ' && (*p != '\0'))
318 {
319 val[i++] = *p++;
320 }
321 // Œã‚ë‚̃Xƒy[ƒX‚ƃJƒ“ƒ}‚à‚Ƃ΂·
322 while((*p == ' ') || (*p == ','))
323 {
324 p++;
325 }
326 // ”’l‚̉ðÍ‚ƃŠƒXƒg‚Ö‚Ì‘}“ü
327 val[i] = '\0';
328 list->push_back((T)str2val(val , zero));
329 }while(*p != '\0');
330 }
331
332 template <class T , typename Y>
333 void dump_limit_value(T* obj)
334 {
335 if(obj->limit_type == LIMIT_RANGE)
336 {
337 cout << "Min value : " << obj->min << endl;
338 cout << "Max value : " << obj->max << endl;
339 }
340 else if(obj->limit_type == LIMIT_LIST)
341 {
342 std::vector<Y>::iterator p;
343
344 cout << "Limit value : ";
345 for(p = obj->value_list.begin() ; p != obj->value_list.end() ; p++)
346 {
347 cout << *p << ",";
348 }
349 cout << endl;
350 }
351 else
352 {
353 cout << "Limit value : None" << endl;
354 }
355
356 if(obj->default_type == HAVE_DEFAULT)
357 {
358 cout << "Default value : " << obj->default_value << endl;
359 }
360 cout << endl;
361 }
362
363 int id;
364 string name;
365 bool multiple;
366 string default_description;
367 bool assign_auto;
368 DEFAULT_TYPE default_type;
369 };
370
371 // INTŒ^iINT32,INT64)
372 class parameter_int_impl : public object_parameter_impl
373 {
374 friend class object_parameter_impl;
375
376 public:
377 parameter_int_impl(string param_name , string parameter_description)
378 : object_parameter_impl(param_name , parameter_description)
379 {
380 // §ŒÀ’l‚̃p[ƒX
381 boost::regex limit_list("\\[\\s*((\\w)+(\\s*,\\s*\\w+)*)\\s*\\]");
382 boost::regex limit_range("\\[\\s*(\\w+)\\s*\\.\\.\\s*(\\w+)\\s*\\]");
383 string::const_iterator start = parameter_description.begin();
384 string::const_iterator end = parameter_description.end();
385 boost::smatch result;
386
387 // ƒŠƒXƒgŒ`Ž®‚©‚̃`ƒFƒbƒN
388 if(boost::regex_search(start , end , result , limit_list))
389 {
390 limit_type = LIMIT_LIST;
391 string str = result.str(1);
392 split_number_list(str.c_str() , &value_list);
393 }
394 // ƒŒƒ“ƒWŒ`Ž®‚©‚̃`ƒFƒbƒN
395 else if(boost::regex_search(start , end , result , limit_range))
396 {
397 limit_type = LIMIT_RANGE;
398 string str;
399
400 // Å¬’l
401 str = result.str(1);
402 min = str2val(str.c_str() , (__int64)0);
403 // Å‘å’l
404 str = result.str(2);
405 max = str2val(str.c_str() , (__int64)0);
406 }
407 else
408 {
409 min = 0;
410 if(parameter_description.find("INT32") != string::npos)
411 {
412 max = INT_MAX;
413 }
414 else
415 {
416 max = _I64_MAX;
417 }
418 limit_type = LIMIT_RANGE;
419 }
420
421 // ƒfƒtƒHƒ‹ƒg’l‚ÌŽZo
422 if(default_type == HAVE_DEFAULT)
423 {
424 default_value = str2val(default_description.c_str() , (__int64)0);
425 }
426 }
427 virtual void display_implementation(void)
428 {
429 cout << "Parameter types : INT" << endl;
430 object_parameter_impl::display_implementation();
431 dump_limit_value<parameter_int_impl , __int64>(this);
432 }
433 bool validate_object_parameter(oil_definition::object_parameter_def *obj);
434 void set_parameter_type(oil_definition::object_parameter_def *obj);
435 protected:
436 VALUE_LIMIT_TYPE limit_type;
437 std::vector<__int64> value_list;
438 __int64 default_value;
439 __int64 max;
440 __int64 min;
441 };
442
443 // UINTŒ^iUINT32,UINT64)
444 class parameter_uint_impl : public object_parameter_impl
445 {
446 friend class object_parameter_impl;
447
448 public:
449 parameter_uint_impl(string param_name , string parameter_description)
450 : object_parameter_impl(param_name , parameter_description)
451 {
452 // §ŒÀ’l‚̃p[ƒX
453 boost::regex limit_list("\\[\\s*((\\w)+(\\s*,\\s*\\w+)*)\\s*\\]");
454 boost::regex limit_range("\\[\\s*(\\w+)\\s*\\.\\.\\s*(\\w+)\\s*\\]");
455 string::const_iterator start = parameter_description.begin();
456 string::const_iterator end = parameter_description.end();
457 boost::smatch result;
458
459 // ƒŠƒXƒgŒ`Ž®‚©‚̃`ƒFƒbƒN
460 if(boost::regex_search(start , end , result , limit_list))
461 {
462 limit_type = LIMIT_LIST;
463 string str = result.str(1);
464 split_number_list(str.c_str() , &value_list);
465 }
466 // ƒŒƒ“ƒWŒ`Ž®‚©‚̃`ƒFƒbƒN
467 else if(boost::regex_search(start , end , result , limit_range))
468 {
469 limit_type = LIMIT_RANGE;
470 string str;
471
472 // Å¬’l
473 str = result.str(1);
474 min = str2val(str.c_str() , (unsigned __int64)0);
475 // Å‘å’l
476 str = result.str(2);
477 max = str2val(str.c_str() , (unsigned __int64)0);
478 }
479 else
480 {
481 min = 0;
482 if(parameter_description.find("UINT32") != string::npos)
483 {
484 max = UINT_MAX;
485 }
486 else
487 {
488 max = _UI64_MAX;
489 }
490 limit_type = LIMIT_RANGE;
491 }
492 // ƒfƒtƒHƒ‹ƒg’l‚ÌŽZo
493 if(default_type == HAVE_DEFAULT)
494 {
495 default_value = str2val(default_description.c_str() , (unsigned __int64)0);
496 }
497 }
498
499 virtual void display_implementation(void)
500 {
501 cout << "Parameter types : UINT" << endl;
502 object_parameter_impl::display_implementation();
503 dump_limit_value<parameter_uint_impl , unsigned __int64>(this);
504 }
505 bool validate_object_parameter(oil_definition::object_parameter_def *obj);
506 void set_parameter_type(oil_definition::object_parameter_def *obj);
507 protected:
508 VALUE_LIMIT_TYPE limit_type;
509 std::vector<unsigned __int64> value_list;
510 unsigned __int64 max;
511 unsigned __int64 min;
512 unsigned __int64 default_value;
513 };
514
515 // FLOATŒ^iFLOAT)
516 class parameter_float_impl : public object_parameter_impl
517 {
518 friend class object_parameter_impl;
519
520 public:
521 parameter_float_impl(string param_name , string parameter_description)
522 : object_parameter_impl(param_name , parameter_description)
523 {
524 // §ŒÀ’l‚̃p[ƒX
525 boost::regex limit_list("\\[\\s*((\\w(\\.\\w+)?)+(\\s*,\\s*\\w+(\\.\\w+)?)*)\\s*\\]");
526 boost::regex limit_range("\\[\\s*(\\w+(\\.\\w+)?)\\s*\\.\\.\\s*(\\w+(\\.\\w+)?)\\s*\\]");
527 string::const_iterator start = parameter_description.begin();
528 string::const_iterator end = parameter_description.end();
529 boost::smatch result;
530
531 // ƒŠƒXƒgŒ`Ž®‚©‚̃`ƒFƒbƒN
532 if(boost::regex_search(start , end , result , limit_list))
533 {
534 limit_type = LIMIT_LIST;
535 string str = result.str(1);
536 split_number_list(str.c_str() , &value_list);
537 }
538 // ƒŒƒ“ƒWŒ`Ž®‚©‚̃`ƒFƒbƒN
539 else if(boost::regex_search(start , end , result , limit_range))
540 {
541 limit_type = LIMIT_RANGE;
542 string str;
543
544 // Å¬’l
545 str = result.str(1);
546 min = str2val(str.c_str() , (double)0);
547 // Å‘å’l
548 str = result.str(3);
549 max = str2val(str.c_str() , (double)0);
550 }
551 else
552 {
553 limit_type = LIMIT_NONE;
554 }
555 // ƒfƒtƒHƒ‹ƒg’l‚ÌŽZo
556 if(default_type == HAVE_DEFAULT)
557 {
558 default_value = str2val(default_description.c_str() , (double)0);
559 }
560 }
561 virtual void display_implementation(void)
562 {
563 cout << "Parameter types : FLOAT" << endl;
564 object_parameter_impl::display_implementation();
565 dump_limit_value<parameter_float_impl , double>(this);
566 }
567 bool validate_object_parameter(oil_definition::object_parameter_def *obj);
568 void set_parameter_type(oil_definition::object_parameter_def *obj);
569 protected:
570 VALUE_LIMIT_TYPE limit_type;
571 std::vector<double> value_list;
572 double max;
573 double min;
574 double default_value;
575 };
576
577 // STRINGŒ^
578 class parameter_string_impl : public object_parameter_impl
579 {
580 public:
581 parameter_string_impl(string param_name , string parameter_description)
582 : object_parameter_impl(param_name , parameter_description)
583 {
584 // ƒfƒtƒHƒ‹ƒg’l‚Ì‘ã“ü
585 if(default_type == HAVE_DEFAULT)
586 {
587 default_value = default_description;
588 }
589 }
590
591 virtual void display_implementation(void)
592 {
593 cout << "Parameter types : STRING" << endl;
594 object_parameter_impl::display_implementation();
595 if(default_type == HAVE_DEFAULT)
596 {
597 cout << "Default value : " << default_value << endl;
598 }
599 }
600 virtual bool validate_object_parameter
601 (oil_definition::object_parameter_def *obj);
602 virtual void set_parameter_type(oil_definition::object_parameter_def *obj);
603 protected:
604 string default_value;
605 };
606
607 // BOOLEANŒ^
608 class parameter_boolean_impl : public parameter_string_impl
609 {
610 public:
611 parameter_boolean_impl(string param_name , string parameter_description)
612 : parameter_string_impl(param_name , parameter_description)
613 {
614 }
615 virtual bool validate_object_parameter
616 (oil_definition::object_parameter_def *obj);
617 virtual void set_parameter_type(oil_definition::object_parameter_def *obj);
618 };
619
620 // ENUMŒ^
621 class parameter_enum_impl : public object_parameter_impl
622 {
623 public:
624 parameter_enum_impl(string param_name , string parameter_description)
625 : object_parameter_impl(param_name , parameter_description)
626 {
627 boost::regex enum_description("(\\w+\\s+[^;]+);(\\s*(.+)\\s)*");
628 boost::regex enum_parse("(\\w+\\s+\\[)?\\s*((\\w+)\\s*(\\{([^\\{\\}]*)\\})?)(\\s*,\\s*(.+))*");
629 boost::regex subparam_name("([^\\[\\]\\s]+)\\s+((WITH_AUTO)?\\s+(\\[.+\\])?)?([^\\[\\]\\s]+)");
630 boost::regex space("\\s*");
631 string::const_iterator start = parameter_description.begin();
632 string::const_iterator end = parameter_description.end();
633 boost::smatch result;
634 toppers::oil::oil_implementation::oil_object_impl *sub_impl;
635 string name;
636
637 // 1ŒÂ‚¸‚ƒpƒ‰ƒ[ƒ^‚ðØ‚蕪‚¯‚ďˆ—
638 while(boost::regex_search(start , end , result , enum_parse))
639 {
640 string temp = result.str(5);
641 string::const_iterator start2 = temp.begin();
642 string::const_iterator end2 = temp.end();
643 boost::smatch result2;
644
645 try
646 {
647 /// try catch
648 sub_impl = new oil_object_impl(param_name);
649 name = result.str(3);
650 // ƒpƒ‰ƒ[ƒ^‚̐؂蕪‚¯
651 while(boost::regex_search(start2 , end2 , result2 , enum_description))
652 {
653 string temp2 = result2.str(1);
654 string::const_iterator start3 = temp2.begin();
655 string::const_iterator end3 = temp2.end();
656 boost::smatch result3;
657 // ƒpƒ‰ƒ[ƒ^–¼‚Ì’Šo
658 (void)boost::regex_search(start3 , end3 , result3 , subparam_name);
659
660 sub_impl->add_parameter(result3.str(5) , result2.str(1) + ";");
661 // ƒpƒ‰ƒ[ƒ^‚ª‚È‚­‚È‚Á‚½‚烋[ƒv‚𔲂¯‚é
662 if(boost::regex_match(result2.str(3) , space))
663 {
664 break;
665 }
666 temp.erase(0 , temp.find(result2.str(3)));
667 end2 = temp.end();
668 }
669
670 // ƒRƒ“ƒeƒi‚Ö‚Ì“o˜^
671 sub_params.insert(pair<string , oil_object_impl*>(name , sub_impl));
672
673 // ƒpƒ‰ƒ[ƒ^‚ª‚È‚­‚È‚Á‚½‚烋[ƒv‚𔲂¯‚é
674 if(boost::regex_match(result.str(7) , space))
675 {
676 break;
677 }
678 parameter_description.erase(0 , parameter_description.find(result.str(7)));
679 end = parameter_description.end();
680 }
681 catch( ... )
682 {
683 toppers::fatal("Memory allocation error.");
684 }
685 }
686 }
687
688 ~parameter_enum_impl()
689 {
690 std::map<std::string , oil_object_impl*>::iterator p;
691
692 for(p = sub_params.begin() ; p != sub_params.end() ; p++)
693 {
694 delete (*p).second;
695 }
696 }
697
698 virtual void display_implementation(void)
699 {
700 std::map<std::string , oil_object_impl*>::iterator p;
701
702 cout << "Parameter types : ENUM" << endl;
703 object_parameter_impl::display_implementation();
704
705 cout << "-------------- Sub parameters --------------" << endl;
706 for(p = sub_params.begin() ; p != sub_params.end() ; p++)
707 {
708 cout << "Sub param name : " << (*p).first << endl;
709 (*p).second->display_implementation();
710 }
711 cout << "--------------------------------------------" << endl;
712
713 }
714
715 bool validate_object_parameter(oil_definition::object_parameter_def *obj ,
716 std::vector<toppers::oil::object_ref> *object_refs);
717 void set_parameter_type
718 (oil_definition::object_parameter_def *obj);
719 protected:
720 std::map<std::string , oil_object_impl*> sub_params;
721 };
722
723 // ŽQÆŒ^
724 class parameter_object_ref_impl : public object_parameter_impl
725 {
726 public:
727 parameter_object_ref_impl(string param_name , string parameter_description)
728 : object_parameter_impl(param_name , parameter_description)
729 {
730 // ŽQÆ‚·‚éƒIƒuƒWƒFƒNƒg–¼‚Ì’Šo
731 boost::regex ref_type("(\\w+)_TYPE");
732 string::const_iterator start = parameter_description.begin();
733 string::const_iterator end = parameter_description.end();
734 boost::smatch result;
735
736 if(boost::regex_search(start , end , result , ref_type))
737 {
738 reftype_name = result.str(1);
739 }
740 /// ƒfƒtƒHƒ‹ƒg’l‚̓ǂݍž‚Ý
741 }
742 virtual void display_implementation(void)
743 {
744 cout << "Parameter types : OBJECT REF" << endl;
745 object_parameter_impl::display_implementation();
746 cout << "Reference Type : " << reftype_name << endl << endl;
747 }
748
749 bool validate_object_parameter
750 (oil_definition::object_parameter_def *obj , std::vector<toppers::oil::object_ref> *object_refs);
751 void set_parameter_type(oil_definition::object_parameter_def *obj);
752 protected:
753 string reftype_name;
754 };
755 }
756
757 namespace oil_definition
758 {
759 // ƒIƒuƒWƒFƒNƒg’è‹`‚̃Nƒ‰ƒX
760 class object_definition
761 {
762 public:
763 object_definition(string object_name_type , object_parameter_def* parent = NULL)
764 {
765 boost::regex object_declaration("(\\w+)\\s+([\\w\\.]+)");
766 string::const_iterator start = object_name_type.begin();
767 string::const_iterator end = object_name_type.end();
768 boost::smatch result;
769
770 // Œ‹‚Ñ•t‚¯‚ç‚ê‚Ä‚¢‚éƒpƒ‰ƒ[ƒ^‚ւ̃|ƒCƒ“ƒ^‚ðŠi”[
771 parent_parameter = parent;
772 // ƒ^ƒCƒv‚ƃl[ƒ€‚ðƒp[ƒX‚µ‚ÄŠi”[
773 if(boost::regex_match(start , end , result , object_declaration))
774 {
775 object_type = result.str(1);
776 name = result.str(2);
777 }
778 else
779 {
780 /* ‚ ‚肦‚È‚¢ */
781 }
782 }
783
784 ~object_definition();
785
786 int add_parameter(string param_name , string param_value);
787
788 string get_object_type(void)
789 {
790 return object_type;
791 }
792
793 std::vector<object_parameter_def*>* get_params(void)
794 {
795 return &params;
796 }
797 void display_definition(void);
798 void set_id(int obj_id)
799 {
800 id = obj_id;
801 }
802 int get_id(void)
803 {
804 return id;
805 }
806 std::string get_name(void)
807 {
808 return name;
809 }
810 object_parameter_def* get_parent(void)
811 {
812 return parent_parameter;
813 }
814
815 private:
816 int id;
817 string name;
818 string object_type;
819 std::vector<object_parameter_def*> params;
820 object_parameter_def* parent_parameter;
821 };
822
823 // ƒIƒuƒWƒFƒNƒg’è‹`ƒpƒ‰ƒ[ƒ^‚ÌŠî–{ƒNƒ‰ƒX
824 class object_parameter_def
825 {
826 public:
827 object_parameter_def(string def_name , string def_value , string parent)
828 {
829 boost::regex have_subparam("(\\w+)\\s*\\{\\s*(([^\\{\\}])+)\\s*\\}");
830 string::const_iterator start = def_value.begin();
831 string::const_iterator end = def_value.end();
832 boost::smatch result;
833
834 name = def_name;
835 parent_name = parent;
836
837 // ƒTƒuƒpƒ‰ƒ[ƒ^‚ª‚ ‚éê‡‚Í‚³‚ç‚É•ª‰ð
838 if(boost::regex_search(start , end , result , have_subparam))
839 {
840 string type_name;
841 object_definition *subparam;
842
843 value = result.str(1);
844
845 type_name = result.str(1) + " SUBPARAM";
846
847 // ƒTƒuƒpƒ‰ƒ[ƒ^‚ðŠi”[‚·‚éƒIƒuƒWƒFƒNƒg‚𐶐¬
848 try
849 {
850 subparam = new object_definition(name + " " + name , this);
851 }
852 catch( std::bad_alloc )
853 {
854 toppers::fatal("Memory allocation error.");
855 }
856
857 boost::regex subparam_regex("((\\w+)\\s*=\\s*([\\w\"]+\\s*(\\{\\s*[^\\{\\}]\\s*\\})?));(.+)");
858 boost::regex space("\\s*");
859 string temp = result.str(2);
860 string::const_iterator start2 = temp.begin();
861 string::const_iterator end2 = temp.end();
862 boost::smatch result2;
863
864 while(boost::regex_search(start2 , end2 , result2 , subparam_regex))
865 {
866 subparam->add_parameter(result2.str(2) , result2.str(3));
867
868 // •ª‰ð‚µI‚í‚Á‚½‚甲‚¯‚é
869 if(boost::regex_match(result2.str(5) , space))
870 {
871 break;
872 }
873 temp.erase(0 , temp.find(result2.str(5)));
874 end2 = temp.end();
875 }
876 // ƒRƒ“ƒeƒi‚ɒljÁ
877 subparams.push_back(subparam);
878 }
879 else
880 {
881 value = def_value;
882 }
883 }
884
885 ~object_parameter_def()
886 {
887 std::vector<object_definition*>::iterator p;
888
889 for(p = subparams.begin() ; p != subparams.end() ; p++)
890 {
891 delete (*p);
892 }
893 }
894
895 string get_parameter_name(void)
896 {
897 return name;
898 }
899
900 string get_value(void)
901 {
902 return value;
903 }
904
905 string get_parent_name(void)
906 {
907 return parent_name;
908 }
909
910 std::vector<object_definition*>* get_subparams(void)
911 {
912 return &subparams;
913 }
914
915 void display_definition(void)
916 {
917 std::vector<object_definition*>::iterator p;
918
919 cout << "\tName : " << name << " Value : " << value << endl;
920 for(p = subparams.begin(); p != subparams.end(); p++)
921 {
922 cout << "\t";
923 (*p)->display_definition();
924 }
925 }
926 void set_type(PARAMETER_TYPE param_type)
927 {
928 type = param_type;
929 }
930 PARAMETER_TYPE get_type(void)
931 {
932 return type;
933 }
934
935 protected:
936 string name;
937 string value;
938 string parent_name;
939 PARAMETER_TYPE type;
940 std::vector<object_definition*> subparams;
941 };
942
943 typedef std::map< std::string, std::vector< object_definition* > > cfg_obj_map;
944 cfg_obj_map merge(std::vector<object_definition*> *obj_defs ,
945 cfg_obj_map& out , string prefix = string("") ,
946 string suffix = string("") , long fixed_id = UINT_MAX);
947 void assign_id(cfg_obj_map obj_defs , long fixed_id = UINT_MAX);
948
949 } /* oil_definition */
950
951
952 } /* oil */
953}
954
955
956#endif /* OIL_OBJECT_H */
Note: See TracBrowser for help on using the repository browser.