Browse Source

Move constructor and move assignment for Resource.

Saves unnecessary manager access.
pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
0f0b7a8d17
  1. 19
      src/ResourceManager.h

19
src/ResourceManager.h

@ -270,6 +270,11 @@ template<class T, class U = T> class Resource {
if(manager) manager->incrementReferenceCount(key);
}
/** @brief Move constructor */
inline Resource(Resource<T, U>&& other): manager(other.manager), key(other.key), lastCheck(other.lastCheck), _state(other._state), data(other.data) {
other.manager = nullptr;
}
/** @brief Destructor */
inline ~Resource() {
if(manager) manager->decrementReferenceCount(key);
@ -289,6 +294,20 @@ template<class T, class U = T> class Resource {
return *this;
}
/** @brief Assignment move operator */
Resource<T, U>& operator=(Resource<T, U>&& other) {
if(manager) manager->decrementReferenceCount(key);
manager = other.manager;
key = other.key;
lastCheck = other.lastCheck;
_state = other._state;
data = other.data;
other.manager = nullptr;
return *this;
}
/**
* @brief %Resource state
*

Loading…
Cancel
Save