| 901 | //----------------------------------------------------------------------------- |
| 902 | |
| 903 | void SimObject::assignFieldsFrom(SimObject *parent) |
| 904 | { |
| 905 | // Only allow field assigns from objects of the same class or |
| 906 | // a superclass. |
| 907 | |
| 908 | if( getClassRep()->isClass( parent->getClassRep() ) ) |
| 909 | { |
| 910 | const AbstractClassRep::FieldList &list = parent->getFieldList(); |
| 911 | |
| 912 | // copy out all the fields: |
| 913 | for(U32 i = 0; i < list.size(); i++) |
| 914 | { |
| 915 | const AbstractClassRep::Field* f = &list[i]; |
| 916 | |
| 917 | if (f->pFieldname == StringTable->insert("docsURL")) |
| 918 | continue; |
| 919 | |
| 920 | // Skip the special field types. |
| 921 | if ( f->type >= AbstractClassRep::ARCFirstCustomField ) |
| 922 | continue; |
| 923 | |
| 924 | // Skip certain fields that we don't want to see copied so we don't |
| 925 | // get error messages from their setters. |
| 926 | |
| 927 | static StringTableEntry sName = StringTable->insert( "name" ); |
| 928 | static StringTableEntry sPersistentId = StringTable->insert( "persistentId" ); |
| 929 | |
| 930 | if( f->pFieldname == sName || f->pFieldname == sPersistentId ) |
| 931 | continue; |
| 932 | |
| 933 | S32 lastField = f->elementCount - 1; |
| 934 | for(S32 j = 0; j <= lastField; j++) |
| 935 | { |
| 936 | const char* fieldVal = (*f->getDataFn)( parent, Con::getData(f->type, (void *) (((const char *)parent) + f->offset), j, f->table, f->flag)); |
| 937 | |
| 938 | // Don't assign the field is the pointer is null or if |
| 939 | // the field is not empty and writing it was disallowed. |
| 940 | if ( !fieldVal || ( fieldVal[0] && !writeField( f->pFieldname, fieldVal ) ) ) |
| 941 | continue; |
| 942 | |
| 943 | // code copied from SimObject::setDataField(). |
| 944 | // TODO: paxorr: abstract this into a better setData / getData that considers prot fields. |
| 945 | FrameTemp<char> buffer(2048); |
| 946 | FrameTemp<char> bufferSecure(2048); // This buffer is used to make a copy of the data |
| 947 | ConsoleBaseType *cbt = ConsoleBaseType::getType( f->type ); |
| 948 | const char* szBuffer = cbt->prepData( fieldVal, buffer, 2048 ); |
| 949 | dMemset( bufferSecure, 0, 2048 ); |
| 950 | dMemcpy( bufferSecure, szBuffer, dStrlen( szBuffer ) ); |
| 951 | |
| 952 | //If we have an index worth mentioning, process it for pass-along as well to ensure we set stuff correctly |
| 953 | char* elementIdxBuffer = nullptr; |
| 954 | if (f->elementCount > 1) |
| 955 | { |
| 956 | elementIdxBuffer = Con::getArgBuffer(256); |
| 957 | dSprintf(elementIdxBuffer, 256, "%i", j); |
| 958 | } |
| 959 | |
| 960 | if((*f->setDataFn)( this, elementIdxBuffer, bufferSecure ) ) |
no test coverage detected