----------------------------------------------------------------------------- Set attribute of top stack element to given value. -----------------------------------------------------------------------------
| 502 | // Set attribute of top stack element to given value. |
| 503 | // ----------------------------------------------------------------------------- |
| 504 | void SimXMLDocument::setObjectAttributes(const char* objectID) |
| 505 | { |
| 506 | if( !objectID || !objectID[0] ) |
| 507 | return; |
| 508 | |
| 509 | if(m_paNode.empty()) |
| 510 | return; |
| 511 | |
| 512 | SimObject *pObject = Sim::findObject( objectID ); |
| 513 | |
| 514 | if( pObject == NULL ) |
| 515 | return; |
| 516 | |
| 517 | const int iLastElement = m_paNode.size() - 1; |
| 518 | TiXmlElement* pElement = m_paNode[iLastElement]; |
| 519 | if(!pElement) |
| 520 | return; |
| 521 | |
| 522 | char textbuf[1024]; |
| 523 | TiXmlElement field( "Field" ); |
| 524 | TiXmlElement group( "FieldGroup" ); |
| 525 | pElement->SetAttribute( "Name", pObject->getName() ); |
| 526 | |
| 527 | |
| 528 | // Iterate over our filed list and add them to the XML document... |
| 529 | AbstractClassRep::FieldList fieldList = pObject->getFieldList(); |
| 530 | AbstractClassRep::FieldList::iterator itr; |
| 531 | for(itr = fieldList.begin(); itr != fieldList.end(); itr++) |
| 532 | { |
| 533 | |
| 534 | if( itr->type == AbstractClassRep::DepricatedFieldType || |
| 535 | itr->type == AbstractClassRep::StartGroupFieldType || |
| 536 | itr->type == AbstractClassRep::EndGroupFieldType) continue; |
| 537 | |
| 538 | // Not an Array |
| 539 | if(itr->elementCount == 1) |
| 540 | { |
| 541 | // get the value of the field as a string. |
| 542 | ConsoleBaseType *cbt = ConsoleBaseType::getType(itr->type); |
| 543 | |
| 544 | const char *val = Con::getData(itr->type, (void *) (((const char *)pObject) + itr->offset), 0, itr->table, itr->flag); |
| 545 | |
| 546 | // Make a copy for the field check. |
| 547 | if (!val) |
| 548 | continue; |
| 549 | |
| 550 | FrameTemp<char> valCopy( dStrlen( val ) + 1 ); |
| 551 | dStrcpy( (char *)valCopy, val ); |
| 552 | |
| 553 | if (!pObject->writeField(itr->pFieldname, valCopy)) |
| 554 | continue; |
| 555 | |
| 556 | val = valCopy; |
| 557 | |
| 558 | |
| 559 | expandEscape(textbuf, val); |
| 560 | |
| 561 | if( !pObject->writeField( itr->pFieldname, textbuf ) ) |
no test coverage detected