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::Cache< Resource, SpecLoader > Class Template Referencefinal

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

#include <Cache.hpp>

+ Collaboration diagram for galaxy::Cache< Resource, SpecLoader >:

Public Member Functions

 Cache () noexcept
 Constructor.
 
 ~Cache ()
 Destructor.
 
void load_file (const std::string &file)
 Load a resource.
 
template<typename... Args>
requires meta::not_memory<Resource> && meta::is_class<Resource> && meta::is_instance_of_v<SpecLoader, Loader>
void load_resource (const std::string &key, Args &&... args)
 Loads a resource with custom args.
 
void load_folder (const std::string &dir)
 Load all resources in a folder.
 
void insert (const std::string &key, std::shared_ptr< Resource > resource) noexcept
 Insert a resource directly into the cache.
 
std::shared_ptr< Resource > get (const std::string &key) noexcept
 Get a resource.
 
bool has (const std::string &key) noexcept
 Check if a resource exists.
 
void clear ()
 Destroy all data in cache.
 
bool empty () const noexcept
 Does the cache have any resources.
 
std::size_t size () const noexcept
 Get amount of resources cached.
 
const Mapcache () const noexcept
 Get entire resource cache.
 

Private Types

using Map = ankerl::unordered_dense::map<std::uint64_t, std::shared_ptr<Resource>>
 Use a dense map for storage.
 

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.
 

Private Attributes

SpecLoader m_loader
 Flexible Loader used to create/load a Resource into the cache.
 
Map m_cache
 Resource storage map.
 

Detailed Description

template<typename Resource, typename SpecLoader>
requires meta::not_memory<Resource> && meta::is_class<Resource> && meta::is_instance_of_v<SpecLoader, Loader>
class galaxy::Cache< Resource, SpecLoader >

Cache for resources such as audio, fonts, etc.

Template Parameters
ResourceA resource is a class containing data, and cannot be a ref or ptr.
SpecLoaderA template specialization of a Loader, to load the Resource.

Definition at line 29 of file Cache.hpp.

Member Typedef Documentation

◆ Map

template<typename Resource , typename SpecLoader >
using galaxy::Cache< Resource, SpecLoader >::Map = ankerl::unordered_dense::map<std::uint64_t, std::shared_ptr<Resource>>
private

Use a dense map for storage.

Definition at line 34 of file Cache.hpp.

Constructor & Destructor Documentation

◆ Cache() [1/3]

template<typename Resource , typename SpecLoader >
requires meta::not_memory<Resource> && meta::is_class<Resource> && meta::is_instance_of_v<SpecLoader, Loader>
galaxy::Cache< Resource, SpecLoader >::Cache ( )
inlinenoexcept

Constructor.

Definition at line 168 of file Cache.hpp.

◆ ~Cache()

template<typename Resource , typename SpecLoader >
requires meta::not_memory<Resource> && meta::is_class<Resource> && meta::is_instance_of_v<SpecLoader, Loader>
galaxy::Cache< Resource, SpecLoader >::~Cache ( )
inline

Destructor.

Definition at line 174 of file Cache.hpp.

+ Here is the call graph for this function:

◆ Cache() [2/3]

template<typename Resource , typename SpecLoader >
galaxy::Cache< Resource, SpecLoader >::Cache ( const Cache< Resource, SpecLoader > & )
privatedelete

Copy constructor.

◆ Cache() [3/3]

template<typename Resource , typename SpecLoader >
galaxy::Cache< Resource, SpecLoader >::Cache ( Cache< Resource, SpecLoader > && )
privatedelete

Move constructor.

Member Function Documentation

◆ load_file()

template<typename Resource , typename SpecLoader >
requires meta::not_memory<Resource> && meta::is_class<Resource> && meta::is_instance_of_v<SpecLoader, Loader>
void galaxy::Cache< Resource, SpecLoader >::load_file ( const std::string & file)
inline

Load a resource.

Key becomes filename. This expects the resource to have a compatible string constructor.

Parameters
fileFile to load in VFS.

Definition at line 181 of file Cache.hpp.

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

◆ load_resource()

template<typename Resource , typename SpecLoader >
requires meta::not_memory<Resource> && meta::is_class<Resource> && meta::is_instance_of_v<SpecLoader, Loader>
template<typename... Args>
requires meta::not_memory<Resource> && meta::is_class<Resource> && meta::is_instance_of_v<SpecLoader, Loader>
void galaxy::Cache< Resource, SpecLoader >::load_resource ( const std::string & key,
Args &&... args )
inline

Loads a resource with custom args.

Template Parameters
ArgsArgument types.
Parameters
keyAccess key / resource name.
argsForward constructor args.

