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 >
Utake (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 32 of file ObjectPool.h.

Constructor & Destructor Documentation

◆ ~ObjectPool()

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

Member Function Documentation

◆ at()

template<typename T >
T * loco::ObjectPool< T >::at ( uint32_t  n) const
inline

◆ 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 58 of file ObjectPool.h.

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

References loco::must_cast().

◆ size()

◆ 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 46 of file ObjectPool.h.

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

References loco::must_cast().

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


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