Doxygen
CachedItem< T, TOwner, creator > 模板类 参考

Wrapper for data that needs to be cached. 更多...

Public 成员函数

T & get (const TOwner *owner) const
 Returns a reference to the cached data. 更多...
 

Private 属性

std::once_flag m_cache_flag
 
m_item
 

详细描述

template<typename T, typename TOwner, T(TOwner::*)() const creator>
class CachedItem< T, TOwner, creator >

Wrapper for data that needs to be cached.

The cached data can be accessed via the get() method from multiple threads. The first thread that calls get() will trigger creation of the data item via the creator method, blocking other threads until the item is available in the cache.

模板参数
Tthe type of the data item in the cache.
TOwnerthe class containing the cached item.
creatorthe method of TOwner to call in order to create the data item to be cached.

在文件 context.cpp91 行定义.

成员函数说明

◆ get()

template<typename T , typename TOwner , T(TOwner::*)() const creator>
T& CachedItem< T, TOwner, creator >::get ( const TOwner *  owner) const
inline

Returns a reference to the cached data.

Conceptually this is a const method, i.e. it will always return the same data The first time it is called, the owner will be asked to create the data.

在文件 context.cpp98 行定义.

99  {
100  // create a lamda function to create the cached data
101  auto creatorFunc = [this,owner]() { m_item = (owner->*creator)(); };
102  // use std::call_once to let one thread invoke the creator func
103  std::call_once(m_cache_flag, creatorFunc);
104  // return the cached results
105  return m_item;
106  }

类成员变量说明

◆ m_cache_flag

template<typename T , typename TOwner , T(TOwner::*)() const creator>
std::once_flag CachedItem< T, TOwner, creator >::m_cache_flag
mutableprivate

◆ m_item

template<typename T , typename TOwner , T(TOwner::*)() const creator>
T CachedItem< T, TOwner, creator >::m_item
mutableprivate

该类的文档由以下文件生成:
CachedItem::m_cache_flag
std::once_flag m_cache_flag
Definition: context.cpp:108
CachedItem::m_item
T m_item
Definition: context.cpp:109