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

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

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

File size: 24.1 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#include <boost/regex.hpp>
43#include <boost/lexical_cast.hpp>
44#include <boost/cast.hpp>
45#include <algorithm>
46#include <functional>
47
48#include "toppers/oil/oil_object.hpp"
49#include "toppers/diagnostics.hpp"
50
51namespace toppers
52{
53 namespace oil
54 {
55 // ƒfƒoƒbƒO—pŠÖ”
56 void dump(boost::smatch *r)
57 {
58 unsigned int i;
59
60 for(i = 0 ; i < r->size() ; i++)
61 {
62 cout << "Match[" << i << "] : " << r->str(i) << endl;
63 }
64 }
65
66 namespace oil_implementation
67 {
68 int oil_object_impl::add_parameter(string param_name , string parameter_description)
69 {
70 if((parameter_description.find("UINT32") == 0)
71 || (parameter_description.find("UINT64") == 0))
72 {
73 this->params.push_back(
74 (object_parameter_impl *)(new parameter_uint_impl(param_name , parameter_description)));
75 }
76 else if((parameter_description.find("INT32") == 0)
77 || (parameter_description.find("INT64") == 0))
78 {
79 this->params.push_back(
80 (object_parameter_impl *)(new parameter_int_impl(param_name , parameter_description)));
81 }
82 else if(parameter_description.find("ENUM") == 0)
83 {
84 this->params.push_back(
85 (object_parameter_impl *)(new parameter_enum_impl(param_name , parameter_description)));
86 }
87 else if(parameter_description.find("BOOLEAN") == 0)
88 {
89 boost::regex bool_with_option("\\[\\s*TRUE");
90 string::const_iterator start = parameter_description.begin();
91 string::const_iterator end = parameter_description.end();
92
93 // [ TRUE , FALSE ]‚ª‚ ‚éê‡‚ÍENUM‚Æ“¯‚¶ˆµ‚¢A‚È‚¢ê‡‚ÍSTRING‚Æ“¯‚¶ˆµ‚¢‚Æ‚·‚é
94 if(regex_search(start , end , bool_with_option))
95 {
96 this->params.push_back(
97 (object_parameter_impl *)(new parameter_enum_impl(param_name , parameter_description)));
98 }
99 else
100 {
101 this->params.push_back(
102 (object_parameter_impl *)(new parameter_boolean_impl(param_name , parameter_description)));
103 }
104 }
105 else if(parameter_description.find("STRING") == 0)
106 {
107 this->params.push_back(
108 (object_parameter_impl *)(new parameter_string_impl(param_name , parameter_description)));
109 }
110 else if(parameter_description.find("FLOAT") == 0)
111 {
112 this->params.push_back(
113 (object_parameter_impl *)(new parameter_float_impl(param_name , parameter_description)));
114 }
115 else if(parameter_description.find("_TYPE") != string::npos)
116 {
117 this->params.push_back(
118 (object_parameter_impl *)(new parameter_object_ref_impl(param_name , parameter_description)));
119 }
120 else
121 {
122 // ‚ ‚肦‚È‚¢
123 }
124
125 return 0;
126 }
127
128 oil_object_impl::~oil_object_impl()
129 {
130 std::vector<object_parameter_impl*>::iterator p;
131
132 for(p = params.begin() ; p != params.end() ; p++)
133 {
134 delete (*p);
135 }
136 }
137
138 bool oil_object_impl::validate_object_parameter
139 (oil_definition::object_parameter_def *obj_param , bool *multiple ,
140 std::vector<object_ref> *references)
141 {
142 std::vector<object_parameter_impl*>::iterator match;
143 bool result = false;
144
145 // “¯‚¶–¼‘O‚ðŽ‚Âƒpƒ‰ƒ[ƒ^‚ª‚ ‚é‚©ŒŸõ
146 // ¦find_if‚¾‚ƃ_ƒEƒ“ƒLƒƒƒXƒg‚ÉŽ¸”s‚µ‚½
147 for(match = params.begin() ; match != params.end() ; match++)
148 {
149 if((*match)->validate_parameter_name(obj_param->get_parameter_name())
150 == true)
151 {
152 break;
153 }
154 }
155
156 // ƒpƒ‰ƒ[ƒ^‚Ì‘®«ƒ`ƒFƒbƒN
157 if(match != params.end())
158 {
159 parameter_object_ref_impl *ref_param;
160 parameter_enum_impl *enum_param;
161
162 ref_param = dynamic_cast<parameter_object_ref_impl*>(*match);
163 if(ref_param != NULL)
164 {
165 if(ref_param->validate_object_parameter(obj_param , references) == true)
166 {
167 *multiple = (*match)->get_multiple();
168 result = true;
169 }
170 }
171 else
172 {
173 // enum‚̏ꍇAŽq—v‘f‚ÅŽQÆ‚ªo‚Ä‚­‚é‰Â”\«‚ª‚ ‚é
174 enum_param = dynamic_cast<parameter_enum_impl*>(*match);
175 if(enum_param != NULL)
176 {
177 if(enum_param->validate_object_parameter(obj_param , references) == true)
178 {
179 *multiple = (*match)->get_multiple();
180 result = true;
181 }
182 else
183 {
184 // ƒGƒ‰[o—Í‚Ívalidate_object_parameter‚ōs‚Á‚Ä‚¢‚邽‚ß•s—vD
185 //toppers::error("Object %1%'s parameter %2% can't set %3%." ,
186 // obj_param->get_parent_name() , obj_param->get_parameter_name() , obj_param->get_value());
187 }
188 }
189 else
190 {
191 if((*match)->validate_object_parameter(obj_param) == true)
192 {
193 *multiple = (*match)->get_multiple();
194 result = true;
195 }
196 else
197 {
198 // ƒGƒ‰[o—Í‚Ívalidate_object_parameter‚ōs‚Á‚Ä‚¢‚邽‚ß•s—vD
199 //toppers::error("Object %1%'s parameter %2% can't set %3%." ,
200 // obj_param->get_parent_name() , obj_param->get_parameter_name() , obj_param->get_value());
201 }
202 }
203 }
204 }
205 else
206 {
207 // ƒGƒ‰[ˆ—
208 toppers::error("Object %1% can't define parameter %2%." ,
209 obj_param->get_parent_name() , obj_param->get_parameter_name());
210 }
211
212 return result;
213 }
214
215 // Šî–{ƒpƒ‰ƒ[ƒ^‚̃`ƒFƒbƒN
216 bool object_parameter_impl::validate_object_parameter
217 (oil_definition::object_parameter_def *obj , bool *auto_param)
218 {
219 // •¡”’è‹`‚̓IƒuƒWƒFƒNƒg‰ðÍ‘¤‚Å‚µ‚©s‚¦‚È‚¢
220 // ƒfƒtƒHƒ‹ƒg’è‹`‚©‚Ç‚¤‚©‚àƒIƒuƒWƒFƒNƒg‚Å‚µ‚©s‚¦‚È‚¢
221 set_parameter_type(obj);
222
223 // AUTO‘®«‚̃`ƒFƒbƒN
224 if(obj->get_value() == "AUTO")
225 {
226 if(assign_auto == false)
227 {
228 toppers::error("Object %1% : %2% can't use \"AUTO\"" ,
229 obj->get_parent_name().c_str() , obj->get_parameter_name().c_str());
230 return false;
231 }
232 else
233 {
234 *auto_param = true;
235 }
236 }
237 else
238 {
239 *auto_param = false;
240 }
241
242 return true;
243 }
244
245 template<typename T>
246 bool validate_number_paremeter
247 (VALUE_LIMIT_TYPE type ,T value , T min , T max , vector<T> *value_list)
248 {
249 bool result = true;
250
251 if(type == LIMIT_RANGE)
252 {
253 if((value < min) || (value > max))
254 {
255 result = false;
256 }
257 }
258 else if(type == LIMIT_LIST)
259 {
260 std::vector<T>::iterator p;
261
262 // ’l‚̃ŠƒXƒg‚É‘¶Ý‚·‚é‚©‚ðŒŸõ
263 p = find(value_list->begin() , value_list->end() , value);
264 if(p >= value_list->end())
265 {
266 result = false;
267 }
268 }
269 else
270 {
271 // ƒ`ƒFƒbƒN‚Í•K—v‚È‚¢
272 }
273
274 return result;
275 }
276
277 template<typename T>
278 void val2string(std::vector<T> *list , std::string *str)
279 {
280 std::vector<T>::iterator p;
281
282 for(p = list->begin() ; p != list->end() ; p++)
283 {
284 try
285 {
286 *str += boost::lexical_cast<string>(*p) + " , ";
287 }
288 catch( ... )
289 {
290 toppers::error("cast error");
291 }
292 }
293 }
294
295 bool parameter_int_impl::validate_object_parameter
296 (oil_definition::object_parameter_def *obj)
297 {
298 bool result = false , assign_auto;
299 __int64 value;
300
301 // Šî–{‘®«‚̃`ƒFƒbƒN
302 if(object_parameter_impl::validate_object_parameter(obj , &assign_auto)
303 == false)
304 {
305 return false;
306 }
307
308 // AUTOƒpƒ‰ƒ[ƒ^‚È‚ç‚·‚®‚É”²‚¯‚é
309 if(assign_auto == true)
310 {
311 return true;
312 }
313
314 // ’l‚É•ÏŠ·
315 if(obj->get_value().find("0x") != string::npos)
316 {
317 (void)sscanf_s(obj->get_value().c_str() , "0x%I64x" , &value);
318 }
319 else if(obj->get_value().find("0X") != string::npos)
320 {
321 (void)sscanf_s(obj->get_value().c_str() , "0X%I64x" , &value);
322 }
323 else
324 {
325 try
326 {
327 value = boost::lexical_cast<__int64>(obj->get_value());
328 }
329 catch(std::exception& exception)
330 {
331 toppers::error("%1%'s %2% is not INT16/INT32." ,
332 obj->get_parent_name() , obj->get_parameter_name());
333
334 return false;
335 }
336 }
337
338 if(validate_number_paremeter
339 (limit_type , value , min , max , &value_list) == false)
340 {
341 if(limit_type == LIMIT_RANGE)
342 {
343 toppers::error("Object %1%'s %2% is \"%3%\" not in range [%4% - %5%]" ,
344 obj->get_parent_name().c_str() , obj->get_parameter_name().c_str() ,
345 obj->get_value() , min , max);
346 }
347 else // if(limit_type == LIMIT_LIST)
348 {
349 std::string str;
350 val2string(&value_list , &str);
351
352 toppers::error("Object %1%'s %2% is \"%3%\" not in range [%4% - %5%]" ,
353 obj->get_parent_name().c_str() , obj->get_parameter_name().c_str() ,
354 obj->get_value() , min , max);
355 }
356 }
357 else
358 {
359 result = true;
360 }
361
362 return result;
363 }
364
365 void parameter_int_impl::set_parameter_type(oil_definition::object_parameter_def *obj)
366 {
367 obj->set_type(TYPE_INT);
368 }
369
370 bool parameter_uint_impl::validate_object_parameter
371 (oil_definition::object_parameter_def *obj)
372 {
373 bool result = false , assign_auto;
374 unsigned __int64 value;
375
376 // Šî–{‘®«‚̃`ƒFƒbƒN
377 if(object_parameter_impl::validate_object_parameter(obj , &assign_auto)
378 == false)
379 {
380 return false;
381 }
382
383 // AUTOƒpƒ‰ƒ[ƒ^‚È‚ç‚·‚®‚É”²‚¯‚é
384 if(assign_auto == true)
385 {
386 return true;
387 }
388
389 // ’l‚É•ÏŠ·
390 if(obj->get_value().find("0x") != string::npos)
391 {
392 (void)sscanf_s(obj->get_value().c_str() , "0x%I64x" , &value);
393 }
394 else if(obj->get_value().find("0X") != string::npos)
395 {
396 (void)sscanf_s(obj->get_value().c_str() , "0X%I64x" , &value);
397 }
398 else
399 {
400 try
401 {
402 value = boost::lexical_cast<unsigned __int64>(obj->get_value());
403 }
404 catch(std::exception& exception)
405 {
406 toppers::error("%1% : %2% is not UINT16/UINT32." ,
407 obj->get_parent_name() , obj->get_parameter_name());
408 return false;
409 }
410 }
411
412 if(validate_number_paremeter
413 (limit_type , value , min , max , &value_list) == false)
414 {
415 if(limit_type ==LIMIT_RANGE)
416 {
417 toppers::error("Object %1%'s %2% : %3% is not in range [%4% - %5%]" ,
418 obj->get_parent_name().c_str() , obj->get_parameter_name().c_str() ,
419 obj->get_value() , min , max);
420 }
421 else // if(limit_type == LIMIT_LIST)
422 {
423 std::string str;
424 val2string(&value_list , &str);
425
426 toppers::error("Object %1%'s %2% : %3% is not in range value list [%4%]" ,
427 obj->get_parent_name().c_str() , obj->get_parameter_name().c_str() ,
428 obj->get_value() , str);
429 }
430 }
431 else
432 {
433 result = true;
434 }
435
436 return result;
437 }
438
439 void parameter_uint_impl::set_parameter_type(oil_definition::object_parameter_def *obj)
440 {
441 obj->set_type(TYPE_UINT);
442 }
443
444 bool parameter_float_impl::validate_object_parameter
445 (oil_definition::object_parameter_def *obj)
446 {
447 bool result = false , assign_auto;
448 double value;
449
450 // Šî–{‘®«‚̃`ƒFƒbƒN
451 if(object_parameter_impl::validate_object_parameter(obj , &assign_auto)
452 == false)
453 {
454 return false;
455 }
456
457 // AUTOƒpƒ‰ƒ[ƒ^‚È‚ç‚·‚®‚É”²‚¯‚é
458 if(assign_auto == true)
459 {
460 return true;
461 }
462
463 // ’l‚É•ÏŠ·
464 try
465 {
466 value = boost::lexical_cast<double>(obj->get_value().c_str());
467 }
468 catch(std::exception& exception)
469 {
470 toppers::error("%1% : %2% is not FLOAT." ,
471 obj->get_parent_name() , obj->get_parameter_name());
472
473 return false;
474 }
475
476 if(validate_number_paremeter
477 (limit_type , value , min , max , &value_list) == false)
478 {
479 if(limit_type ==LIMIT_RANGE)
480 {
481 toppers::error("Object %1%'s %2% : %3% is not in range [%4% - %5%]" ,
482 obj->get_parent_name().c_str() , obj->get_parameter_name().c_str() ,
483 obj->get_value().c_str() , min , max);
484 }
485 else // if(limit_type == LIMIT_LIST)
486 {
487 std::string str;
488 val2string(&value_list , &str);
489
490 toppers::error("Object %1%' %2% : %3% is not in range value list [%4%]" ,
491 obj->get_parent_name().c_str() , obj->get_parameter_name().c_str() ,
492 obj->get_value().c_str() , str.c_str());
493 }
494 }
495 else
496 {
497 result = true;
498 }
499
500 return result;
501 }
502
503 void parameter_float_impl::set_parameter_type(oil_definition::object_parameter_def *obj)
504 {
505 obj->set_type(TYPE_FLOAT);
506 }
507
508 bool parameter_enum_impl::validate_object_parameter
509 (oil_definition::object_parameter_def *obj , std::vector<toppers::oil::object_ref> *object_refs)
510 {
511 std::map<std::string , oil_object_impl*>::iterator p;
512 bool result = true , assign_auto;
513
514 // Šî–{‘®«‚̃`ƒFƒbƒN
515 if(object_parameter_impl::validate_object_parameter(obj , &assign_auto)
516 == false)
517 {
518 return false;
519 }
520
521 // AUTOƒpƒ‰ƒ[ƒ^‚È‚ç‚·‚®‚É”²‚¯‚é
522 if(assign_auto == true)
523 {
524 return true;
525 }
526
527 // ƒpƒ‰ƒ[ƒ^‚ªENUM‚̃ŠƒXƒg‚É‚ ‚é‚©ŒŸõ(‘“–‚½‚èj
528 std::vector<oil_definition::object_definition*>::iterator s;
529 std::string str;
530 bool hit = false;
531
532 for(p = sub_params.begin() ; p != sub_params.end(); p++)
533 {
534 // ƒGƒ‰[ˆ——p‚̃ŠƒXƒg
535 str += (*p).first + " , ";
536 // ƒpƒ‰ƒ[ƒ^–¼‚ªˆê’v‚µ‚Ä‚¢‚È‚¯‚ê‚ΐæ‚̏ˆ—‚͍s‚í‚È‚¢
537 if(obj->get_value() == (*p).first)
538 {
539 hit = true;
540 }
541 }
542 // ƒŠƒXƒg‚É‚È‚©‚Á‚½ê‡‚̏ˆ—
543 if(hit == false)
544 {
545 toppers::error("Object %1%'s %2% : %3% is not in range [%4%]" ,
546 obj->get_parent_name().c_str() , obj->get_parameter_name().c_str() ,
547 obj->get_value().c_str() , str);
548
549 return false;
550 }
551
552 // ƒTƒuƒpƒ‰ƒ[ƒ^‚ɂ‚¢‚Ä‚àƒ`ƒFƒbƒN
553 for(s = obj->get_subparams()->begin() ; s != obj->get_subparams()->end() ; s++)
554 {
555 for(p = sub_params.begin() ; p != sub_params.end(); p++)
556 {
557 /* “¯–¼‚̐ݒè‚Ì’è‹`•”‚ðŒ©‚Â‚¯‚½‚çÄ‹A‚ÅŒŸ¸ */
558 if((*s)->get_parent()->get_value() == (*p).first)
559 {
560 if((*p).second->validate_object_configuration((*s) , object_refs) == true)
561 {
562 result = true;
563 }
564 }
565 }
566 if(result == true)
567 {
568 break;
569 }
570 }
571 // Œ©‚‚©‚ç‚È‚¯‚ê‚΃Gƒ‰[
572 if((obj->get_subparams()->empty() == false)
573 && (s == obj->get_subparams()->end()))
574 {
575 result = false;
576 }
577
578 return result;
579 }
580
581 bool parameter_object_ref_impl::validate_object_parameter
582 (oil_definition::object_parameter_def *obj , std::vector<toppers::oil::object_ref> *object_refs)
583 {
584 // Šî–{‘®«‚̃`ƒFƒbƒN
585 // ƒŠƒtƒ@ƒŒƒ“ƒXæ‚̃`ƒFƒbƒN‚à‚±‚±‚ōs‚¤‚ׂ«‚¾‚ªA
586 // ƒŠƒtƒ@ƒŒƒ“ƒXæ‚̃IƒuƒWƒFƒNƒgŽí—Þ‚ðŽæ“¾‚Å‚«‚È‚¢‚½‚ߌã‚ōs‚¤
587 if(object_parameter_impl::validate_object_parameter(obj , &assign_auto)
588 == false)
589 {
590 return false;
591 }
592
593 // ƒ`ƒFƒbƒN‚·‚é‚ׂ«ƒŠƒtƒ@ƒŒƒ“ƒX‚Ì‘ã“ü
594 object_ref ref = { reftype_name , obj->get_value() };
595 object_refs->push_back(ref);
596
597 return true;
598 }
599
600 void parameter_string_impl::set_parameter_type
601 (oil_definition::object_parameter_def *obj)
602 {
603 obj->set_type(TYPE_STRING);
604 }
605
606 void parameter_boolean_impl::set_parameter_type
607 (oil_definition::object_parameter_def *obj)
608 {
609 obj->set_type(TYPE_BOOLEAN);
610 }
611
612 void parameter_enum_impl::set_parameter_type(oil_definition::object_parameter_def *obj)
613 {
614 obj->set_type(TYPE_ENUM);
615 }
616
617 void parameter_object_ref_impl::set_parameter_type(oil_definition::object_parameter_def *obj)
618 {
619 obj->set_type(TYPE_REF);
620 }
621
622 bool oil_object_impl::validate_object_configuration
623 (oil_definition::object_definition * obj_def , std::vector<object_ref> *references)
624 {
625 std::vector<oil_definition::object_parameter_def*>::iterator p;
626 std::vector<oil_definition::object_parameter_def*> *obj_params;
627 std::vector<object_parameter_impl*>::iterator q;
628 std::vector<string> defined_parameter;
629 std::vector<object_parameter_impl*> undefined_parameter;
630 std::vector<string>::iterator found , s;
631 bool result = true;
632 bool multiple;
633
634 // ƒIƒuƒWƒFƒNƒg–¼‚ª‡‚Á‚Ä‚¢‚é‚©ƒ`ƒFƒbƒN
635 if(name != obj_def->get_object_type())
636 {
637 return false;
638 }
639
640 // ƒpƒ‰ƒ[ƒ^‚̐®‡«ƒ`ƒFƒbƒN
641 obj_params = obj_def->get_params();
642 for(p = obj_params->begin() ; p != obj_params->end() ; p++)
643 {
644 if(validate_object_parameter(*p , &multiple , references) == false)
645 {
646 result = false;
647 }
648
649 // •¡”’è‹`‰Â”\‚©‚̃`ƒFƒbƒN
650 if(((found = find(defined_parameter.begin() , defined_parameter.end() ,
651 (*p)->get_parameter_name())) != defined_parameter.end())
652 && (multiple == false))
653 {
654 toppers::error("Object %1% : %2% can define once." ,
655 obj_def->get_name().c_str() , (*p)->get_parameter_name().c_str());
656
657 result = false;
658 }
659 else
660 {
661 defined_parameter.push_back((*p)->get_parameter_name());
662 }
663 }
664
665 if(result == true)
666 {
667 //
668 // ƒfƒtƒHƒ‹ƒgƒpƒ‰ƒ[ƒ^‚̕⊮
669 //
670
671 // ƒIƒuƒWƒFƒNƒg’è‹`‚É‹LÚ‚³‚ê‚Ä‚¢‚È‚¢ƒpƒ‰ƒ[ƒ^‚Ì’Tõ
672 for(q = params.begin() ; q != params.end() ; q++)
673 {
674 s = find(defined_parameter.begin() ,
675 defined_parameter.end() , (*q)->get_name());
676
677 if(s == defined_parameter.end())
678 {
679 undefined_parameter.push_back((*q));
680 }
681 }
682
683 // ’Tõ‚µ‚½ƒpƒ‰ƒ[ƒ^‚ɑ΂µ‚ẴfƒtƒHƒ‹ƒgƒpƒ‰ƒ[ƒ^‚̕⊮
684 for(q = undefined_parameter.begin() ; q != undefined_parameter.end() ; q++)
685 {
686 string default_value;
687 DEFAULT_TYPE deftype = (*q)->get_default(&default_value);
688
689 if((deftype == HAVE_DEFAULT)
690 || (deftype == AUTO))
691 {
692 obj_def->add_parameter((*q)->get_name() , default_value);
693 }
694 else if(deftype == NO_DEFAULT)
695 {
696 toppers::error("Object %1% : Parmeter %2% is not defined. %2% doesn't have default value." ,
697 obj_def->get_name().c_str() , (*q)->get_name().c_str());
698
699 result = false;
700 }
701 else /* deftype == HAVE_NOT_DEFINE */
702 {
703 }
704
705 }
706 }
707
708 return result;
709 }
710
711 bool parameter_string_impl::validate_object_parameter
712 (oil_definition::object_parameter_def *obj)
713 {
714 // •¶Žš‘®«‚Í“Á‚ɐ§–ñ‚ª‚È‚¢‚½‚ߏí‚Étrue
715 return true;
716 }
717
718 bool parameter_boolean_impl::validate_object_parameter
719 (oil_definition::object_parameter_def *obj)
720 {
721 // TRUE‚©FALSE‚Å‚È‚¢‚Æ‚È‚ç‚È‚¢
722 if((obj->get_value() == "TRUE")
723 || (obj->get_value() == "FALSE"))
724 {
725 return true;
726 }
727
728 toppers::error("Object %1%'s %2% is \"%3%\" , but can not set [TRUE , FALSE , ]." ,
729 obj->get_parent_name() , obj->get_parameter_name() , obj->get_value());
730
731 return false;
732 }
733
734 void oil_object_impl::display_implementation(void)
735 {
736 std::vector<object_parameter_impl*>::iterator p;
737
738 cout << "=========== Object Name : " << name << "===========" << endl << endl;
739 for(p = params.begin() ; p != params.end() ; p++)
740 {
741 (*p)->display_implementation();
742 }
743 cout << endl << "==================================" << endl;
744
745 }
746
747 void object_parameter_impl::set_parameter_type
748 (oil_definition::object_parameter_def *obj)
749 {
750 obj->set_type(TYPE_UNKNOWN);
751 }
752 }
753
754 namespace oil_definition
755 {
756 object_definition* find_object(string name)
757 {
758 return NULL;
759 }
760
761 int object_definition::add_parameter(string param_name , string param_value)
762 {
763 try
764 {
765 object_parameter_def* param_def =
766 new object_parameter_def(param_name , param_value , name);
767 params.push_back(param_def);
768 }
769 catch(...)
770 {
771 // ƒGƒ‰[ˆ—
772 }
773
774 return 0;
775 }
776
777 object_definition::~object_definition()
778 {
779 std::vector<object_parameter_def*>::iterator p;
780
781 for(p = params.begin() ; p != params.end() ; p++)
782 {
783 delete (*p);
784 }
785 }
786
787 void object_definition::display_definition(void)
788 {
789 std::vector<object_parameter_def*>::iterator p;
790
791 for(p = params.begin() ; p != params.end() ; p++)
792 {
793 (*p)->display_definition();
794 }
795 cout << endl << endl;
796 }
797
798
799 /*!
800 * \brief ƒIƒuƒWƒFƒNƒgID”ԍ†‚ÌŠ„•t‚¯
801 * \param[in] api_map ƒ\[ƒX‚É‹Lq‚³‚ꂽÃ“IAPI‚ð“o˜^‚µ‚½ƒRƒ“ƒeƒi
802 */
803 void assign_id( cfg_obj_map obj_def_map , long fixed_id)
804 {
805 using namespace toppers;
806 using namespace toppers::oil::oil_definition;
807
808 std::map<std::string, std::vector< object_definition* >>::iterator p;
809 std::vector<object_definition*>::iterator q;
810 int serial;
811
812 for(p = obj_def_map.begin() ; p != obj_def_map.end() ; p++)
813 {
814 serial = 0;
815 // ƒIƒuƒWƒFƒNƒg‚²‚Æ‚ÉIDŠ„“–‚Ä
816 for(q = (*p).second.begin() ; q != (*p).second.end() ; q++)
817 {
818 if(fixed_id == UINT_MAX)
819 {
820 (*q)->set_id(serial++);
821 }
822 else
823 {
824 (*q)->set_id(fixed_id);
825 }
826 }
827 }
828
829 }
830
831 cfg_obj_map merge(std::vector<object_definition*> *obj_defs ,
832 cfg_obj_map& out , string prefix , string suffix , long fixed_id)
833 {
834 std::vector<object_definition*>::iterator p , q;
835 std::vector<object_definition*> *sub_objects;
836 std::vector<object_parameter_def*>::iterator r;
837 std::vector<object_parameter_def*> *subparams;
838
839 for(p = obj_defs->begin() ; p != obj_defs->end() ; p++)
840 {
841 string s(prefix + (*p)->get_object_type() + suffix);
842 out[ s ].push_back(*p);
843 }
844
845 // ID‚ðˆê“xŠ„•t‚¯‚é
846 assign_id(out , fixed_id);
847
848 for(p = obj_defs->begin() ; p != obj_defs->end() ; p++)
849 {
850 long id;
851 subparams = (*p)->get_params();
852 // ƒTƒuƒpƒ‰ƒ[ƒ^‚à“o˜^
853 for(r = subparams->begin() ; r != subparams->end() ; r++)
854 {
855 sub_objects = (*r)->get_subparams();
856 id = (*p)->get_id();
857
858 string s = "." + (*r)->get_value();
859
860 // ƒTƒuƒpƒ‰ƒ[ƒ^‚ÌŽ‚‘®«‚͍ċA‚Å“o˜^‚·‚é
861 if(sub_objects->empty() == false)
862 {
863 cfg_obj_map temp;
864 std::string subparam_name =
865 (*p)->get_object_type() + ".";
866 temp = merge(sub_objects , temp , subparam_name , s , id);
867
868 // Œ‹‰Ê‚ðƒRƒs[(‚¿‚傤‚Ç‚¢‚¢ƒƒ\ƒbƒh‚ª–³‚¢)
869 std::map< std::string, std::vector< object_definition* >>::iterator x;
870 for(x = temp.begin() ; x != temp.end() ; x++ )
871 {
872 std::vector< object_definition* >::iterator y;
873 for(y = (*x).second.begin() ; y != (*x).second.end() ; y++)
874 {
875 out[(*x).first].push_back((*y));
876 }
877 //out[(*x).first] = (*x).second;
878 //out[(*x).first].push_back((*x).second);
879 }
880 }
881 }
882 }
883
884 return out;
885 }
886 }
887 } /* oil */
888
889}
Note: See TracBrowser for help on using the repository browser.