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

Method asCScriptObject

sdk/angelscript/source/as_scriptobject.cpp:335–391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

333}
334
335asCScriptObject::asCScriptObject(asCObjectType *ot, bool doInitialize)
336{
337 refCount.set(1);
338 objType = ot;
339 objType->AddRef();
340 isDestructCalled = false;
341 extra = 0;
342 hasRefCountReachedZero = false;
343
344 // Notify the garbage collector of this object
345 if( objType->flags & asOBJ_GC )
346 objType->engine->gc.AddScriptObjectToGC(this, objType);
347
348 // Initialize members to zero. Technically we only need to zero the pointer
349 // members, but just the memset is faster than having to loop and check the datatypes
350 memset((void*)(this+1), 0, objType->size - sizeof(asCScriptObject));
351
352 if( doInitialize )
353 {
354#ifdef AS_NO_MEMBER_INIT
355 // When member initialization is disabled the constructor must make sure
356 // to allocate and initialize all members with the default constructor
357 for( asUINT n = 0; n < objType->properties.GetLength(); n++ )
358 {
359 asCObjectProperty *prop = objType->properties[n];
360 if( prop->type.IsObject() && !prop->type.IsObjectHandle() )
361 {
362 if( prop->type.IsReference() || prop->type.GetTypeInfo()->flags & asOBJ_REF )
363 {
364 asPWORD *ptr = reinterpret_cast<asPWORD*>(reinterpret_cast<asBYTE*>(this) + prop->byteOffset);
365 if( prop->type.GetTypeInfo()->flags & asOBJ_SCRIPT_OBJECT )
366 *ptr = (asPWORD)ScriptObjectFactory(prop->type.GetTypeInfo(), ot->engine);
367 else
368 *ptr = (asPWORD)AllocateUninitializedObject(prop->type.GetTypeInfo(), ot->engine);
369 }
370 }
371 }
372#endif
373 }
374 else
375 {
376 // When the object is created without initialization, all non-handle members must be allocated, but not initialized
377 asCScriptEngine *engine = objType->engine;
378 for( asUINT n = 0; n < objType->properties.GetLength(); n++ )
379 {
380 asCObjectProperty *prop = objType->properties[n];
381 if( prop->type.IsObject() && !prop->type.IsObjectHandle() )
382 {
383 if( prop->type.IsReference() || (prop->type.GetTypeInfo()->flags & asOBJ_REF) )
384 {
385 asPWORD *ptr = reinterpret_cast<asPWORD*>(reinterpret_cast<asBYTE*>(this) + prop->byteOffset);
386 *ptr = (asPWORD)AllocateUninitializedObject(CastToObjectType(prop->type.GetTypeInfo()), engine);
387 }
388 }
389 }
390 }
391}
392

Callers

nothing calls this directly

Calls 9

CastToObjectTypeFunction · 0.85
setMethod · 0.80
AddScriptObjectToGCMethod · 0.80
IsObjectMethod · 0.80
IsObjectHandleMethod · 0.80
GetTypeInfoMethod · 0.80
AddRefMethod · 0.45
GetLengthMethod · 0.45
IsReferenceMethod · 0.45

Tested by

no test coverage detected