17#ifndef _FGE_C_BASEMANAGER_HPP_INCLUDED
18#define _FGE_C_BASEMANAGER_HPP_INCLUDED
20#include "FastEngine/C_accessLock.hpp"
21#include "FastEngine/fge_except.hpp"
22#include "FastEngine/network/C_packet.hpp"
23#include "FastEngine/string_hash.hpp"
32#include <unordered_map>
35#define FGE_MANAGER_BAD std::string_view()
44 using DataPointer = std::shared_ptr<TData>;
46 inline virtual void unload() {}
50 std::filesystem::path _path;
61template<
class TData,
class TDataBlock = BaseDataBlock<TData>>
65 using DataType = TData;
66 using DataBlockType = TDataBlock;
67 using DataBlockPointer = std::shared_ptr<TDataBlock>;
68 using Map = std::unordered_map<std::string, DataBlockPointer, StringHash, std::equal_to<>>;
89 [[nodiscard]]
virtual bool isInitialized() = 0;
90 virtual void uninitialize() = 0;
97 [[nodiscard]] std::size_t
size()
const;
145 [[nodiscard]] DataBlockPointer
getElement(std::string_view name)
const;
146 [[nodiscard]]
bool contains(std::string_view name)
const;
147 bool unload(std::string_view name);
157 bool push(std::string_view name, DataBlockPointer block);
161 mutable std::mutex g_mutex;
164 DataBlockPointer _g_badElement;
167enum class DataAccessorOptions
170 ALLOW_VARIANT_OF_DATAPOINTER_AND_BLOCKPOINTER
173template<
class TManager, TManager* TGlobalManager>
176 using Manager = TManager;
177 [[nodiscard]]
inline constexpr TManager& operator()()
const {
return *TGlobalManager; }
180template<
class TDataAccessorManagerInfo, DataAccessorOptions TOption>
184 using SharedDataType =
typename TDataAccessorManagerInfo::Manager::DataBlockPointer;
185 using SharedType =
typename TDataAccessorManagerInfo::Manager::DataBlockType::DataPointer;
208 requires(TOption == DataAccessorOptions::ALLOW_VARIANT_OF_DATAPOINTER_AND_BLOCKPOINTER);
216 virtual void clear();
228 [[nodiscard]]
bool valid()
const;
244 requires(TOption == DataAccessorOptions::ALLOW_VARIANT_OF_DATAPOINTER_AND_BLOCKPOINTER);
250 [[nodiscard]] std::string
const&
getName()
const;
252 auto& operator=(std::string_view name);
253 auto& operator=(
char const name[]);
254 auto& operator=(std::string name);
255 auto& operator=(SharedDataType data);
256 auto& operator=(SharedType data)
257 requires(TOption == DataAccessorOptions::ALLOW_VARIANT_OF_DATAPOINTER_AND_BLOCKPOINTER);
266 [[nodiscard]]
typename TDataAccessorManagerInfo::Manager::DataType*
retrieve();
267 [[nodiscard]]
typename TDataAccessorManagerInfo::Manager::DataType
const*
retrieve()
const;
270 using VariantType = std::variant<SharedDataType, SharedType>;
271 using Type = std::conditional_t<TOption == DataAccessorOptions::BLOCKPOINTER_ONLY, SharedDataType, VariantType>;
277template<
class TDataAccessorManagerInfo, DataAccessorOptions TOption>
279template<
class TDataAccessorManagerInfo, DataAccessorOptions TOption>
282template<
class TDataAccessorManagerInfo, DataAccessorOptions TOption>
284template<
class TDataAccessorManagerInfo, DataAccessorOptions TOption>
289#include "C_baseManager.inl"
Class that lock a mutex and unlock it only when the object is destroyed.
Definition C_accessLock.hpp:38
Definition C_baseManager.hpp:182
SharedType const & getSharedData() const
Get the shared resource data.
Definition C_baseManager.inl:218
bool valid() const
Check if the font is valid (not unloaded)
Definition C_baseManager.inl:183
TDataAccessorManagerInfo::Manager::DataType * retrieve()
Retrieve the raw shared pointer from the current resource.
Definition C_baseManager.inl:291
SharedDataType const & getSharedBlock() const
Get the resource block data.
Definition C_baseManager.inl:201
virtual void clear()
Clear the resource.
Definition C_baseManager.inl:170
std::string const & getName() const
Get the name of the resource.
Definition C_baseManager.inl:233
void reload()
Reload the cached resource from the same name.
Definition C_baseManager.inl:177
Base class for all managers.
Definition C_baseManager.hpp:63
Map::const_iterator begin(AccessLock< std::mutex > const &lock) const
Get the "begin" iterator of the manager.
Definition C_baseManager.inl:35
DataBlockPointer getElement(std::string_view name) const
Get the resource with the given name.
Definition C_baseManager.inl:55
AccessLock< std::mutex > acquireLock() const
Acquire a AccessLock, with the manager mutex.
Definition C_baseManager.inl:29
std::size_t size() const
Get the number of elements in the manager.
Definition C_baseManager.inl:23
bool push(std::string_view name, DataBlockPointer block)
Add a user handled resource.
Definition C_baseManager.inl:117
DataBlockPointer const & getBadElement() const
Get the "bad" element.
Definition C_baseManager.inl:49
Map::const_iterator end(AccessLock< std::mutex > const &lock) const
Get the "end" iterator of the manager.
Definition C_baseManager.inl:42
virtual bool initialize()=0
Initialize the manager.
Definition C_packet.hpp:70
Definition C_baseManager.hpp:42
Definition C_baseManager.hpp:175