Just posting for constructive nitpicking
One question, It won't let me do a delete it->second in the remove resource function, it is having an issue with boost::shared_ptr...Code:#include <vector> #include <map> #include <boost\shared_ptr.hpp> #include <boost\weak_ptr.hpp> template< typename T_ > class Resource_Manager { public: Resource_Manager<T_>() {}; ~Resource_Manager<T_>() {}; boost::weak_ptr<T_> Request_Resource(const std::string &name) { std::map< std::string, boost::shared_ptr<T_> >::iterator it = mResources.find(name); if(it == mResources.end()) { boost::shared_ptr<T_> Raw_Resource(new T_); Raw_Resource->Load_Resource(name); mResources.insert(std::make_pair(name, Raw_Resource)); boost::weak_ptr<T_> Resource(Raw_Resource); return Resource; } else { boost::weak_ptr<T_> Resource(it->second); return Resource; } } void Request_Resource_Removal(const std::string &name) { std::map<std::string, boost::shared_ptr<T_> >::iterator it = mResources.find(name); if (it != mResources.end()) { // how do I remove an element of the map without breaking anything? } } private: std::map< std::string, boost::shared_ptr<T_> > mResources; };
TODO:
Count references to each shared pointer, release resource when reference count gets to zero.



LinkBack URL
About LinkBacks




Want to add some