Cogs.Core
|
Provides handling of reading and caching of external resources. More...
#include <ResourceStore.h>
Public Member Functions | |
ResourceStore (class Context *context) | |
void | preloadResources (const std::vector< std::string > &resourceNames) |
Tells the resource system to fetch and cache the given resources. | |
bool | hasResources (const std::vector< std::string > &resourceNames) |
Check if all the given resources are present in the resource store. | |
bool | hasResource (const std::string &resourceName) |
Check if the given resource is present in the resource store. | |
void | addResource (std::string_view resourceName, const std::string_view content) |
Add the given resource string to the resource store. | |
void | addResource (std::string_view resourceName, const void *content_data, size_t content_size) |
Add the given resource contents to the resource store. | |
void | addResourceArchive (const std::string &archiveName, bool prepend=false) |
Add the given resource archive to the store. | |
std::string | getResourcePath (std::string_view resourceName, ResourceStoreFlags flags=ResourceStoreFlags::None) const |
ResourceQueryResult | getResourceLocation (std::string_view resourceName, ResourceStoreFlags flags=ResourceStoreFlags::None) const |
Get location data for the given resource. | |
ResourceBuffer | getResourceContents (std::string_view resourceName, ResourceStoreFlags flags=ResourceStoreFlags::None) const |
Get the contents of the resource with the given name. | |
std::string | getResourceContentString (std::string_view resourceName, ResourceStoreFlags flags=ResourceStoreFlags::None) const |
Get the contents of the resource with the given copied into a string. | |
void | addSearchPath (const std::string &path, bool prepend=false) |
Add the given path to the set of search paths used to look up resources. | |
const std::string & | getDataDir () const |
Get the path of the data directory. | |
void | purge (const std::string &resourceName) |
Purge the given file from the cache. | |
void | clear () |
Clear the cache. | |
IIOHandler * | getIOHandler () |
Retrieve the IO handler interface. | |
Private Attributes | |
std::unique_ptr< struct ResourceStoreStorage > | data |
Friends | |
void | resourceStoreInspector (Context *context, bool *show) |
Provides handling of reading and caching of external resources.
Accessing resource data can be done through the getResourceContent* methods. The way data is retrieved is as follows:
Definition at line 106 of file ResourceStore.h.
|
explicit |
Definition at line 280 of file ResourceStore.cpp.
void Cogs::Core::ResourceStore::addResource | ( | std::string_view | resourceName, |
const std::string_view | content | ||
) |
Add the given resource string to the resource store.
Definition at line 439 of file ResourceStore.cpp.
void Cogs::Core::ResourceStore::addResource | ( | std::string_view | resourceName, |
const void * | content_data, | ||
size_t | content_size | ||
) |
Add the given resource contents to the resource store.
Definition at line 451 of file ResourceStore.cpp.
void Cogs::Core::ResourceStore::addResourceArchive | ( | const std::string & | archiveName, |
bool | prepend = false |
||
) |
Add the given resource archive to the store.
Definition at line 463 of file ResourceStore.cpp.
void Cogs::Core::ResourceStore::addSearchPath | ( | const std::string & | path, |
bool | prepend = false |
||
) |
Add the given path to the set of search paths used to look up resources.
Set prepend to true to make the store find resources in the given path before paths already added
Definition at line 545 of file ResourceStore.cpp.
void Cogs::Core::ResourceStore::clear | ( | ) |
Clear the cache.
Definition at line 577 of file ResourceStore.cpp.
const std::string & Cogs::Core::ResourceStore::getDataDir | ( | ) | const |
Get the path of the data directory.
Definition at line 433 of file ResourceStore.cpp.
Cogs::IIOHandler * Cogs::Core::ResourceStore::getIOHandler | ( | ) |
Retrieve the IO handler interface.
Definition at line 583 of file ResourceStore.cpp.
Cogs::Core::ResourceBuffer Cogs::Core::ResourceStore::getResourceContents | ( | std::string_view | resourceName, |
ResourceStoreFlags | flags = ResourceStoreFlags::None |
||
) | const |
Get the contents of the resource with the given name.
Definition at line 362 of file ResourceStore.cpp.
References Cogs::Core::NoCachedContent, and Cogs::Core::PreferUncachedContent.
Referenced by Cogs::Core::IOHandler::resolveFile(), and Cogs::Core::ResourceArchive::ResourceArchive().
std::string Cogs::Core::ResourceStore::getResourceContentString | ( | std::string_view | resourceName, |
ResourceStoreFlags | flags = ResourceStoreFlags::None |
||
) | const |
Get the contents of the resource with the given copied into a string.
Consider using
Definition at line 419 of file ResourceStore.cpp.
Cogs::Core::ResourceQueryResult Cogs::Core::ResourceStore::getResourceLocation | ( | std::string_view | resourceName, |
ResourceStoreFlags | flags = ResourceStoreFlags::None |
||
) | const |
Get location data for the given resource.
Definition at line 494 of file ResourceStore.cpp.
References Cogs::Core::NoCachedContent.
std::string Cogs::Core::ResourceStore::getResourcePath | ( | std::string_view | resourceName, |
ResourceStoreFlags | flags = ResourceStoreFlags::None |
||
) | const |
Definition at line 473 of file ResourceStore.cpp.
bool Cogs::Core::ResourceStore::hasResource | ( | const std::string & | resourceName | ) |
Check if the given resource is present in the resource store.
Definition at line 341 of file ResourceStore.cpp.
bool Cogs::Core::ResourceStore::hasResources | ( | const std::vector< std::string > & | resourceNames | ) |
Check if all the given resources are present in the resource store.
Definition at line 330 of file ResourceStore.cpp.
void Cogs::Core::ResourceStore::preloadResources | ( | const std::vector< std::string > & | resourceNames | ) |
Tells the resource system to fetch and cache the given resources.
Definition at line 300 of file ResourceStore.cpp.
void Cogs::Core::ResourceStore::purge | ( | const std::string & | resourceName | ) |
Purge the given file from the cache.
Definition at line 558 of file ResourceStore.cpp.
|
private |
Definition at line 197 of file ResourceStore.h.