VLink  2.0.0
A high-performance communication middleware
vlink::AbstractFactory< FilterT > 模板类 参考

Lazily allocates and caches AbstractObject instances keyed by FilterT. 更多...

#include <abstract_factory.h>

vlink::AbstractFactory< FilterT > 的协作图:

Public 成员函数

bool has_object (Object *ptr) const
 Tests whether ptr corresponds to a live object created by this factory. 更多...
 
template<typename ObjectT >
std::shared_ptr< ObjectT > get_object (const FilterT &filter)
 Looks up or creates the ObjectT registered against filter. 更多...
 

Protected 成员函数

 AbstractFactory ()
 Constructs an empty factory. 更多...
 
virtual ~AbstractFactory ()
 Destroys the factory and releases the cache. 更多...
 

详细描述

template<typename FilterT>
class vlink::AbstractFactory< FilterT >

Lazily allocates and caches AbstractObject instances keyed by FilterT.

Holds a std::map<FilterT, std::weak_ptr<Object>> so that multiple node peers requesting the same key reuse the same registration record. The returned std::shared_ptr carries a custom deleter that erases the map entry when the last owner releases the object, which keeps the lookup map free of stale weak_ptr slots.

注解
The factory itself is non-copyable and non-movable; share it through a singleton or a per-transport static instance.
模板参数
FilterTTopic-key type (typically std::string).

构造及析构函数说明

◆ AbstractFactory()

template<typename FilterT >
vlink::AbstractFactory< FilterT >::AbstractFactory ( )
inlineprotecteddefault

Constructs an empty factory.

◆ ~AbstractFactory()

template<typename FilterT >
vlink::AbstractFactory< FilterT >::~AbstractFactory ( )
inlineprotectedvirtualdefault

Destroys the factory and releases the cache.

成员函数说明

◆ get_object()

template<typename FilterT >
template<typename ObjectT >
std::shared_ptr< ObjectT > vlink::AbstractFactory< FilterT >::get_object ( const FilterT &  filter)
inline

Looks up or creates the ObjectT registered against filter.

If the cached weak_ptr is still valid, the existing instance is shared with the caller. Otherwise a new ObjectT is allocated (outside the factory lock so its constructor can re-enter VLink safely), the resulting shared_ptr is given a deleter that removes the cache entry on destruction, and the value is stored back into the map.

模板参数
ObjectTConcrete subclass of AbstractObject<FilterT> to allocate.
参数
filterKey identifying the topic.
返回
Shared ownership handle for the cached object.

◆ has_object()

template<typename FilterT >
bool vlink::AbstractFactory< FilterT >::has_object ( Object ptr) const
inline

Tests whether ptr corresponds to a live object created by this factory.

参数
ptrRaw pointer to validate.
返回
true when the object is still alive in this factory; false otherwise.

该类的文档由以下文件生成: