7#include <Common/assertion.h>
8#include <Common/Container/TStdUnorderedStringMap.h>
10#include <unordered_map>
23 std::shared_ptr<ISdlResource>
get(std::string_view resourceName)
const override;
24 bool has(std::string_view resourceName)
const override;
32 std::shared_ptr<ISdlResource> resource,
33 std::string_view resourceName);
39 std::shared_ptr<ISdlResource>
remove(std::string_view resourceName);
49 std::string
rename(std::string_view resourceName, std::string_view newResourceName);
66 std::vector<std::string>* out_resourceNames =
nullptr)
const;
71 std::vector<std::shared_ptr<ISdlResource>>
getAll(
72 std::vector<std::string>* out_resourceNames =
nullptr)
const;
86 std::vector<std::string>* out_resourceNames =
nullptr)
const;
91 std::vector<const ISdlResource*>
listAll(
92 std::vector<std::string>* out_resourceNames =
nullptr)
const;
95 using ResourceMapType = TStdUnorderedStringMap<std::shared_ptr<ISdlResource>>;
97 ResourceMapType m_nameToResource;
102 const auto& iter = m_nameToResource.find(resourceName);
103 return iter != m_nameToResource.end() ? iter->second :
nullptr;
110 const auto& iter = m_nameToResource.find(resourceName);
111 return iter != m_nameToResource.end();
116 std::vector<std::string>*
const out_resourceNames)
const
118 static_assert(std::is_base_of_v<ISdlResource, T>,
119 "T is not a SDL resource.");
121 std::vector<std::shared_ptr<T>> resources;
122 for(
const auto& [name, resource] : m_nameToResource)
124 std::shared_ptr<T> castedResource = std::dynamic_pointer_cast<T>(resource);
127 resources.push_back(std::move(castedResource));
129 if(out_resourceNames)
131 out_resourceNames->push_back(name);
140 std::vector<std::string>*
const out_resourceNames)
const
142 static_assert(std::is_base_of_v<ISdlResource, T>,
143 "T is not a SDL resource.");
145 std::vector<const T*> resources;
146 for(
const auto& [name, resource] : m_nameToResource)
148 T* castedResource =
dynamic_cast<T*
>(resource.get());
151 resources.push_back(castedResource);
153 if(out_resourceNames)
155 out_resourceNames->push_back(name);
View for a group of SDL references.
Definition ISdlReferenceGroup.h:18
Definition RawResourceCollection.h:21
std::vector< std::shared_ptr< ISdlResource > > getAll(std::vector< std::string > *out_resourceNames=nullptr) const
Get a list of all resources in the scene. See getAllOfType() for details on the method.
Definition RawResourceCollection.cpp:85
std::string rename(std::string_view resourceName, std::string_view newResourceName)
Rename a resource. The new name must be unique within this collection. If newResourceName is not a un...
Definition RawResourceCollection.cpp:47
std::vector< const T * > listAllOfType(std::vector< std::string > *out_resourceNames=nullptr) const
Get a list of all resources of type T. Does not involve any change in ownership. Useful for operation...
Definition RawResourceCollection.h:139
std::shared_ptr< ISdlResource > get(std::string_view resourceName) const override
Get a resource reference.
Definition RawResourceCollection.h:100
void add(std::shared_ptr< ISdlResource > resource, std::string_view resourceName)
Add a resource.
Definition RawResourceCollection.cpp:11
std::string makeResourceName(std::string_view intendedName)
Create a resource name that is unique within this collection.
Definition RawResourceCollection.cpp:63
std::vector< const ISdlResource * > listAll(std::vector< std::string > *out_resourceNames=nullptr) const
Get a list of all resources in the scene. See listAllOfType() for details on the method.
Definition RawResourceCollection.cpp:91
std::vector< std::shared_ptr< T > > getAllOfType(std::vector< std::string > *out_resourceNames=nullptr) const
Get all resources of type T. Different to its list<XXX>() variants, this method returns actual resour...
Definition RawResourceCollection.h:115
bool has(std::string_view resourceName) const override
Check the existence of a resource reference.
Definition RawResourceCollection.h:106
std::shared_ptr< ISdlResource > remove(std::string_view resourceName)
Remove a resource.
Definition RawResourceCollection.cpp:34
The root for all renderer implementations.
Definition EEngineProject.h:6