| 26 | using ReusableObject = ObjectPoolEntry<Shared<Object>, void (*)(Shared<Object>&)>; |
| 27 | |
| 28 | class Pool { |
| 29 | public: |
| 30 | ReusableObject create() { |
| 31 | return _innerPool.getOrCreate( |
| 32 | [&]() { |
| 33 | _createdObjectsCount++; |
| 34 | return Valdi::makeShared<Object>(); |
| 35 | }, |
| 36 | &cleanUpObject); |
| 37 | } |
| 38 | |
| 39 | int getCreatedObjectsCount() const { |
| 40 | return _createdObjectsCount; |
| 41 | } |
| 42 | |
| 43 | private: |
| 44 | ObjectPoolInner<Shared<Object>> _innerPool; |
| 45 | int _createdObjectsCount = 0; |
| 46 | }; |
| 47 | |
| 48 | TEST(ObjectPool, canCreateAndReuse) { |
| 49 | auto pool = Pool(); |