I'd like to build an asset manager that can "own" allocated data loaded that's typically from files. That way, I can keep certain commonly-used assets that are persistent across multiple states of the game's life-cycle easily without having to write special-case code.
Plus, there's also no confusion of which pointer needs to release my asset from memory.
I'd like to somehow store all of my assets in STL maps where each different type of asset gets its own map. For example, if I add a texture to my AssetManager, a map that only holds pointers to allocated assets of type "Texture" will be created if it hasn't already. If I want to load up a SpriteCollection, I'd load and add it to the AssetManager. It'll generate another STL map to hold anything that's of type SpriteCollection if one doesn't already exist, or just add it to the one that does. Then, if I wanted to get a particular texture, I'd pass in the type and name (key) to that texture stored in the Texture's STL map. The getter method would be something along these lines:
Texture2D *texturePtr = AssetManager::GetAsset<Texture2D>("hero_character");
Another interesting thing is since I'm using multiple maps, I could have a SpriteSheet asset loaded that's also named "hero_character", and I'd be unique from the Texture2D pointer who's key is also "hero_character" because they're both different types of assets.
I'm new to templates, however... I'm trying to wrap my head around this, but haven't gotten it quite yet. Is this even possible in C++?