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

Method Sort

sdk/add_on/scriptarray/scriptarray.cpp:1462–1614  ·  view source on GitHub ↗

internal

Source from the content-addressed store, hash-verified

1460
1461// internal
1462void CScriptArray::Sort(asUINT startAt, asUINT count, bool asc)
1463{
1464 // Subtype isn't primitive and doesn't have opCmp
1465 SArrayCache *cache = reinterpret_cast<SArrayCache*>(objType->GetUserData(ARRAY_CACHE));
1466 if( subTypeId & ~asTYPEID_MASK_SEQNBR )
1467 {
1468 if( !cache || cache->cmpFunc == 0 )
1469 {
1470 asIScriptContext *ctx = asGetActiveContext();
1471 asITypeInfo* subType = objType->GetEngine()->GetTypeInfoById(subTypeId);
1472
1473 // Throw an exception
1474 if( ctx )
1475 {
1476 char tmp[512];
1477
1478 if( cache && cache->cmpFuncReturnCode == asMULTIPLE_FUNCTIONS )
1479#if defined(_MSC_VER) && _MSC_VER >= 1500 && !defined(__S3E__)
1480 sprintf_s(tmp, 512, "Type '%s' has multiple matching opCmp methods", subType->GetName());
1481#else
1482 snprintf(tmp, sizeof(tmp), "Type '%s' has multiple matching opCmp methods", subType->GetName());
1483#endif
1484 else
1485#if defined(_MSC_VER) && _MSC_VER >= 1500 && !defined(__S3E__)
1486 sprintf_s(tmp, 512, "Type '%s' does not have a matching opCmp method", subType->GetName());
1487#else
1488 snprintf(tmp, sizeof(tmp), "Type '%s' does not have a matching opCmp method", subType->GetName());
1489#endif
1490
1491 ctx->SetException(tmp);
1492 }
1493
1494 return;
1495 }
1496 }
1497
1498 // No need to sort
1499 if( count < 2 )
1500 {
1501 return;
1502 }
1503
1504 int start = startAt;
1505 int end = startAt + count;
1506
1507 // Check if we could access invalid item while sorting
1508 if( start >= (int)buffer->numElements || end > (int)buffer->numElements )
1509 {
1510 asIScriptContext *ctx = asGetActiveContext();
1511
1512 // Throw an exception
1513 if( ctx )
1514 {
1515 ctx->SetException("Index out of bounds");
1516 }
1517
1518 return;
1519 }

Callers 1

Calls 15

GetTypeInfoByIdMethod · 0.80
SetExceptionMethod · 0.80
PushStateMethod · 0.80
RequestContextMethod · 0.80
GetStateMethod · 0.80
PopStateMethod · 0.80
AbortMethod · 0.80
ReturnContextMethod · 0.80
SetArgAddressMethod · 0.80
ExecuteMethod · 0.80
GetUserDataMethod · 0.45

Tested by

no test coverage detected