flyweight.hpp
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
flyweight::flyweight_refcounted< T, Args > Class Template Reference

#include <flyweight.hpp>

Inheritance diagram for flyweight::flyweight_refcounted< T, Args >:
flyweight::flyweight< detail::refcounted_value< T >, Args... >

Public Types

using autorelease_value = autorelease_value< T, flyweight_refcounted, std::tuple< Args... > >
 

Public Member Functions

 flyweight_refcounted ()
 
template<typename Creator >
 flyweight_refcounted (Creator &&creator)
 
template<typename Creator , typename Deleter >
 flyweight_refcounted (Creator &&creator, Deleter &&deleter)
 
T & get (const std::tuple< Args... > &arg_tuple)
 
template<bool uses_multiple_args = (sizeof...(Args) > 1)>
auto get (Args &&... args) -> typename std::enable_if< uses_multiple_args, T & >::type
 Alternative to flyweight_refcounted::get with the arguments unpacked.
 
autorelease_value get_autorelease (const std::tuple< Args... > &arg_tuple)
 
template<bool uses_multiple_args = (sizeof...(Args) > 1)>
auto get_autorelease (Args &&... args) -> typename std::enable_if< uses_multiple_args, autorelease_value >::type
 Alternative to flyweight_refcounted::get_autorelease with the arguments unpacked.
 
size_t reference_count (const std::tuple< Args... > &arg_tuple) const
 
template<bool uses_multiple_args = (sizeof...(Args) > 1)>
auto reference_count (Args &&... args) const -> typename std::enable_if< uses_multiple_args, size_t >::type
 Alternative to flyweight_refcounted::reference_count with the arguments unpacked.
 
bool release (const std::tuple< Args... > &arg_tuple)
 
template<bool uses_multiple_args = (sizeof...(Args) > 1)>
auto release (Args &&... args) -> typename std::enable_if< uses_multiple_args, bool >::type
 Alternative to flyweight_refcounted::release with the arguments unpacked.
 

Detailed Description

template<typename T, typename... Args>
class flyweight::flyweight_refcounted< T, Args >

flyweight subclass that employs reference counting.

The reference count increments for each call to flyweight_refcounted::get and decrements for each call to flyweight_refcounted::release using the same arguments. When calling flyweight_refcounted::release, the value is actually deleted from the cache only when the reference count reaches zero.

This is specially useful for implementing resource management of heavy objects, like images used as icons in an interactive app.

See also
flyweight

Constructor & Destructor Documentation

◆ flyweight_refcounted() [1/3]

template<typename T , typename... Args>
flyweight::flyweight_refcounted< T, Args >::flyweight_refcounted ( )
inline
See also
flyweight()

◆ flyweight_refcounted() [2/3]

template<typename T , typename... Args>
template<typename Creator >
flyweight::flyweight_refcounted< T, Args >::flyweight_refcounted ( Creator &&  creator)
inline

◆ flyweight_refcounted() [3/3]

template<typename T , typename... Args>
template<typename Creator , typename Deleter >
flyweight::flyweight_refcounted< T, Args >::flyweight_refcounted ( Creator &&  creator,
Deleter &&  deleter 
)
inline

Member Function Documentation

◆ get() [1/2]

template<typename T , typename... Args>
T & flyweight::flyweight_refcounted< T, Args >::get ( const std::tuple< Args... > &  arg_tuple)
inline

Override for flyweight::get with reference counting.

See also
flyweight::get

◆ get() [2/2]

template<typename T , typename... Args>
template<bool uses_multiple_args = (sizeof...(Args) > 1)>
auto flyweight::flyweight_refcounted< T, Args >::get ( Args &&...  args) -> typename std::enable_if<uses_multiple_args, T&>::type
inline

Alternative to flyweight_refcounted::get with the arguments unpacked.

◆ get_autorelease() [1/2]

template<typename T , typename... Args>
autorelease_value flyweight::flyweight_refcounted< T, Args >::get_autorelease ( const std::tuple< Args... > &  arg_tuple)
inline

Override for flyweight::get_autorelease with reference counting.

See also
flyweight::get_autorelease

◆ get_autorelease() [2/2]

template<typename T , typename... Args>
template<bool uses_multiple_args = (sizeof...(Args) > 1)>
auto flyweight::flyweight_refcounted< T, Args >::get_autorelease ( Args &&...  args) -> typename std::enable_if<uses_multiple_args, autorelease_value>::type
inline

Alternative to flyweight_refcounted::get_autorelease with the arguments unpacked.

◆ reference_count() [1/2]

template<typename T , typename... Args>
size_t flyweight::flyweight_refcounted< T, Args >::reference_count ( const std::tuple< Args... > &  arg_tuple) const
inline

Checks the current reference count for the value mapped to the passed arguments.

See also
reference_count_tuple

◆ reference_count() [2/2]

template<typename T , typename... Args>
template<bool uses_multiple_args = (sizeof...(Args) > 1)>
auto flyweight::flyweight_refcounted< T, Args >::reference_count ( Args &&...  args) const -> typename std::enable_if<uses_multiple_args, size_t>::type
inline

Alternative to flyweight_refcounted::reference_count with the arguments unpacked.

◆ release() [1/2]

template<typename T , typename... Args>
bool flyweight::flyweight_refcounted< T, Args >::release ( const std::tuple< Args... > &  arg_tuple)
inline

Override for flyweight::release with reference counting. The value will actually be released only when the reference count reaches zero.

◆ release() [2/2]

template<typename T , typename... Args>
template<bool uses_multiple_args = (sizeof...(Args) > 1)>
auto flyweight::flyweight_refcounted< T, Args >::release ( Args &&...  args) -> typename std::enable_if<uses_multiple_args, bool>::type
inline

Alternative to flyweight_refcounted::release with the arguments unpacked.


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