ONE - On-device Neural Engine
Loading...
Searching...
No Matches
loco::ObjectPool< T > Class Template Reference

Object Pool. More...

#include <ObjectPool.h>

Public Member Functions

virtual ~ObjectPool ()=default
 
uint32_t size (void) const
 Return the number of objects.
 
T * at (uint32_t n) const
 Access N-th object.
 

Protected Member Functions

template<typename U >
U * take (std::unique_ptr< U > &&o)
 Take the ownership of a given object and returns its raw pointer.
 
bool erase (T *ptr)
 Erase an object from the pool.
 

Detailed Description

template<typename T>
class loco::ObjectPool< T >

Object Pool.

Note
ObjectPool owns registered objects.

Definition at line 31 of file ObjectPool.h.

Constructor & Destructor Documentation

◆ ~ObjectPool()

template<typename T >
virtual loco::ObjectPool< T >::~ObjectPool ( )
virtualdefault

Member Function Documentation

◆ at()

◆ erase()

template<typename T >
bool loco::ObjectPool< T >::erase ( T *  ptr)
inlineprotected

Erase an object from the pool.

erase(p) returns false if p does not belong to this object pool.

Definition at line 57 of file ObjectPool.h.

58 {
59 auto pred = [ptr](const std::unique_ptr<T> &o) { return o.get() == ptr; };
60 auto it = std::find_if(_pool.begin(), _pool.end(), pred);
61
62 if (it == _pool.end())
63 {
64 return false;
65 }
66
67 _pool.erase(it);
68 return true;
69 }

◆ size()

template<typename T >
uint32_t loco::ObjectPool< T >::size ( void  ) const
inline

◆ take()

template<typename T >
template<typename U >
U * loco::ObjectPool< T >::take ( std::unique_ptr< U > &&  o)
inlineprotected

Take the ownership of a given object and returns its raw pointer.

Definition at line 45 of file ObjectPool.h.

46 {
47 auto res = o.get();
48 _pool.emplace_back(std::move(o));
49 return res;
50 }

Referenced by loco::Graph::SimpleFactoryObjectPool< T >::create().


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