80 const T old = reference;
84 return ScopeGuard([&reference, old]() { reference = old; });
110 const T old = reference;
111 reference = newValue;
112 return ScopeGuard([&reference, old]() { reference = old; });
136 template<
class Getter,
class Setter> [[nodiscard]]
139 const auto old = getter();
140 return ScopeGuard([setter, old]() { setter(old); });
167 template<
class Getter,
class Setter> [[nodiscard]]
169 const typename std::result_of<Getter()>::type newValue)
171 const auto old = getter();
173 return ScopeGuard([setter, old]() { setter(old); });
190 typedef typename std::invoke_result<Functor>::type value_type;
191 std::function<void(
const value_type&)> setter(functor);
192 const auto old = functor();
193 return ScopeGuard([setter, old] {setter(old);});
209 template<
class Functor> [[nodiscard]]
212 typedef typename std::invoke_result<Functor>::type value_type;
213 std::function<void(
const value_type&)> setter(functor);
214 const auto old = functor();
216 return ScopeGuard([setter, old] {setter(old);});
241 return ScopeGuard([&pointer]() {
delete pointer; pointer =
nullptr; });
261 template<
class CharT,
class Traits =
typename std::
char_traits<CharT>> [[nodiscard]]
264 const std::ios::fmtflags flags{stream.flags()};
265 const std::streamsize precision{stream.precision()};
266 const std::streamsize width{stream.width()};
267 const CharT fill{stream.fill()};
271 stream.precision(precision);
298 const std::string old{gSystem->GetWorkingDirectory()};
299 return ScopeGuard([old]() {gSystem->ChangeDirectory(old.c_str());});
325 const std::string old{gSystem->GetWorkingDirectory()};
326 gSystem->ChangeDirectory(newDirectory.c_str());
327 return ScopeGuard([old]() {gSystem->ChangeDirectory(old.c_str());});
354 auto getBatchMode = []() {
355 return gROOT->IsBatch();
358 auto setBatchMode = [](
bool batchMode_) {
359 gROOT->SetBatch(batchMode_);
Simple ScopeGuard to execute a function at the end of the object lifetime.
static ScopeGuard guardStreamState(std::basic_ios< CharT, Traits > &stream)
Create a ScopeGuard for the state of a stream to reset all the formatting at the end of the object li...
static ScopeGuard guardValue(T &reference)
Create a ScopeGuard for a value: The content of reference will be copied and reset when the returned ...
ScopeGuard(Callable &&f)
Construct a object with a callable function to be called on destruction.
void release()
Release the guard without calling the cleanup function.
ScopeGuard(const ScopeGuard &)=delete
No copies.
std::function< void()> m_exitfunc
Function to be called on exit.
static ScopeGuard guardGetterSetter(Getter getter, Setter setter)
Create a ScopeGuard from a getter and setter: On construction the getter object is called to obtain a...
ScopeGuard & operator=(ScopeGuard &&)=delete
No move assignment.
static ScopeGuard guardDeletion(T *&pointer)
Create a ScopeGuard to delete a raw pointer at the end of the scope.
static ScopeGuard guardFunctor(Functor functor)
Create a ScopeGuard from a functor object with appropriately overloaded operator() calls to get and s...
static ScopeGuard guardValue(T &reference, const V &newValue)
Create a ScopeGuard for a value: The content of reference will be copied and reset when the returned ...
~ScopeGuard()
Call function on destruct unless released has been called.
static ScopeGuard guardWorkingDirectory(const std::string &newDirectory)
Create a ScopeGuard of the current working directory and change into a new directory.
static ScopeGuard guardBatchMode(bool batchMode=true)
Create a ScopeGuard to turn ROOT into batch mode and restore the initial batch mode status after the ...
bool m_engaged
Indicate whether function should be called.
static ScopeGuard guardGetterSetter(const Getter &getter, Setter setter, const typename std::result_of< Getter()>::type newValue)
Create a ScopeGuard from a getter and setter: On construction first the getter is called to get the o...
static ScopeGuard guardFunctor(Functor functor, const typename std::result_of< Functor()>::type &newValue)
Create a ScopeGuard from a functor object with appropriately overloaded operator() calls to get and s...
static ScopeGuard guardWorkingDirectory()
Create a ScopeGuard of the current working directory.
ScopeGuard(ScopeGuard &&sg)=delete
No move construction.
ScopeGuard & operator=(const ScopeGuard &)=delete
No assignment.
Abstract base class for different kinds of events.