MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / assignFieldsFrom

Method assignFieldsFrom

Engine/source/console/simObject.cpp:841–900  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

839//-----------------------------------------------------------------------------
840
841void 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

Callers 11

cloneMethod · 0.80
simObject.cppFile · 0.80
execMethod · 0.80

Calls 13

getDataFunction · 0.85
getTypeFunction · 0.85
setDataFunction · 0.85
errorfFunction · 0.85
getClassRepMethod · 0.80
prepDataMethod · 0.80
dMemsetFunction · 0.50
dMemcpyFunction · 0.50
dStrlenFunction · 0.50
isClassMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected