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

Method RefCastObject

sdk/angelscript/source/as_scriptengine.cpp:5241–5355  ·  view source on GitHub ↗

interface

Source from the content-addressed store, hash-verified

5239
5240// interface
5241int asCScriptEngine::RefCastObject(void *obj, asITypeInfo *fromType, asITypeInfo *toType, void **newPtr, bool useOnlyImplicitCast)
5242{
5243 if( newPtr == 0 ) return asINVALID_ARG;
5244 *newPtr = 0;
5245
5246 if( fromType == 0 || toType == 0 ) return asINVALID_ARG;
5247
5248 // A null-pointer can always be cast to another type, so it will always be successful
5249 if( obj == 0 )
5250 return asSUCCESS;
5251
5252 if( fromType == toType )
5253 {
5254 *newPtr = obj;
5255 AddRefScriptObject(*newPtr, toType);
5256 return asSUCCESS;
5257 }
5258
5259 // Check for funcdefs
5260 if ((fromType->GetFlags() & asOBJ_FUNCDEF) && (toType->GetFlags() & asOBJ_FUNCDEF))
5261 {
5262 asCFuncdefType *fromFunc = CastToFuncdefType(reinterpret_cast<asCTypeInfo*>(fromType));
5263 asCFuncdefType *toFunc = CastToFuncdefType(reinterpret_cast<asCTypeInfo*>(toType));
5264
5265 if (fromFunc && toFunc && fromFunc->funcdef->IsSignatureExceptNameEqual(toFunc->funcdef))
5266 {
5267 *newPtr = obj;
5268 AddRefScriptObject(*newPtr, toType);
5269 return asSUCCESS;
5270 }
5271
5272 return asSUCCESS;
5273 }
5274
5275 // Look for ref cast behaviours
5276 asCScriptFunction *universalCastFunc = 0;
5277 asCObjectType *from = CastToObjectType(reinterpret_cast< asCTypeInfo*>(fromType));
5278 if( from == 0 ) return asINVALID_ARG;
5279 for( asUINT n = 0; n < from->methods.GetLength(); n++ )
5280 {
5281 asCScriptFunction *func = scriptFunctions[from->methods[n]];
5282 if( func->name == "opImplCast" ||
5283 (!useOnlyImplicitCast && func->name == "opCast") )
5284 {
5285 if( func->returnType.GetTypeInfo() == toType )
5286 {
5287 *newPtr = CallObjectMethodRetPtr(obj, func->id);
5288 // The ref cast behaviour returns a handle with incremented
5289 // ref counter, so there is no need to call AddRef explicitly
5290 // unless the function is registered with autohandle
5291 if( func->sysFuncIntf->returnAutoHandle )
5292 AddRefScriptObject(*newPtr, toType);
5293 return asSUCCESS;
5294 }
5295 else if( func->returnType.GetTokenType() == ttVoid &&
5296 func->parameterTypes.GetLength() == 1 &&
5297 func->parameterTypes[0].GetTokenType() == ttQuestion )
5298 {

Callers 6

GetMethod · 0.80
CastMethod · 0.80
RetrieveMethod · 0.80
TestFunction · 0.80
opCastMethod · 0.80
opConvMethod · 0.80

Calls 15

CastToFuncdefTypeFunction · 0.85
CastToObjectTypeFunction · 0.85
GetFlagsMethod · 0.80
GetTypeInfoMethod · 0.80
GetTokenTypeMethod · 0.80
SetObjectMethod · 0.80
SetArgVarTypeMethod · 0.80
ExecuteMethod · 0.80
GetLengthMethod · 0.45
PrepareMethod · 0.45
GetTypeIdMethod · 0.45

Tested by 3

TestFunction · 0.64
opCastMethod · 0.64
opConvMethod · 0.64