Browse Source

Prefix internal Resource members with an underscore.

pull/415/head
Vladimír Vondruš 6 years ago
parent
commit
91fc09e3e9
  1. 66
      src/Magnum/Resource.h

66
src/Magnum/Resource.h

@ -127,11 +127,11 @@ class Resource {
* Creates empty resource. Resources are acquired from the manager by
* calling @ref ResourceManager::get().
*/
explicit Resource(): manager(nullptr), lastCheck(0), _state(ResourceState::Final), data(nullptr) {}
explicit Resource(): _manager{nullptr}, _lastCheck{0}, _state{ResourceState::Final}, _data{nullptr} {}
/** @brief Copy constructor */
Resource(const Resource<T, U>& other): manager(other.manager), _key(other._key), lastCheck(other.lastCheck), _state(other._state), data(other.data) {
if(manager) manager->incrementReferenceCount(_key);
Resource(const Resource<T, U>& other): _manager{other._manager}, _key{other._key}, _lastCheck{other._lastCheck}, _state{other._state}, _data{other._data} {
if(_manager) _manager->incrementReferenceCount(_key);
}
/** @brief Move constructor */
@ -139,7 +139,7 @@ class Resource {
/** @brief Destructor */
~Resource() {
if(manager) manager->decrementReferenceCount(_key);
if(_manager) _manager->decrementReferenceCount(_key);
}
/** @brief Copy assignment */
@ -150,7 +150,7 @@ class Resource {
/** @brief Equality comparison */
bool operator==(const Resource<T, U>& other) const {
return manager == other.manager && _key == other._key;
return _manager == other._manager && _key == other._key;
}
/** @brief Equality comparison with other types is explicitly disallowed */
@ -187,7 +187,7 @@ class Resource {
*/
operator bool() {
acquire();
return data;
return _data;
}
/**
@ -197,7 +197,7 @@ class Resource {
*/
operator U*() {
acquire();
return static_cast<U*>(data);
return static_cast<U*>(_data);
}
/**
@ -209,8 +209,8 @@ class Resource {
*/
U& operator*() {
acquire();
CORRADE_ASSERT(data, "Resource: accessing not loaded data with key" << key(), *static_cast<U*>(data));
return *static_cast<U*>(data);
CORRADE_ASSERT(_data, "Resource: accessing not loaded data with key" << _key, *static_cast<U*>(_data));
return *static_cast<U*>(_data);
}
/**
@ -222,8 +222,8 @@ class Resource {
*/
U* operator->() {
acquire();
CORRADE_ASSERT(data, "Resource: accessing not loaded data with key" << key(), nullptr);
return static_cast<U*>(data);
CORRADE_ASSERT(_data, "Resource: accessing not loaded data with key" << _key, nullptr);
return static_cast<U*>(_data);
}
private:
@ -231,47 +231,47 @@ class Resource {
friend Implementation::ResourceManagerData<T>;
#endif
Resource(Implementation::ResourceManagerData<T>* manager, ResourceKey key): manager(manager), _key(key), lastCheck(0), _state(ResourceState::NotLoaded), data(nullptr) {
Resource(Implementation::ResourceManagerData<T>* manager, ResourceKey key): _manager{manager}, _key{key}, _lastCheck{0}, _state{ResourceState::NotLoaded}, _data{nullptr} {
manager->incrementReferenceCount(key);
}
void acquire();
Implementation::ResourceManagerData<T>* manager;
Implementation::ResourceManagerData<T>* _manager;
ResourceKey _key;
std::size_t lastCheck;
std::size_t _lastCheck;
ResourceState _state;
T* data;
T* _data;
};
template<class T, class U> Resource<T, U>& Resource<T, U>::operator=(const Resource<T, U>& other) {
if(manager) manager->decrementReferenceCount(_key);
if(_manager) _manager->decrementReferenceCount(_key);
manager = other.manager;
_manager = other._manager;
_key = other._key;
lastCheck = other.lastCheck;
_lastCheck = other._lastCheck;
_state = other._state;
data = other.data;
_data = other._data;
if(manager) manager->incrementReferenceCount(_key);
if(_manager) _manager->incrementReferenceCount(_key);
return *this;
}
template<class T, class U> Resource<T, U>::Resource(Resource<T, U>&& other) noexcept: manager(other.manager), _key(other._key), lastCheck(other.lastCheck), _state(other._state), data(other.data) {
other.manager = nullptr;
template<class T, class U> Resource<T, U>::Resource(Resource<T, U>&& other) noexcept: _manager(other._manager), _key(other._key), _lastCheck(other._lastCheck), _state(other._state), _data(other._data) {
other._manager = nullptr;
other._key = {};
other.lastCheck = 0;
other._lastCheck = 0;
other._state = ResourceState::Final;
other.data = nullptr;
other._data = nullptr;
}
template<class T, class U> Resource<T, U>& Resource<T, U>::operator=(Resource<T, U>&& other) noexcept {
using std::swap;
swap(manager, other.manager);
swap(_manager, other._manager);
swap(_key, other._key);
swap(lastCheck, other.lastCheck);
swap(_lastCheck, other._lastCheck);
swap(_state, other._state);
swap(data, other.data);
swap(_data, other._data);
return *this;
}
@ -280,20 +280,20 @@ template<class T, class U> void Resource<T, U>::acquire() {
if(_state == ResourceState::Final) return;
/* Nothing changed since last check */
if(manager->lastChange() < lastCheck) return;
if(_manager->lastChange() < _lastCheck) return;
/* Acquire new data and save last check time */
const typename Implementation::ResourceManagerData<T>::Data& d = manager->data(_key);
lastCheck = manager->lastChange();
const typename Implementation::ResourceManagerData<T>::Data& d = _manager->data(_key);
_lastCheck = _manager->lastChange();
/* Try to get the data */
data = d.data;
_data = d.data;
_state = static_cast<ResourceState>(d.state);
/* Data are not available */
if(!data) {
if(!_data) {
/* Fallback found, add *Fallback to state */
if((data = manager->fallback())) {
if((_data = _manager->fallback())) {
if(_state == ResourceState::Loading)
_state = ResourceState::LoadingFallback;
else if(_state == ResourceState::NotFound)

Loading…
Cancel
Save