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

Method CScriptArray

sdk/add_on/scriptarray/scriptarray.cpp:405–496  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

403}
404
405CScriptArray::CScriptArray(asITypeInfo *ti, void *buf)
406{
407 // The object type should be the template instance of the array
408 assert( ti && string(ti->GetName()) == "array" );
409
410 refCount = 1;
411 gcFlag = false;
412 objType = ti;
413 objType->AddRef();
414 buffer = 0;
415
416 Precache();
417
418 asIScriptEngine *engine = ti->GetEngine();
419
420 // Determine element size
421 if( subTypeId & asTYPEID_MASK_OBJECT )
422 elementSize = sizeof(asPWORD);
423 else
424 elementSize = engine->GetSizeOfPrimitiveType(subTypeId);
425
426 // Determine the initial size from the buffer
427 asUINT length = *(asUINT*)buf;
428
429 // Make sure the array size isn't too large for us to handle
430 if( !CheckMaxSize(length) )
431 {
432 // Don't continue with the initialization
433 return;
434 }
435
436 // Copy the values of the array elements from the buffer
437 if( (ti->GetSubTypeId() & asTYPEID_MASK_OBJECT) == 0 )
438 {
439 CreateBuffer(&buffer, length);
440
441 // Copy the values of the primitive type into the internal buffer
442 if( length > 0 )
443 memcpy(At(0), (((asUINT*)buf)+1), length * elementSize);
444 }
445 else if( ti->GetSubTypeId() & asTYPEID_OBJHANDLE )
446 {
447 CreateBuffer(&buffer, length);
448
449 // Copy the handles into the internal buffer
450 if( length > 0 )
451 memcpy(At(0), (((asUINT*)buf)+1), length * elementSize);
452
453 // With object handles it is safe to clear the memory in the received buffer
454 // instead of increasing the ref count. It will save time both by avoiding the
455 // call the increase ref, and also relieve the engine from having to release
456 // its references too
457 memset((((asUINT*)buf)+1), 0, length * elementSize);
458 }
459 else if( ti->GetSubType()->GetFlags() & asOBJ_REF )
460 {
461 // Only allocate the buffer, but not the objects
462 subTypeId |= asTYPEID_OBJHANDLE;

Callers

nothing calls this directly

Calls 10

GetFlagsMethod · 0.80
AssignScriptObjectMethod · 0.80
GetNameMethod · 0.45
AddRefMethod · 0.45
GetEngineMethod · 0.45
GetSubTypeIdMethod · 0.45
GetSubTypeMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected