VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
vlink::AbstractFactory< FilterT > Class Template Reference

Topic-keyed factory that creates and caches AbstractObject instances. More...

#include <abstract_factory.h>

Collaboration diagram for vlink::AbstractFactory< FilterT >:

Public Member Functions

bool has_object (Object *ptr) const
 Returns true if ptr is a live object tracked by this factory.
template<typename ObjectT>
std::shared_ptr< ObjectT > get_object (const FilterT &filter)
 Retrieves or creates the AbstractObject for the given filter key.

Protected Member Functions

 AbstractFactory ()
 Protected default constructor.
virtual ~AbstractFactory ()
 Protected virtual destructor.

Detailed Description

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

Topic-keyed factory that creates and caches AbstractObject instances.

Maintains a std::map<FilterT, std::weak_ptr<Object>> so that multiple NodeImpl instances sharing the same topic key reuse the same AbstractObject. Objects are reference-counted: the entry is automatically removed from the map when the last shared_ptr to the object is destroyed, preventing stale entries from accumulating.

Note
This class is not copy-constructible or copy-assignable.
Template Parameters
FilterTThe key type used to identify topics (e.g. std::string).

Constructor & Destructor Documentation

◆ AbstractFactory()

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

Protected default constructor.

Here is the caller graph for this function:

◆ ~AbstractFactory()

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

Protected virtual destructor.

Here is the call graph for this function:

Member Function Documentation

◆ get_object()

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

Retrieves or creates the AbstractObject for the given filter key.

If an object already exists for filter and is still alive (the weak_ptr is valid), the existing shared_ptr is returned. Otherwise a new ObjectT is heap-allocated, wrapped in a shared_ptr with a custom deleter that removes the entry from the internal map on destruction, and cached.

Template Parameters
ObjectTConcrete subclass of AbstractObject<FilterT> to instantiate.
Parameters
filterTopic key used to look up or create the object.
Returns
A shared_ptr<ObjectT> for the given filter.

◆ has_object()

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

Returns true if ptr is a live object tracked by this factory.

Checks the internal set of raw pointers to verify that ptr points to an object that was created by this factory and has not yet been destroyed.

Parameters
ptrRaw pointer to check.
Returns
true if the object is currently alive; false otherwise.

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