lmms
Cross-platform music production software
Loading...
Searching...
No Matches
lmms::FileResourceCache< T > Class Template Reference

A non-owning cache for resources loaded from file paths. More...

#include <FileResourceCache.h>

Classes

struct  Entry

Public Member Functions

template<typename Factory>
requires (std::is_invocable_r_v<std::shared_ptr<const T>, Factory>)
auto fetch (const std::filesystem::path &path, Factory &&factory) -> std::shared_ptr< const T >

Private Attributes

std::unordered_map< std::filesystem::path, Entry > m_entries

Detailed Description

template<typename T>
class lmms::FileResourceCache< T >

A non-owning cache for resources loaded from file paths.

Todo
In the future, this class should have a cache replacement policy in order to cache unused resources temporarily until they are requested again, or if the eviction criteria is met.
Template Parameters
TThe type of resource to cache.

Member Function Documentation

◆ fetch()

template<typename T>
template<typename Factory>
requires (std::is_invocable_r_v<std::shared_ptr<const T>, Factory>)
auto lmms::FileResourceCache< T >::fetch ( const std::filesystem::path & path,
Factory && factory ) -> std::shared_ptr< const T >
inline

Retrieves a cached resource or creates a new one.

The factory must be invocable without arguments and return a std::shared_ptr<const T>.

If the factory returns nullptr, no resource is cached.

Parameters
pathFilesystem path identifying the resource.
factoryCallable used to create the resource when necessary.
Returns
The cached or newly created resource, or nullptr on failure.

Member Data Documentation

◆ m_entries

template<typename T>
std::unordered_map<std::filesystem::path, Entry> lmms::FileResourceCache< T >::m_entries
private

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