internal
| 894 | |
| 895 | // internal |
| 896 | int asCScriptObject::CopyFromAs(const asCScriptObject *other, asCObjectType *in_objType) |
| 897 | { |
| 898 | if( other != this ) |
| 899 | { |
| 900 | if( !other->objType->DerivesFrom(in_objType) ) |
| 901 | { |
| 902 | // We cannot allow a value assignment from a type that isn't the same or |
| 903 | // derives from this type as the member properties may not have the same layout |
| 904 | asIScriptContext *ctx = asGetActiveContext(); |
| 905 | ctx->SetException(TXT_MISMATCH_IN_VALUE_ASSIGN); |
| 906 | return asERROR; |
| 907 | } |
| 908 | |
| 909 | // If the script class implements the opAssign method, it should be called |
| 910 | asCScriptEngine *engine = in_objType->engine; |
| 911 | asCScriptFunction *func = engine->scriptFunctions[in_objType->beh.copy]; |
| 912 | if( func->funcType == asFUNC_SYSTEM ) |
| 913 | { |
| 914 | // If derived, use the base class' assignment operator to copy the inherited |
| 915 | // properties. Then only copy new properties for the derived class |
| 916 | if( in_objType->derivedFrom ) |
| 917 | CopyFromAs(other, in_objType->derivedFrom); |
| 918 | |
| 919 | for( asUINT n = in_objType->derivedFrom ? in_objType->derivedFrom->properties.GetLength() : 0; |
| 920 | n < in_objType->properties.GetLength(); |
| 921 | n++ ) |
| 922 | { |
| 923 | asCObjectProperty *prop = in_objType->properties[n]; |
| 924 | if( prop->type.IsObject() ) |
| 925 | { |
| 926 | void **dst = (void**)(((char*)this) + prop->byteOffset); |
| 927 | void **src = (void**)(((char*)other) + prop->byteOffset); |
| 928 | if( !prop->type.IsObjectHandle() ) |
| 929 | { |
| 930 | if( prop->type.IsReference() || (prop->type.GetTypeInfo()->flags & asOBJ_REF) ) |
| 931 | CopyObject(*src, *dst, CastToObjectType(prop->type.GetTypeInfo()), engine); |
| 932 | else |
| 933 | CopyObject(src, dst, CastToObjectType(prop->type.GetTypeInfo()), engine); |
| 934 | } |
| 935 | else |
| 936 | CopyHandle((asPWORD*)src, (asPWORD*)dst, CastToObjectType(prop->type.GetTypeInfo()), engine); |
| 937 | } |
| 938 | else if (prop->type.IsFuncdef()) |
| 939 | { |
| 940 | asCScriptFunction **dst = (asCScriptFunction**)(((char*)this) + prop->byteOffset); |
| 941 | asCScriptFunction **src = (asCScriptFunction**)(((char*)other) + prop->byteOffset); |
| 942 | if (*dst) |
| 943 | (*dst)->Release(); |
| 944 | *dst = *src; |
| 945 | if (*dst) |
| 946 | (*dst)->AddRef(); |
| 947 | } |
| 948 | else |
| 949 | { |
| 950 | void *dst = ((char*)this) + prop->byteOffset; |
| 951 | void *src = ((char*)other) + prop->byteOffset; |
| 952 | memcpy(dst, src, prop->type.GetSizeInMemoryBytes()); |
| 953 | } |
nothing calls this directly
no test coverage detected