| 417 | } |
| 418 | |
| 419 | template<class EntityDesc > bool SelectEntities(ccCommandLineInterface::SelectEntitiesOptions options, |
| 420 | const ccCommandLineParser& cmd, |
| 421 | std::vector<EntityDesc>& selectedEntities, |
| 422 | std::vector<EntityDesc>& unselectedEntities, |
| 423 | QString entityType) |
| 424 | { |
| 425 | //early abort if no cloud found |
| 426 | if (selectedEntities.empty() && unselectedEntities.empty()) |
| 427 | { |
| 428 | //do not stop execution, just warn the user and return |
| 429 | cmd.warning(QObject::tr("\tNo %1 loaded. Load some with the -O command").arg(entityType)); |
| 430 | return true; |
| 431 | } |
| 432 | |
| 433 | if (options.selectRegex && !options.regex.isValid()) |
| 434 | { |
| 435 | return cmd.error(QObject::tr("Regex string invalid: %1").arg(options.regex.errorString())); |
| 436 | } |
| 437 | |
| 438 | try |
| 439 | { |
| 440 | //store everthyng in the unselected vector |
| 441 | unselectedEntities.insert(unselectedEntities.end(), selectedEntities.begin(), selectedEntities.end()); |
| 442 | selectedEntities.clear(); |
| 443 | |
| 444 | //sort the unselected clouds by uniqueID (so as to restore the order in which they were loaded/created) |
| 445 | std::sort(unselectedEntities.begin(), unselectedEntities.end(), [](const EntityDesc& a, const EntityDesc& b) { return (a.getEntity()->getUniqueID() < b.getEntity()->getUniqueID()); }); |
| 446 | |
| 447 | //put elements to the front facing vector |
| 448 | unsigned index = 0; |
| 449 | assert(!unselectedEntities.empty()); // we have tested above that neither selectedEntities and unselectedEntities are both empty |
| 450 | size_t lastIndex = unselectedEntities.size() - 1; |
| 451 | for (typename std::vector<EntityDesc>::iterator it = unselectedEntities.begin(); it != unselectedEntities.end();) |
| 452 | { |
| 453 | QString nameToValidate = QObject::tr("%1/%2").arg(it->basename).arg(it->getEntity()->getName()); |
| 454 | bool toBeSelected = false; |
| 455 | if (!options.reverse) |
| 456 | { |
| 457 | //first {n} |
| 458 | if (options.selectFirst && index < options.firstNr) |
| 459 | { |
| 460 | toBeSelected = true; |
| 461 | } |
| 462 | |
| 463 | //last {n} |
| 464 | if (options.selectLast && index > lastIndex - options.lastNr) |
| 465 | { |
| 466 | toBeSelected = true; |
| 467 | } |
| 468 | } |
| 469 | else |
| 470 | { |
| 471 | //not first {n} |
| 472 | if (options.selectFirst && index >= options.firstNr && !options.selectLast) |
| 473 | { |
| 474 | toBeSelected = true; |
| 475 | } |
| 476 |
no test coverage detected