| 1499 | /// should be made thread-safe explicitly |
| 1500 | template <typename T_Ptr, typename Pred> |
| 1501 | class RegistryWithPred : public AbstractRegistry<T_Ptr, std::vector<T_Ptr*>> { |
| 1502 | public: |
| 1503 | typedef typename RegistryWithPred<T_Ptr, Pred>::iterator iterator; |
| 1504 | typedef typename RegistryWithPred<T_Ptr, Pred>::const_iterator const_iterator; |
| 1505 | |
| 1506 | RegistryWithPred(void) { |
| 1507 | } |
| 1508 | |
| 1509 | virtual ~RegistryWithPred(void) { |
| 1510 | unregisterAll(); |
| 1511 | } |
| 1512 | |
| 1513 | /// @brief Copy constructor that is useful for base classes. Try to avoid this constructor, use move constructor. |
| 1514 | RegistryWithPred(const RegistryWithPred& sr) : AbstractRegistry<T_Ptr, std::vector<T_Ptr*>>() { |
| 1515 | if (this == &sr) { |
| 1516 | return; |
| 1517 | } |
| 1518 | this->reinitDeepCopy(sr); |
| 1519 | } |
| 1520 | |
| 1521 | /// @brief Assignment operator that unregisters all the existing registeries and deeply copies each of repo element |
| 1522 | /// @see unregisterAll() |
| 1523 | /// @see deepCopy(const AbstractRegistry&) |
| 1524 | RegistryWithPred& operator=(const RegistryWithPred& sr) { |
| 1525 | if (this == &sr) { |
| 1526 | return *this; |
| 1527 | } |
| 1528 | this->reinitDeepCopy(sr); |
| 1529 | return *this; |
| 1530 | } |
| 1531 | |
| 1532 | friend base::type::ostream_t& operator<<(base::type::ostream_t& os, const RegistryWithPred& sr) { |
| 1533 | for (const_iterator it = sr.list().begin(); it != sr.list().end(); ++it) { |
| 1534 | os << ELPP_LITERAL(" ") << **it << ELPP_LITERAL("\n"); |
| 1535 | } |
| 1536 | return os; |
| 1537 | } |
| 1538 | |
| 1539 | protected: |
| 1540 | virtual void unregisterAll(void) ELPP_FINAL { |
| 1541 | if (!this->empty()) { |
| 1542 | for (auto&& curr : this->list()) { |
| 1543 | base::utils::safeDelete(curr); |
| 1544 | } |
| 1545 | this->list().clear(); |
| 1546 | } |
| 1547 | } |
| 1548 | |
| 1549 | virtual void unregister(T_Ptr*& ptr) ELPP_FINAL { |
| 1550 | if (ptr) { |
| 1551 | iterator iter = this->begin(); |
| 1552 | for (; iter != this->end(); ++iter) { |
| 1553 | if (ptr == *iter) { |
| 1554 | break; |
| 1555 | } |
| 1556 | } |
| 1557 | if (iter != this->end() && *iter != nullptr) { |
| 1558 | this->list().erase(iter); |
nothing calls this directly
no test coverage detected