]> 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 5358183f24bc5a39d156b6f9bcab1c87136bac31..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"
@@ -21,17 +22,6 @@ resource_load_error::resource_load_error(const string &name, const exception &ex
 { }
 
 
-ResourceManager::ResourceManager():
-       policy(LOAD_ON_DEMAND),
-       async_loads(true),
-       total_data_size(0),
-       size_limit(0),
-       frame(0),
-       min_retain_frames(30),
-       max_retain_frames(0),
-       next_unload(0)
-{ }
-
 ResourceManager::~ResourceManager()
 {
        thread.terminate();
@@ -67,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);