| 1423 | /// explicitly (by using lock functions) |
| 1424 | template <typename T_Ptr, typename T_Key = const char*> |
| 1425 | class Registry : public AbstractRegistry<T_Ptr, std::map<T_Key, T_Ptr*>> { |
| 1426 | public: |
| 1427 | typedef typename Registry<T_Ptr, T_Key>::iterator iterator; |
| 1428 | typedef typename Registry<T_Ptr, T_Key>::const_iterator const_iterator; |
| 1429 | |
| 1430 | Registry(void) {} |
| 1431 | |
| 1432 | /// @brief Copy constructor that is useful for base classes. Try to avoid this constructor, use move constructor. |
| 1433 | Registry(const Registry& sr) : AbstractRegistry<T_Ptr, std::vector<T_Ptr*>>() { |
| 1434 | if (this == &sr) { |
| 1435 | return; |
| 1436 | } |
| 1437 | this->reinitDeepCopy(sr); |
| 1438 | } |
| 1439 | |
| 1440 | /// @brief Assignment operator that unregisters all the existing registeries and deeply copies each of repo element |
| 1441 | /// @see unregisterAll() |
| 1442 | /// @see deepCopy(const AbstractRegistry&) |
| 1443 | Registry& operator=(const Registry& sr) { |
| 1444 | if (this == &sr) { |
| 1445 | return *this; |
| 1446 | } |
| 1447 | this->reinitDeepCopy(sr); |
| 1448 | return *this; |
| 1449 | } |
| 1450 | |
| 1451 | virtual ~Registry(void) { |
| 1452 | unregisterAll(); |
| 1453 | } |
| 1454 | |
| 1455 | protected: |
| 1456 | virtual void unregisterAll(void) ELPP_FINAL { |
| 1457 | if (!this->empty()) { |
| 1458 | for (auto&& curr : this->list()) { |
| 1459 | base::utils::safeDelete(curr.second); |
| 1460 | } |
| 1461 | this->list().clear(); |
| 1462 | } |
| 1463 | } |
| 1464 | |
| 1465 | /// @brief Registers new registry to repository. |
| 1466 | virtual void registerNew(const T_Key& uniqKey, T_Ptr* ptr) ELPP_FINAL { |
| 1467 | unregister(uniqKey); |
| 1468 | this->list().insert(std::make_pair(uniqKey, ptr)); |
| 1469 | } |
| 1470 | |
| 1471 | /// @brief Unregisters single entry mapped to specified unique key |
| 1472 | void unregister(const T_Key& uniqKey) { |
| 1473 | T_Ptr* existing = get(uniqKey); |
| 1474 | if (existing != nullptr) { |
| 1475 | this->list().erase(uniqKey); |
| 1476 | base::utils::safeDelete(existing); |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | /// @brief Gets pointer from repository. If none found, nullptr is returned. |
| 1481 | T_Ptr* get(const T_Key& uniqKey) { |
| 1482 | iterator it = this->list().find(uniqKey); |
nothing calls this directly
no test coverage detected