19#include <unordered_map>
20#include "aeongames/ResourceFactory.hpp"
21#include "aeongames/ResourceCache.hpp"
22#include "aeongames/ResourceId.hpp"
26 static std::unordered_map < uint32_t, std::tuple<std::function <
UniqueAnyPtr ( uint32_t ) >,
UniqueAnyPtr >> Constructors;
30 auto it = Constructors.find ( aResourceId.
GetType() );
31 if ( it != Constructors.end() )
33 return std::get<0> ( it->second ) ( aResourceId.
GetPath() );
35 std::ostringstream stream;
36 stream <<
"No constructor registered for type " << aResourceId.
GetType();
37 throw std::runtime_error ( stream.str().c_str() );
41 if ( Constructors.find ( aType ) == Constructors.end() )
43 Constructors[aType] = std::make_pair ( aConstructor, std::move ( aDefaultResource ) );
50 auto it = Constructors.find ( aType );
51 if ( it != Constructors.end() )
53 Constructors.erase ( it );
60 for (
auto& i : Constructors )
62 if ( !aEnumerator ( i.first ) )
72 auto it = Constructors.find ( aType );
73 if ( it != Constructors.end() )
75 return std::get<1> ( it->second );
77 return unique_any_nullptr;
Identifies a resource by its type and path CRC32 hashes.
uint32_t GetType() const
Get the CRC32 hash of the resource type.
uint32_t GetPath() const
Get the CRC32 hash of the resource path.
A type-erased owning smart pointer with unique ownership semantics.
<- This is here just for the literals
DLL const UniqueAnyPtr & GetDefaultResource(uint32_t aType)
Get the default resource for a given type.
DLL UniqueAnyPtr ConstructResource(const ResourceId &aResourceId)
Construct a resource identified by a ResourceId.
DLL bool UnregisterResourceConstructor(uint32_t aType)
Unregister a resource constructor.
DLL void EnumerateResourceConstructors(const std::function< bool(uint32_t) > &aEnumerator)
Enumerate all registered resource constructors.
DLL bool RegisterResourceConstructor(uint32_t aType, const std::function< UniqueAnyPtr(uint32_t) > &aConstructor, UniqueAnyPtr &&aDefaultResource=nullptr)
Register a constructor for a resource type.