Celeritas 0.6.0-93+develop.7a7d9941
|
Hold a shared pointer across test cases and clean at teardown. More...
#include <PersistentSP.hh>
Public Types | |
Type aliases | |
using | SP = std::shared_ptr< T > |
Public Member Functions | |
PersistentSP (std::string &&desc) | |
Register the environment on construction. | |
operator bool () const | |
Whether a value is stored. | |
void | set (std::string &&key, SP &&ptr) |
Replace the pointer. | |
void | clear () |
Clear stored value. | |
std::string const & | key () const |
Access the key (empty if unset) | |
SP const & | value () const |
Access the pointer (null if unset) | |
Hold a shared pointer across test cases and clean at teardown.
Keep a static
instance of this class inside a test harness (or anywhere); it will register a cleanup function in GoogleTest that will fire before the end of the program.
This is needed to manage persistent objects that use static storage duration, such as VecGeom. For those cases, a static object that cleans up VecGeom on teardown may be called after VecGeom's static destructors, since static initialization/destruction order is undefined across translation units.