Cogs.Core
Public Member Functions | Private Attributes | Friends | List of all members
Cogs::Core::ResourceStore Class Reference

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.
 
IIOHandlergetIOHandler ()
 Retrieve the IO handler interface.
 

Private Attributes

std::unique_ptr< struct ResourceStoreStoragedata
 

Friends

void resourceStoreInspector (Context *context, bool *show)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ResourceStore()

Cogs::Core::ResourceStore::ResourceStore ( class Context context)
explicit

Definition at line 280 of file ResourceStore.cpp.

Member Function Documentation

◆ addResource() [1/2]

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.

◆ addResource() [2/2]

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.

◆ addResourceArchive()

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.

◆ addSearchPath()

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.

◆ clear()

void Cogs::Core::ResourceStore::clear ( )

Clear the cache.

Definition at line 577 of file ResourceStore.cpp.

◆ getDataDir()

const std::string & Cogs::Core::ResourceStore::getDataDir ( ) const

Get the path of the data directory.

Definition at line 433 of file ResourceStore.cpp.

◆ getIOHandler()

Cogs::IIOHandler * Cogs::Core::ResourceStore::getIOHandler ( )

Retrieve the IO handler interface.

Definition at line 583 of file ResourceStore.cpp.

◆ getResourceContents()

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().

◆ getResourceContentString()

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

See also
getResourceContents to avoid the extra copy.

Definition at line 419 of file ResourceStore.cpp.

◆ getResourceLocation()

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.

◆ getResourcePath()

std::string Cogs::Core::ResourceStore::getResourcePath ( std::string_view  resourceName,
ResourceStoreFlags  flags = ResourceStoreFlags::None 
) const

Definition at line 473 of file ResourceStore.cpp.

◆ hasResource()

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.

◆ hasResources()

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.

◆ preloadResources()

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.

◆ purge()

void Cogs::Core::ResourceStore::purge ( const std::string &  resourceName)

Purge the given file from the cache.

Definition at line 558 of file ResourceStore.cpp.

Member Data Documentation

◆ data

std::unique_ptr<struct ResourceStoreStorage> Cogs::Core::ResourceStore::data
private

Definition at line 197 of file ResourceStore.h.


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