FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
fge::manager::BaseManager< TData, TDataBlock > Class Template Referenceabstract

Base class for all managers. More...

#include <C_baseManager.hpp>

Public Types

using DataType = TData
 
using DataBlockType = TDataBlock
 
using DataBlockPointer = std::shared_ptr<TDataBlock>
 
using Map = std::unordered_map<std::string, DataBlockPointer, StringHash, std::equal_to<>>
 

Public Member Functions

 BaseManager (BaseManager const &r)=delete
 
 BaseManager (BaseManager &&r) noexcept=delete
 
BaseManageroperator= (BaseManager const &r)=delete
 
BaseManageroperator= (BaseManager &&r) noexcept=delete
 
virtual bool initialize ()=0
 Initialize the manager.
 
virtual bool isInitialized ()=0
 
virtual void uninitialize ()=0
 
std::size_t size () const
 Get the number of elements in the manager.
 
AccessLock< std::mutex > acquireLock () const
 Acquire a AccessLock, with the manager mutex.
 
Map::const_iterator begin (AccessLock< std::mutex > const &lock) const
 Get the "begin" iterator of the manager.
 
Map::const_iterator end (AccessLock< std::mutex > const &lock) const
 Get the "end" iterator of the manager.
 
DataBlockPointer const & getBadElement () const
 Get the "bad" element.
 
DataBlockPointer getElement (std::string_view name) const
 Get the resource with the given name.
 
bool contains (std::string_view name) const
 
bool unload (std::string_view name)
 
void unloadAll ()
 
bool push (std::string_view name, DataBlockPointer block)
 Add a user handled resource.
 

Protected Attributes

DataBlockPointer _g_badElement
 

Detailed Description

template<class TData, class TDataBlock = BaseDataBlock<TData>>
class fge::manager::BaseManager< TData, TDataBlock >

Base class for all managers.

A manager (or registry) is a class that manages a set of resources with a string key. This class is thread-safe.

Member Function Documentation

◆ acquireLock()

template<class TData , class TDataBlock >
AccessLock< std::mutex > fge::manager::BaseManager< TData, TDataBlock >::acquireLock ( ) const
nodiscard

Acquire a AccessLock, with the manager mutex.

In order to use iterators, you have to acquire a unique lock from this function. The lock is not differed and will lock the mutex.

Returns
A AccessLock bound to this mutex

◆ begin()

template<class TData , class TDataBlock >
BaseManager< TData, TDataBlock >::Map::const_iterator fge::manager::BaseManager< TData, TDataBlock >::begin ( AccessLock< std::mutex > const & lock) const
nodiscard

Get the "begin" iterator of the manager.

You have to provide a valid reference to a AccessLock acquired with the function AcquireLock(). This function will throw if one of this is not respected :

  • The mutex pointer of the lock does not correspond to this mutex.
Parameters
lockA AccessLock bound to this mutex
Returns
The "begin" iterator of the texture manager

◆ end()

template<class TData , class TDataBlock >
BaseManager< TData, TDataBlock >::Map::const_iterator fge::manager::BaseManager< TData, TDataBlock >::end ( AccessLock< std::mutex > const & lock) const
nodiscard

Get the "end" iterator of the manager.

See also
begin()
Parameters
lockA AccessLock bound to this mutex
Returns
The "end" iterator of the manager

◆ getBadElement()

template<class TData , class TDataBlock >
BaseManager< TData, TDataBlock >::DataBlockPointer const & fge::manager::BaseManager< TData, TDataBlock >::getBadElement ( ) const
nodiscard

Get the "bad" element.

A bad element is a "valid" default resource that is returned when the requested resource is not found. return The "bad" element

◆ getElement()

template<class TData , class TDataBlock >
BaseManager< TData, TDataBlock >::DataBlockPointer fge::manager::BaseManager< TData, TDataBlock >::getElement ( std::string_view name) const
nodiscard

Get the resource with the given name.

Parameters
nameThe name of the resource to get
Returns
The resource with the given name or the bad resource if not found

◆ initialize()

template<class TData , class TDataBlock = BaseDataBlock<TData>>
virtual bool fge::manager::BaseManager< TData, TDataBlock >::initialize ( )
pure virtual

Initialize the manager.

The philosophy with this class is to always return a "valid" element even if the element is not found. When this method is called, a "bad" element is created and stored in the manager.

Warning
Note that there is no verification about the above statement, and you can always create your own manager without a "bad" element.

return true if the manager is initialized, false otherwise

Implemented in fge::anim::AnimationManager, fge::audio::AudioManager, fge::font::FontManager, fge::shader::ShaderManager, and fge::texture::TextureManager.

◆ push()

template<class TData , class TDataBlock >
bool fge::manager::BaseManager< TData, TDataBlock >::push ( std::string_view name,
DataBlockPointer block )

Add a user handled resource.

Parameters
nameThe name of the texture to add
blockThe block data to add
Returns
true if the resource was added, false otherwise

◆ size()

template<class TData , class TDataBlock >
std::size_t fge::manager::BaseManager< TData, TDataBlock >::size ( ) const
nodiscard

Get the number of elements in the manager.

return The number of elements in the manager without the "bad" element


The documentation for this class was generated from the following files: