libcruft-util/debug/fpe.hpp

40 lines
1.2 KiB
C++

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2021, Danny Robson <danny@nerdcruft.net>
*/
///////////////////////////////////////////////////////////////////////////////
namespace cruft::debug::fpe {
void enable (void);
void disable (void);
bool value (void);
bool value (bool);
/// Returns the FPE state to the value it was at construction time when the object falls out of scope.
///
/// Copy and move constructors are deliberately deleted to avoid accidentally leaking state.
class scoped_reset {
public:
/// An explict enablement state to enact at construction.
scoped_reset (bool enabled);
/// Caches the current state without changing anything.
scoped_reset ();
scoped_reset (scoped_reset const&) = delete;
scoped_reset& operator= (scoped_reset const&) = delete;
scoped_reset (scoped_reset &&) noexcept = delete;
scoped_reset& operator= (scoped_reset &&) noexcept = delete;
~scoped_reset ();
private:
bool m_prev;
};
}