SFML community forums

Help => Graphics => Topic started by: The Terminator on July 25, 2012, 05:23:46 pm

Title: Resource Manager
Post by: The Terminator on July 25, 2012, 05:23:46 pm
I'm trying to create a resource manager, here's my main abstract class for the other managers to inherit from. I'm trying to use a templated class so it can be generic:

Manager.h:

namespace ShockEngine {
    template<class T> class Manager {
    protected:
        std::map<std::string, T> mediaList;
       
    public:
        virtual T getMedia(const T& fileName) = 0;
    };
}

Here's my texture manager, which is a derived class of Manager:

TextureManager.h:

#include "Manager.h"

namespace ShockEngine {
    class TextureManager: public Manager<sf::Texture> {
    protected:
        std::map<std::string, sf::Texture> textureList;
       
    public:
        TextureManager();
        virtual ~TextureManager();
       
        Manager<sf::Texture> addMedia(const std::string& fileName);
    };
   
    static TextureManager textureManager;
}

When I try to build and run this, 3 errors come up with my static definition of a texturemanager object, saying "Variable type TextureManager is an abstract class" I've tried to rewrite the template, use different techniques, but nothing works.
Title: Re: Resource Manager
Post by: eXpl0it3r on July 25, 2012, 05:52:22 pm
Then don't declare the destructor of your TextureManager as virtual and implement the getMedia function from the Manager class. ;)
Also read somethings about the virtual keyword and abstract classes. If you don't understand why this error appears then you're lacking major knowledge there. ;)
Title: Re: Resource Manager
Post by: Nexus on July 25, 2012, 11:46:34 pm
TheTerminator, it looks like you need to learn about when to use which abstraction mechanism. Why do you use templates? There is no generic code, you still write a specific std::map in the texture class.

And why do you use inheritance (or even more, polymorphism)? When will you ever work with an abstract base pointer Manager<sf::Texture>* if you refer to TextureManager?

Additionally, protected member variables and static variables in the global namespace (especially in header files) are questionable because of encapsulation and linkage, respectively.

Deconstructor
The function is called destructor ;)
Title: Re: Resource Manager
Post by: eXpl0it3r on July 26, 2012, 12:38:12 am
The function is called destructor ;)
Man, I always write that wrong... ::) :-\
*fixed* :D

PS: @Terminator: Use Thor's resource cache (http://www.bromeon.ch/thor/)! :P
Title: Re: Resource Manager
Post by: The Terminator on July 26, 2012, 06:50:22 pm
No it's ok guys, I got the thing sorted out and I threw my old design out and created a new one that actually works lol. Thanks for the help anyways.