Fabric: Introducing ContextContainer::update()

Summary:
The new method allows updating a ContextContainer using another one.
We will need that in the coming diffs.

Changelog: [Internal] Introducing `ContextContainer::update`

Reviewed By: sammy-SC

Differential Revision: D17960238

fbshipit-source-id: 187dcecbeee8c3de082575e53d5430d91b5338c5
This commit is contained in:
Valentin Shergin
2019-10-24 17:45:39 -07:00
committed by Facebook Github Bot
parent 4bdb702b9e
commit b30bf2f94e
+19
View File
@@ -62,6 +62,25 @@ class ContextContainer final {
#endif
}
/*
* Updates the container with values from a given container.
* Values with keys that already exist in the container will be replaced with
* values from the given container.
*/
void update(ContextContainer const &contextContainer) const {
std::unique_lock<better::shared_mutex> lock(mutex_);
for (auto const &pair : contextContainer.instances_) {
instances_.erase(pair.first);
instances_.insert(pair);
#ifndef NDEBUG
typeNames_.erase(pair.first);
typeNames_.insert(
{pair.first, contextContainer.typeNames_.at(pair.first)});
#endif
}
}
/*
* Returns a previously registered instance of the particular type `T`
* for `key`.