After using my extremely flawed resource manager I finally re-designed it.
Here is the new design.
BaseMgr
-----------
- A template mgr class that wraps a map<unsigned int, T* pObject>.
- Supports Add, Remove, Get, and Update.
- Cleans up memory during destruction
DerivedMgr
--------------
- Simply derive from manager base and set the template type.
ResMgr
---------
- Class that wraps a vector of BaseMgr objects - ID is returned to user when
object is added - unique ID which is just the size_t index of the object
- Supports Add, Remove, Get, and Update
- Cleans up memory during destruction
Nice and simple and handles all my resources. It would be easy to add in a cache to disk scheme in the update function of BaseMgr.
Comments? I did it this way b/c most of the manager classes shared the same traits and basic operations. Coding those for every type of manager became really annoying. And now I have a nice way of wrapping all the manager's into one object called a resource manager. The main app class has a pointer to this which can then be used to access the manager's it contains.
The only problem now is the size_t index of the manager's in the ResMgr vector. This would not be known to other objects and the only scheme I can come up with is an enum that these objects can use to access the manager objects. I don't like this but haven't figured out a better method yet.