29 label_(kLabelChanged, std::string(), this) {}
42 for (
const auto& group : resources_)
43 for (
const auto& entry : group)
44 entry.second->holder_ =
nullptr;
46 for (
const auto& group : resources_)
47 for (
const auto& entry : group)
48 entry.second->OnDestroyed();
55 DCHECK(resource->holder_ ==
nullptr || resource->holder_ ==
this);
57 const size_t num_fields = fields_.size();
58 for (
size_t i = 0; i < num_fields; ++i)
59 resource->
OnChanged(fields_[i]->GetBit());
68 if (index >= resources_.size()) {
80 auto found = resources_[index].find(key);
81 old_resource = (found == resources_[index].end() ?
nullptr : found->second);
86 resource->holder_ =
this;
90 old_resource->holder_ =
nullptr;
91 found->second = resource;
94 resources_[index].emplace(key, resource);
96 }
else if (old_resource) {
98 old_resource->holder_ =
nullptr;
99 resources_[index].erase(found);
100 if (index + 1 == resources_.size()) {
102 auto first_nonempty = std::find_if(resources_.rbegin(), resources_.rend(),
104 resources_.resize(std::distance(first_nonempty, resources_.rend()),
113 if (resource && !old_resource)
115 else if (!resource && old_resource)
119 DCHECK(resources_.empty() || !resources_.back().empty());
123 const size_t count = resources_.size();
124 if (index >= count)
return nullptr;
125 auto found = resources_[index].find(key);
126 return found == resources_[index].end() ?
nullptr : found->second;
This class can be used in place of std::unordered_map to allow an Ion Allocator to be used for memory...
void SetResource(size_t index, ResourceKey key, ResourceBase *resource) const
Sets the resource at the passed index and key.
ResourceHolder()
The constructor is protected because this is an abstract base class.
~ResourceHolder() override
The destructor invokes the resource callback.
A LockGuard locks a mutex when created, and unlocks it when destroyed.
ResourceKey GetKey() const
Retrieve a key that disambiguates between multiple resources created for the same holder by the same ...
A WriteLock obtains a write lock, but has a similar interface to a Mutex and can be used with a Write...
#define DCHECK_EQ(val1, val2)
ResourceBase * GetResource(size_t index, ResourceKey key) const
Returns the Resource at the given index and key, or NULL if no resource was previously set at that lo...
intptr_t ResourceKey
Type of identifiers used to disambiguate between multiple resources created for the same Ion object b...
ResourceBase is an internal abstract base class for managed resources.
virtual void OnChanged(const int bit)=0
Informs the resource that something has changed and that it needs to update itself.