galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
galaxy::resource::Cache< Resource, Loader > Class Template Referencefinal

Cache for resources such as audio, fonts, etc. More...

#include <Cache.hpp>

+ Collaboration diagram for galaxy::resource::Cache< Resource, Loader >:

Public Member Functions

 Cache () noexcept
 Constructor.
 
 ~Cache ()
 Destructor.
 
void load (const std::string &file)
 Load a resource.
 
void load_folder (const std::string &dir)
 Load resources of a specific type.
 
void insert (std::string_view id, std::unique_ptr< Resource > &resource)
 Insert a resource directly into the cache.
 
Resource * get (std::string_view id)
 Retrieve a resource.
 
void clear ()
 Destroy resources.
 
bool has (std::string_view id)
 Check if a resource exists.
 
bool empty () const
 Does the cache have any resources.
 
std::size_t size () const
 Get amount of resources cached.
 
const CacheTypecache () const
 Get entire resource cache.
 
const meta::vector< std::string > & keys ()
 Get a list of keys in the cache.
 

Private Types

using CacheType = ankerl::unordered_dense::map<std::uint64_t, std::unique_ptr<Resource>>
 

Private Member Functions

 Cache (const Cache &)=delete
 Copy constructor.
 
 Cache (Cache &&)=delete
 Move constructor.
 
Cacheoperator= (const Cache &)=delete
 Copy assignment operator.
 
Cacheoperator= (Cache &&)=delete
 Move assignment operator.
 
std::uint64_t hash (std::string_view str)
 Hashes the key into an integer for faster map lookup time.
 

Private Attributes

Loader m_loader
 Used to load a resource into the cache. Allows for flexiblity.
 
CacheType m_cache
 The actual data store.
 
meta::vector< std::string > m_keys
 A list of keys currently in the cache.
 

Detailed Description

template<meta::not_memory Resource, meta::not_memory Loader>
class galaxy::resource::Cache< Resource, Loader >

Cache for resources such as audio, fonts, etc.

Template Parameters
ResourceType of resource to manage.
LoaderLoader to use when loading the resource.

Definition at line 30 of file Cache.hpp.

Member Typedef Documentation

◆ CacheType

template<meta::not_memory Resource, meta::not_memory Loader>
using galaxy::resource::Cache< Resource, Loader >::CacheType = ankerl::unordered_dense::map<std::uint64_t, std::unique_ptr<Resource>>
private

Definition at line 32 of file Cache.hpp.

Constructor & Destructor Documentation

◆ Cache() [1/3]

template<meta::not_memory Resource, meta::not_memory Loader>
galaxy::resource::Cache< Resource, Loader >::Cache ( )
inlinenoexcept

Constructor.

Definition at line 38 of file Cache.hpp.

◆ ~Cache()

template<meta::not_memory Resource, meta::not_memory Loader>
galaxy::resource::Cache< Resource, Loader >::~Cache ( )
inline

Destructor.

Definition at line 45 of file Cache.hpp.

+ Here is the call graph for this function:

◆ Cache() [2/3]

template<meta::not_memory Resource, meta::not_memory Loader>
galaxy::resource::Cache< Resource, Loader >::Cache ( const Cache< Resource, Loader > & )
privatedelete

Copy constructor.

◆ Cache() [3/3]

template<meta::not_memory Resource, meta::not_memory Loader>
galaxy::resource::Cache< Resource, Loader >::Cache ( Cache< Resource, Loader > && )
privatedelete

Move constructor.

Member Function Documentation

◆ load()

template<meta::not_memory Resource, meta::not_memory Loader>
void galaxy::resource::Cache< Resource, Loader >::load ( const std::string & file)
inline

Load a resource.

Parameters
fileFile to load. Also serves as key hash.

Definition at line 55 of file Cache.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load_folder()

template<meta::not_memory Resource, meta::not_memory Loader>
void galaxy::resource::Cache< Resource, Loader >::load_folder ( const std::string & dir)
inline

Load resources of a specific type.

Parameters
dirThe directory in the vfs to load assets from.

