From 995b5f7d4bf727a4b88f1bb3b63426064fa51c09 Mon Sep 17 00:00:00 2001 From: Vitaly Baranov Date: Wed, 18 Sep 2024 13:13:13 +0200 Subject: [PATCH] Extend IAccessStorage::findAll() to enable finding all the entities in the storage. --- src/Access/IAccessStorage.cpp | 14 +++++++++++++- src/Access/IAccessStorage.h | 18 +++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/Access/IAccessStorage.cpp b/src/Access/IAccessStorage.cpp index 9d51ac1f9a4..5f367693b40 100644 --- a/src/Access/IAccessStorage.cpp +++ b/src/Access/IAccessStorage.cpp @@ -16,7 +16,7 @@ #include #include #include - +#include #include #include #include @@ -74,6 +74,18 @@ std::vector IAccessStorage::find(AccessEntityType type, const Strings & na } +std::vector IAccessStorage::findAllImpl() const +{ + std::vector res; + for (auto type : collections::range(AccessEntityType::MAX)) + { + auto ids = findAllImpl(type); + res.insert(res.end(), ids.begin(), ids.end()); + } + return res; +} + + UUID IAccessStorage::getID(AccessEntityType type, const String & name) const { auto id = findImpl(type, name); diff --git a/src/Access/IAccessStorage.h b/src/Access/IAccessStorage.h index b1bec2ce465..84cbdd0a751 100644 --- a/src/Access/IAccessStorage.h +++ b/src/Access/IAccessStorage.h @@ -91,8 +91,9 @@ public: /// Returns the identifiers of all the entities of a specified type contained in the storage. std::vector findAll(AccessEntityType type) const; - template - std::vector findAll() const { return findAll(EntityClassT::TYPE); } + /// Returns the identifiers of all the entities in the storage. + template + std::vector findAll() const; /// Searches for an entity with specified type and name. Returns std::nullopt if not found. std::optional find(AccessEntityType type, const String & name) const; @@ -149,7 +150,7 @@ public: std::optional> tryReadNameWithType(const UUID & id) const; /// Reads all entities and returns them with their IDs. - template + template std::vector>> readAllWithIDs() const; std::vector> readAllWithIDs(AccessEntityType type) const; @@ -220,6 +221,7 @@ public: protected: virtual std::optional findImpl(AccessEntityType type, const String & name) const = 0; virtual std::vector findAllImpl(AccessEntityType type) const = 0; + virtual std::vector findAllImpl() const; virtual AccessEntityPtr readImpl(const UUID & id, bool throw_if_not_exists) const = 0; virtual std::optional> readNameWithTypeImpl(const UUID & id, bool throw_if_not_exists) const; virtual bool insertImpl(const UUID & id, const AccessEntityPtr & entity, bool replace_if_exists, bool throw_if_exists, UUID * conflicting_id); @@ -268,6 +270,16 @@ private: }; +template +std::vector IAccessStorage::findAll() const +{ + if constexpr (std::is_same_v) + return findAllImpl(); + else + return findAllImpl(EntityClassT::TYPE); +} + + template std::shared_ptr IAccessStorage::read(const UUID & id, bool throw_if_not_exists) const {