template class EE::System::ResourceManagerMulti

Overview

A simple resource manager. It keeps a list of the resources, and free the instances of the resources when the manager is closed. Resources must implement getId() and getName() properties getId() is the string hash of getName(). Allows repeated keys. More…

#include <resourcemanager.hpp>

template <class T>
class ResourceManagerMulti {
public:
    // construction

    virtual ~ResourceManagerMulti();

    // methods

    virtual T* add(T* resource);
    bool remove(T* resource, bool remove = true);
    bool removeById(const String::HashType& id, bool remove = true);
    bool removeByName(const std::string& name, bool remove = true);
    T* getByName(const std::string& name);
    T* getById(const String::HashType& id);
    Uint32 getCount();
    Uint32 getCount(const std::string& name);
    Uint32 getCount(const String::HashType& id);
    bool exists(const std::string& name);
    bool existsId(const String::HashType& id);
    void destroy();
    void printNames();
    std::unordered_multimap<String::HashType, T*>& getResources();
    const bool& isDestroying() const;
};

Detailed Documentation

A simple resource manager. It keeps a list of the resources, and free the instances of the resources when the manager is closed. Resources must implement getId() and getName() properties getId() is the string hash of getName(). Allows repeated keys.

Construction

virtual ~ResourceManagerMulti()

The destructor will call destroy() and destroy all the resources added to the manager.

Methods

virtual T* add(T* resource)

Add the resource to the resource manager.

Parameters:

resource

The resource to be managed by the manager

bool remove(T* resource, bool remove = true)

Removes the resource from the manager.

Parameters:

resource

The resource to remove

remove

Indicates if the resource must be destroyed after being removed from the manager

bool removeById(const String::HashType& id, bool remove = true)

Removes the resource by its id.

See also:

remove

bool removeByName(const std::string& name, bool remove = true)

Removes the resource by its name.

See also:

remove

T* getByName(const std::string& name)

Returns:

A resource by its name. If not found returns NULL.

T* getById(const String::HashType& id)

Returns:

A resource by its id. If not found returns NULL.

Uint32 getCount()

Returns:

The number of resources added

Uint32 getCount(const std::string& name)

Returns:

The number of resources that where added with the indicated name.

Uint32 getCount(const String::HashType& id)

Returns:

The number of resources that where added with the indicated id.

bool exists(const std::string& name)

Returns:

If the resource name exists in the resources list.

bool existsId(const String::HashType& id)

Returns:

If the resource id exists in the resources list.

void destroy()

Destroy all the resources added ( delete the instances of the resources )

void printNames()

Prints all the resources names added to the manager.

std::unordered_multimap<String::HashType, T*>& getResources()

Returns:

A reference to the resources list of the manager.

const bool& isDestroying() const

Indicates if the resource manager is destroy the resources.