Definition at line 66 of file Cache.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insert()

template<meta::not_memory Resource, meta::not_memory Loader>
void galaxy::resource::Cache< Resource, Loader >::insert ( std::string_view id,
std::unique_ptr< Resource > & resource )
inline

Insert a resource directly into the cache.

Parameters
idKey to use to access resource.
resourcePointer to resource to take ownership of.

Definition at line 82 of file Cache.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get()

template<meta::not_memory Resource, meta::not_memory Loader>
Resource * galaxy::resource::Cache< Resource, Loader >::get ( std::string_view id)
inlinenodiscard

Retrieve a resource.

Parameters
idKey to use to access resource.
Returns
Returns a shared pointer to the resource.

Definition at line 103 of file Cache.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clear()

template<meta::not_memory Resource, meta::not_memory Loader>
void galaxy::resource::Cache< Resource, Loader >::clear ( )
inline

Destroy resources.

Definition at line 118 of file Cache.hpp.

+ Here is the caller graph for this function:

◆ has()

template<meta::not_memory Resource, meta::not_memory Loader>
bool galaxy::resource::Cache< Resource, Loader >::has ( std::string_view id)
inlinenodiscard

Check if a resource exists.

Parameters
idKey to use to access resource.
Returns
True if resource was found.

Definition at line 131 of file Cache.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ empty()

template<meta::not_memory Resource, meta::not_memory Loader>
bool galaxy::resource::Cache< Resource, Loader >::empty ( ) const
inlinenodiscard

Does the cache have any resources.

Returns
True if empty, false otherwise.

Definition at line 142 of file Cache.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ size()

template<meta::not_memory Resource, meta::not_memory Loader>
std::size_t galaxy::resource::Cache< Resource, Loader >::size ( ) const
inlinenodiscard

Get amount of resources cached.

Definition at line 151 of file Cache.hpp.

+ Here is the caller graph for this function:

◆ cache()

template<meta::not_memory Resource, meta::not_memory Loader>
const CacheType & galaxy::resource::Cache< Resource, Loader >::cache ( ) const
inlinenodiscard

Get entire resource cache.

Returns
Const reference to the resource cache.

Definition at line 162 of file Cache.hpp.

◆ keys()

template<meta::not_memory Resource, meta::not_memory Loader>
const meta::vector< std::string > & galaxy::resource::Cache< Resource, Loader >::keys ( )
inlinenodiscard

Get a list of keys in the cache.

Returns
A vector of char pointers.

Definition at line 173 of file Cache.hpp.

+ Here is the caller graph for this function:

◆ operator=() [1/2]

template<meta::not_memory Resource, meta::not_memory Loader>
Cache & galaxy::resource::Cache< Resource, Loader >::operator= ( const Cache< Resource, Loader > & )
privatedelete

Copy assignment operator.

◆ operator=() [2/2]

template<meta::not_memory Resource, meta::not_memory Loader>
Cache & galaxy::resource::Cache< Resource, Loader >::operator= ( Cache< Resource, Loader > && )
privatedelete

Move assignment operator.

◆ hash()

template<meta::not_memory Resource, meta::not_memory Loader>
std::uint64_t galaxy::resource::Cache< Resource, Loader >::hash ( std::string_view str)
inlineprivate

Hashes the key into an integer for faster map lookup time.

Definition at line 202 of file Cache.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_loader

template<meta::not_memory Resource, meta::not_memory Loader>
Loader galaxy::resource::Cache< Resource, Loader >::m_loader
private

Used to load a resource into the cache. Allows for flexiblity.

Definition at line 212 of file Cache.hpp.

◆ m_cache

template<meta::not_memory Resource, meta::not_memory Loader>
CacheType galaxy::resource::Cache< Resource, Loader >::m_cache
private

The actual data store.

Definition at line 217 of file Cache.hpp.

◆ m_keys

template<meta::not_memory Resource, meta::not_memory Loader>
meta::vector<std::string> galaxy::resource::Cache< Resource, Loader >::m_keys
private

A list of keys currently in the cache.

Definition at line 222 of file Cache.hpp.


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