]> git.tdb.fi Git - libs/gl.git/blobdiff - source/resources/resourcemanager.cpp
Add correct copy and move semantics to most classes
[libs/gl.git] / source / resources / resourcemanager.cpp
index f25e6ad1db1b53e609b68cf8d8d9559848da7b66..c72b361ce1f41ae9ec69d73d69a7d0e7307fcb21 100644 (file)
@@ -3,6 +3,7 @@
 #include <msp/debug/demangle.h>
 #include <msp/strings/format.h>
 #include <msp/time/utils.h>
+#include "error.h"
 #include "resourcemanager.h"
 #include "resources.h"
 #include "resourceobserver.h"
@@ -56,10 +57,22 @@ void ResourceManager::set_max_retain_frames(unsigned f)
 
 void ResourceManager::add_resource(Resource &r)
 {
+       if(r.get_manager()!=this)
+               throw invalid_operation("ResourceManager::add_resource");
        MutexLock lock(map_mutex);
        insert_unique(resources, &r, ManagedResource(r));
 }
 
+void ResourceManager::move_resource(Resource &from, Resource &to)
+{
+       if(to.get_manager()!=this || from.get_manager_data()!=to.get_manager_data())
+               throw invalid_operation("ResourceManager::move_resource");
+       ManagedResource *managed = reinterpret_cast<ManagedResource *>(to.get_manager_data());
+       MutexLock lock(map_mutex);
+       insert_unique(resources, &to, *managed);
+       resources.erase(&from);
+}
+
 const ResourceManager::ManagedResource &ResourceManager::get_managed_resource(const Resource &r) const
 {
        MutexLock lock(map_mutex);