----------------------------------------------------------------------------- Parse an XML file containing program options -----------------------------------------------------------------------------
| 498 | // Parse an XML file containing program options |
| 499 | //----------------------------------------------------------------------------- |
| 500 | bool Options::ParseOptionsXML |
| 501 | ( |
| 502 | string const& _filename |
| 503 | ) |
| 504 | { |
| 505 | TiXmlDocument doc; |
| 506 | if( !doc.LoadFile( _filename.c_str(), TIXML_ENCODING_UTF8 ) ) |
| 507 | { |
| 508 | Log::Write(LogLevel_Warning, "Failed to Parse %s: %s", _filename.c_str(), doc.ErrorDesc()); |
| 509 | return false; |
| 510 | } |
| 511 | doc.SetUserData((void *)_filename.c_str()); |
| 512 | Log::Write(LogLevel_Info, "Reading %s for Options", _filename.c_str()); |
| 513 | |
| 514 | TiXmlElement const* optionsElement = doc.RootElement(); |
| 515 | |
| 516 | // Read the options |
| 517 | TiXmlElement const* optionElement = optionsElement->FirstChildElement(); |
| 518 | while( optionElement ) |
| 519 | { |
| 520 | char const* str = optionElement->Value(); |
| 521 | if( str && !strcmp( str, "Option" ) ) |
| 522 | { |
| 523 | char const* name = optionElement->Attribute( "name" ); |
| 524 | if( name ) |
| 525 | { |
| 526 | Option* option = Find( name ); |
| 527 | if( option ) |
| 528 | { |
| 529 | char const* value = optionElement->Attribute( "value" ); |
| 530 | if( value ) |
| 531 | { |
| 532 | // Set the value |
| 533 | option->SetValueFromString( value ); |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | optionElement = optionElement->NextSiblingElement(); |
| 540 | } |
| 541 | |
| 542 | return true; |
| 543 | } |
| 544 | |
| 545 | //----------------------------------------------------------------------------- |
| 546 | // <Options::AddOption> |
nothing calls this directly
no test coverage detected