| 839 | //----------------------------------------------------------------------------- |
| 840 | |
| 841 | void SimObject::assignFieldsFrom(SimObject *parent) |
| 842 | { |
| 843 | // Only allow field assigns from objects of the same class or |
| 844 | // a superclass. |
| 845 | |
| 846 | if( getClassRep()->isClass( parent->getClassRep() ) ) |
| 847 | { |
| 848 | const AbstractClassRep::FieldList &list = parent->getFieldList(); |
| 849 | |
| 850 | // copy out all the fields: |
| 851 | for(U32 i = 0; i < list.size(); i++) |
| 852 | { |
| 853 | const AbstractClassRep::Field* f = &list[i]; |
| 854 | |
| 855 | // Skip the special field types. |
| 856 | if ( f->type >= AbstractClassRep::ARCFirstCustomField ) |
| 857 | continue; |
| 858 | |
| 859 | // Skip certain fields that we don't want to see copied so we don't |
| 860 | // get error messages from their setters. |
| 861 | |
| 862 | static StringTableEntry sName = StringTable->insert( "name" ); |
| 863 | static StringTableEntry sPersistentId = StringTable->insert( "persistentId" ); |
| 864 | |
| 865 | if( f->pFieldname == sName || f->pFieldname == sPersistentId ) |
| 866 | continue; |
| 867 | |
| 868 | S32 lastField = f->elementCount - 1; |
| 869 | for(S32 j = 0; j <= lastField; j++) |
| 870 | { |
| 871 | const char* fieldVal = (*f->getDataFn)( parent, Con::getData(f->type, (void *) (((const char *)parent) + f->offset), j, f->table, f->flag)); |
| 872 | |
| 873 | // Don't assign the field is the pointer is null or if |
| 874 | // the field is not empty and writing it was disallowed. |
| 875 | if ( !fieldVal || ( fieldVal[0] && !writeField( f->pFieldname, fieldVal ) ) ) |
| 876 | continue; |
| 877 | |
| 878 | // code copied from SimObject::setDataField(). |
| 879 | // TODO: paxorr: abstract this into a better setData / getData that considers prot fields. |
| 880 | FrameTemp<char> buffer(2048); |
| 881 | FrameTemp<char> bufferSecure(2048); // This buffer is used to make a copy of the data |
| 882 | ConsoleBaseType *cbt = ConsoleBaseType::getType( f->type ); |
| 883 | const char* szBuffer = cbt->prepData( fieldVal, buffer, 2048 ); |
| 884 | dMemset( bufferSecure, 0, 2048 ); |
| 885 | dMemcpy( bufferSecure, szBuffer, dStrlen( szBuffer ) ); |
| 886 | |
| 887 | if((*f->setDataFn)( this, NULL, bufferSecure ) ) |
| 888 | Con::setData(f->type, (void *) (((const char *)this) + f->offset), j, 1, &fieldVal, f->table); |
| 889 | } |
| 890 | } |
| 891 | } |
| 892 | else |
| 893 | { |
| 894 | Con::errorf( "SimObject::assignFieldsFrom() - cannot assigned fields from object of type '%s' to object of type '%s'", |
| 895 | parent->getClassName(), getClassName() |
| 896 | ); |
| 897 | } |
| 898 |
no test coverage detected