MCPcopy Create free account
hub / github.com/anjo76/angelscript / CopyBuffer

Method CopyBuffer

sdk/add_on/scriptarray/scriptarray.cpp:1697–1775  ·  view source on GitHub ↗

internal

Source from the content-addressed store, hash-verified

1695
1696// internal
1697void CScriptArray::CopyBuffer(SArrayBuffer *dst, SArrayBuffer *src)
1698{
1699 asIScriptEngine *engine = objType->GetEngine();
1700 if( subTypeId & asTYPEID_OBJHANDLE )
1701 {
1702 // Copy the references and increase the reference counters
1703 if( dst->numElements > 0 && src->numElements > 0 )
1704 {
1705 int count = dst->numElements > src->numElements ? src->numElements : dst->numElements;
1706
1707 void **max = (void**)(dst->data + count * sizeof(void*));
1708 void **d = (void**)dst->data;
1709 void **s = (void**)src->data;
1710
1711 for( ; d < max; d++, s++ )
1712 {
1713 void *tmp = *d;
1714 *d = *s;
1715 if( *d )
1716 engine->AddRefScriptObject(*d, objType->GetSubType());
1717 // Release the old ref after incrementing the new to avoid problem incase it is the same ref
1718 if( tmp )
1719 engine->ReleaseScriptObject(tmp, objType->GetSubType());
1720 }
1721 }
1722 }
1723 else
1724 {
1725 if( dst->numElements > 0 && src->numElements > 0 )
1726 {
1727 int count = dst->numElements > src->numElements ? src->numElements : dst->numElements;
1728 if( subTypeId & asTYPEID_MASK_OBJECT )
1729 {
1730 // Call the assignment operator on all of the objects
1731 void **max = (void**)(dst->data + count * sizeof(void*));
1732 void **d = (void**)dst->data;
1733 void **s = (void**)src->data;
1734
1735 asITypeInfo *subType = objType->GetSubType();
1736 if (subType->GetFlags() & asOBJ_ASHANDLE)
1737 {
1738 // For objects that should work as handles we must use the opHndlAssign method
1739 // TODO: Must support alternative syntaxes as well
1740 // TODO: Move the lookup of the opHndlAssign method to Precache() so it is only done once
1741 string decl = string(subType->GetName()) + "& opHndlAssign(const " + string(subType->GetName()) + "&in)";
1742 asIScriptFunction *func = subType->GetMethodByDecl(decl.c_str());
1743 if (func)
1744 {
1745 // TODO: Reuse active context if existing
1746 asIScriptContext* ctx = engine->RequestContext();
1747 for (; d < max; d++, s++)
1748 {
1749 ctx->Prepare(func);
1750 ctx->SetObject(*d);
1751 ctx->SetArgAddress(0, *s);
1752 // TODO: Handle errors
1753 ctx->Execute();
1754 }

Callers

nothing calls this directly

Calls 14

AddRefScriptObjectMethod · 0.80
ReleaseScriptObjectMethod · 0.80
GetFlagsMethod · 0.80
RequestContextMethod · 0.80
SetObjectMethod · 0.80
SetArgAddressMethod · 0.80
ExecuteMethod · 0.80
ReturnContextMethod · 0.80
AssignScriptObjectMethod · 0.80
GetEngineMethod · 0.45
GetSubTypeMethod · 0.45
GetNameMethod · 0.45

Tested by

no test coverage detected