16 #ifndef SURGSIM_FRAMEWORK_REUSEFACTORY_H
17 #define SURGSIM_FRAMEWORK_REUSEFACTORY_H
71 std::shared_ptr<T> object;
75 object = std::shared_ptr<T>(
new T(),
Deleter(
this));
123 #endif // SURGSIM_FRAMEWORK_REUSEFACTORY_H
Definition: DriveElementFromInputBehavior.cpp:27
ReuseFactory()
Constructor. Initially no unused objects are available, so returned instances are new allocations...
Definition: ReuseFactory.h:63
~ReuseFactory()
Destructor. Any remaining unused objects will be deleted.
Definition: ReuseFactory.h:65
std::stack< std::unique_ptr< T > > m_unusedObjects
Stack of objects that are available for reuse.
Definition: ReuseFactory.h:116
std::shared_ptr< T > getInstance()
Get a new or previously deleted object of class T.
Definition: ReuseFactory.h:69
Deleter(ReuseFactory *factory)
Constructor.
Definition: ReuseFactory.h:93
void addUnused(T *unusedObject)
Adds an object to the stack of unused objects.
Definition: ReuseFactory.h:110
ReuseFactory * m_factory
ReuseFactory with the collection of unused objects for reuse.
Definition: ReuseFactory.h:104
friend class Deleter
Custom Deleter is friended to manage unused objects rather than actually deleting them...
Definition: ReuseFactory.h:60
Custom deleter to keep unused objects for reuse, rather than actually deleting them.
Definition: ReuseFactory.h:88
Factory for acquiring new or unused existing instances of class T to reduce repeated deallocation and...
Definition: ReuseFactory.h:57
void operator()(T *unusedObject) const
Deletion method, adds the object to the ReuseFactory's collection.
Definition: ReuseFactory.h:98