----------------------------------------------------------------------------- Set attribute of top stack element to given value. -----------------------------------------------------------------------------
| 787 | // Set attribute of top stack element to given value. |
| 788 | // ----------------------------------------------------------------------------- |
| 789 | void SimXMLDocument::setObjectAttributes(const char* objectID) |
| 790 | { |
| 791 | if( !objectID || !objectID[0] ) |
| 792 | return; |
| 793 | |
| 794 | if(m_paNode.empty()) |
| 795 | return; |
| 796 | |
| 797 | SimObject *pObject = Sim::findObject( objectID ); |
| 798 | |
| 799 | if( pObject == NULL ) |
| 800 | return; |
| 801 | |
| 802 | const S32 iLastElement = m_paNode.size() - 1; |
| 803 | TiXmlElement* pElement = m_paNode[iLastElement]; |
| 804 | if(!pElement) |
| 805 | return; |
| 806 | |
| 807 | char textbuf[1024]; |
| 808 | TiXmlElement field( "Field" ); |
| 809 | TiXmlElement group( "FieldGroup" ); |
| 810 | pElement->SetAttribute( "Name", pObject->getName() ); |
| 811 | |
| 812 | |
| 813 | // Iterate over our filed list and add them to the XML document... |
| 814 | AbstractClassRep::FieldList fieldList = pObject->getFieldList(); |
| 815 | AbstractClassRep::FieldList::iterator itr; |
| 816 | for(itr = fieldList.begin(); itr != fieldList.end(); itr++) |
| 817 | { |
| 818 | |
| 819 | if( itr->type == AbstractClassRep::DeprecatedFieldType || |
| 820 | itr->type == AbstractClassRep::StartGroupFieldType || |
| 821 | itr->type == AbstractClassRep::EndGroupFieldType) continue; |
| 822 | |
| 823 | // Not an Array |
| 824 | if(itr->elementCount == 1) |
| 825 | { |
| 826 | // get the value of the field as a string. |
| 827 | ConsoleBaseType *cbt = ConsoleBaseType::getType(itr->type); |
| 828 | |
| 829 | const char *val = Con::getData(itr->type, (void *) (((const char *)pObject) + itr->offset), 0, itr->table, itr->flag); |
| 830 | |
| 831 | // Make a copy for the field check. |
| 832 | if (!val) |
| 833 | continue; |
| 834 | |
| 835 | FrameTemp<char> valCopy( dStrlen( val ) + 1 ); |
| 836 | dStrcpy( (char *)valCopy, val ); |
| 837 | |
| 838 | if (!pObject->writeField(itr->pFieldname, valCopy)) |
| 839 | continue; |
| 840 | |
| 841 | val = valCopy; |
| 842 | |
| 843 | |
| 844 | expandEscape(textbuf, val); |
| 845 | |
| 846 | if( !pObject->writeField( itr->pFieldname, textbuf ) ) |
no test coverage detected