Definition at line 197 of file Cache.hpp.

+ Here is the call graph for this function:

◆ load_folder()

template<typename Resource , typename SpecLoader >
requires meta::not_memory<Resource> && meta::is_class<Resource> && meta::is_instance_of_v<SpecLoader, Loader>
void galaxy::Cache< Resource, SpecLoader >::load_folder ( const std::string & dir)
inline

Load all resources in a folder.

Key becomes filename. This expects the resource to have a compatible string constructor.

Parameters
dirThe directory in the vfs to load from.

Definition at line 212 of file Cache.hpp.

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

◆ insert()

template<typename Resource , typename SpecLoader >
requires meta::not_memory<Resource> && meta::is_class<Resource> && meta::is_instance_of_v<SpecLoader, Loader>
void galaxy::Cache< Resource, SpecLoader >::insert ( const std::string & key,
std::shared_ptr< Resource > resource )
inlinenoexcept

Insert a resource directly into the cache.

Parameters
keyAccess key / resource name.
resourceShared pointer to resource.

Definition at line 223 of file Cache.hpp.

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

◆ get()

template<typename Resource , typename SpecLoader >
requires meta::not_memory<Resource> && meta::is_class<Resource> && meta::is_instance_of_v<SpecLoader, Loader>
std::shared_ptr< Resource > galaxy::Cache< Resource, SpecLoader >::get ( const std::string & key)
inlinenodiscardnoexcept

Get a resource.

Parameters
keyName/id of resource.
Returns
Returns a shared pointer to the resource.

Definition at line 238 of file Cache.hpp.

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

◆ has()

template<typename Resource , typename SpecLoader >
requires meta::not_memory<Resource> && meta::is_class<Resource> && meta::is_instance_of_v<SpecLoader, Loader>
bool galaxy::Cache< Resource, SpecLoader >::has ( const std::string & key)
inlinenodiscardnoexcept

Check if a resource exists.

Parameters
keyName/id of resource.
Returns
True if resource was found.

Definition at line 251 of file Cache.hpp.

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

◆ clear()

template<typename Resource , typename SpecLoader >
requires meta::not_memory<Resource> && meta::is_class<Resource> && meta::is_instance_of_v<SpecLoader, Loader>
void galaxy::Cache< Resource, SpecLoader >::clear ( )
inline

Destroy all data in cache.

Definition at line 259 of file Cache.hpp.

+ Here is the caller graph for this function:

◆ empty()

template<typename Resource , typename SpecLoader >
requires meta::not_memory<Resource> && meta::is_class<Resource> && meta::is_instance_of_v<SpecLoader, Loader>
bool galaxy::Cache< Resource, SpecLoader >::empty ( ) const
inlinenodiscardnoexcept

Does the cache have any resources.

Returns
True if empty, false otherwise.

Definition at line 266 of file Cache.hpp.

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

◆ size()

template<typename Resource , typename SpecLoader >
requires meta::not_memory<Resource> && meta::is_class<Resource> && meta::is_instance_of_v<SpecLoader, Loader>
std::size_t galaxy::Cache< Resource, SpecLoader >::size ( ) const
inlinenodiscardnoexcept

Get amount of resources cached.

Definition at line 273 of file Cache.hpp.

+ Here is the caller graph for this function:

◆ cache()

template<typename Resource , typename SpecLoader >
requires meta::not_memory<Resource> && meta::is_class<Resource> && meta::is_instance_of_v<SpecLoader, Loader>
const Cache< Resource, SpecLoader >::Map & galaxy::Cache< Resource, SpecLoader >::cache ( ) const
inlinenodiscardnoexcept

Get entire resource cache.

Returns
Const reference to the resource cache.

Definition at line 280 of file Cache.hpp.

◆ operator=() [1/2]

template<typename Resource , typename SpecLoader >
Cache & galaxy::Cache< Resource, SpecLoader >::operator= ( const Cache< Resource, SpecLoader > & )
privatedelete

Copy assignment operator.

◆ operator=() [2/2]

template<typename Resource , typename SpecLoader >
Cache & galaxy::Cache< Resource, SpecLoader >::operator= ( Cache< Resource, SpecLoader > && )
privatedelete

Move assignment operator.

Member Data Documentation

◆ m_loader

template<typename Resource , typename SpecLoader >
SpecLoader galaxy::Cache< Resource, SpecLoader >::m_loader
private

Flexible Loader used to create/load a Resource into the cache.

Definition at line 158 of file Cache.hpp.

◆ m_cache

template<typename Resource , typename SpecLoader >
Map galaxy::Cache< Resource, SpecLoader >::m_cache
private

Resource storage map.

Definition at line 163 of file Cache.hpp.


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