Add helper to use stack variables with shared_ptr

If an interface requires a shared_ptr, but we have an object that is
known to outlive the client anyway, we can use a custom deleter to
suppress the delete part and pass this object around anyway.
This commit is contained in:
Roland Kaufmann 2013-11-08 12:45:21 +01:00
parent 568e597561
commit ede84e6cc8

View File

@ -31,6 +31,20 @@ namespace parameter { class ParameterGroup; }
class SimulatorTimer;
class WellState;
/*!
* Custom deleter that does nothing. This is usable when an interface
* needs a shared_ptr, but you want to pass an object that has local
* storage (and you know that the shared_ptr client doesn't need it
* outside of the scope).
*
* \example
* \code{.cpp}
* Foo obj;
* auto ptr = std::shared_ptr <Foo> (&obj, no_delete);
* \endcode
*/
inline void no_delete (void const *) { }
/*!
* Interface for writing non-compositional (blackoil, two-phase) simulation
* state to files.
@ -85,6 +99,8 @@ public:
* that is returned.
*
* @return Pointer to a multiplexer to all applicable output formats.
*
* @see Opm::no_delete
*/
static std::unique_ptr <OutputWriter>
create (const parameter::ParameterGroup& params,