392 if (pFile->objects[i] == this) |
392 if (pFile->objects[i] == this) |
393 return i; |
393 return i; |
394 |
394 |
395 return -1; |
395 return -1; |
396 } |
396 } |
|
397 |
|
398 void LDObject::moveObjects (std::vector<LDObject*> objs, const bool bUp) { |
|
399 // If we move down, we need to iterate the array in reverse order. |
|
400 const long start = bUp ? 0 : (objs.size() - 1); |
|
401 const long end = bUp ? objs.size() : -1; |
|
402 const long incr = bUp ? 1 : -1; |
|
403 |
|
404 for (long i = start; i != end; i += incr) { |
|
405 LDObject* obj = objs[i]; |
|
406 |
|
407 const long lIndex = obj->getIndex (g_CurrentFile), |
|
408 lTarget = lIndex + (bUp ? -1 : 1); |
|
409 |
|
410 if ((bUp == true and lIndex == 0) or |
|
411 (bUp == false and lIndex == (long)(g_CurrentFile->objects.size() - 1))) |
|
412 { |
|
413 // One of the objects hit the extrema. If this happens, this should be the first |
|
414 // object to be iterated on. Thus, nothing has changed yet and it's safe to just |
|
415 // abort the entire operation. |
|
416 assert (i == start); |
|
417 return; |
|
418 } |
|
419 |
|
420 obj->swap (g_CurrentFile->objects[lTarget]); |
|
421 } |
|
422 } |