30 std::vector<std::shared_ptr<MemoryPersistenceStrategy>>& strategies) :
31 strategies_(strategies)
39 std::vector<std::string>
42 std::vector<std::string> keys;
44 for (
auto& strategy : strategies_)
46 std::vector<std::string> strategyKeys = strategy->getContainerKeys(
id);
47 keys.insert(keys.end(), strategyKeys.begin(), strategyKeys.end());
57 std::vector<std::string>
60 std::vector<std::string> keys;
62 for (
auto& strategy : strategies_)
64 std::vector<std::string> strategyKeys = strategy->getItemKeys(
id);
65 keys.insert(keys.end(), strategyKeys.begin(), strategyKeys.end());
77 for (
auto& s : strategies_)
79 if (s->containsContainer(
id, key))
94 for (
auto& s : strategies_)
96 if (s->containsItem(
id, key))
110 const std::string key,
111 std::vector<unsigned char>&
data)
override
113 for (
auto& s : strategies_)
115 s->storeItem(
id, key,
data);
122 std::vector<unsigned char>
125 for (
auto& s : strategies_)
127 if (s->containsItem(
id, key))
129 return s->retrieveItem(
id, key);
133 return std::vector<unsigned char>();
139 for (
auto& s : strategies_)
141 if (s->containsItem(
id, key))
143 return s->retrieveItemWithOrigin(
id, key);
147 return {
"undefined4", std::vector<unsigned char>()};
158 for (
auto& s : strategies_)
160 s->setExportName(exportName);
171 strategies_.emplace_back(strategy);
186 for (
auto& s : strategies_)
188 s->createPropertyDefinitions(defs, prefix);
206 return std::any_of(strategies_.begin(),
208 [](
const auto& s) { return s->isEnabled(); });
214 for (
auto& s : strategies_)
223 for (
auto& s : strategies_)
231 std::vector<std::shared_ptr<MemoryPersistenceStrategy>> strategies_;
MemoryPersistenceStrategy()
std::string exportName_
Name of the specific memory export where our items should be stored.
void addStrategy(std::shared_ptr< MemoryPersistenceStrategy > strategy)
Add another strategy to the end.
RedundantPersistenceStrategy(std::vector< std::shared_ptr< MemoryPersistenceStrategy > > &strategies)
bool containsContainer(const armarx::armem::MemoryID &id, std::string key) override
Checks if any strategy contains the container.
std::vector< std::string > getItemKeys(const armarx::armem::MemoryID &id) override
Returns all items over all strategies.
ItemResult retrieveItemWithOrigin(const armarx::armem::MemoryID &id, std::string &key) override
Retrieves the actual data but also appends the origin which is in this case the strategy identifier.
bool containsItem(const armarx::armem::MemoryID &id, std::string key) override
Checks if any strategy contains the item.
std::vector< std::string > getContainerKeys(const armarx::armem::MemoryID &id) override
Returns all containers over all strategies.
void clearStrategies()
Removes all strategies.
void setExportName(const std::string &exportName) override
Sets the export name for all strategies.
RedundantPersistenceStrategy()=default
void storeItem(const armarx::armem::MemoryID &id, const std::string key, std::vector< unsigned char > &data) override
Stores the item to every strategy.
std::vector< unsigned char > retrieveItem(const armarx::armem::MemoryID &id, std::string key) override
Retrieves the data of the item following the FIFO principle (if the item exists at any strategy).
bool isEnabled() override
Whether anything would actually be stored, i.e.
void createPropertyDefinitions(PropertyDefinitionsPtr &defs, const std::string &prefix) override
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Retrieved items' data with an origin (resp.