Class ErrorModeLock
Defined in File errors.hpp
Class Documentation
A recursive lock on the current global navtk::ErrorMode (as reported by navtk::get_global_error_mode) that makes sure the value can only be changed by the current thread.
The lock is honored both by other navtk::ErrorModeLock instances and navtk::set_global_error_mode.
When an instance of ErrorModeLock is created, the current global ErrorMode is stored. If the
enable_restoreparameter istrue(the default), this saved state will be restored (regardless of any same-thread calls to navtk::set_global_error_mode that may have run during its lifetime).ErrorModeLock instances are backed by
std::unique_lock, and as such can be moved but not copied.Python users should use this object as a context manager (using the
withstatement) to ensure the lock is correctly released at the appropriate time.with navtk.ErrorModeLock(navtk.ErrorMode.OFF): # your code here
The ErrorModeLock python bindings are not threadsafe themselves. The
__enter__and__exit__methods (used by thewithstatement) should only be called by the thread that created the ErrorModeLock.Public Functions
Sets the value of the global ErrorMode (see navtk::get_global_error_mode) for the lifetime of this object.
- Parameters
target_mode – Mode to set.
enable_restore – Whether to restore the previous global error mode when this object goes out of scope.
Moves ownership of the lock to a new instance, preventing the original instance from changing the global state when it is destroyed.
- Parameters
src – Source object being moved-from
Deleted; use
std::moveinstead.
Deleted; causes nonsense behavior.
Deleted; causes nonsense behavior.
Protected Functions
Release the underlying lock and restore the previous navtk::ErrorMode.
C++ users should allow the destructor to be called instead; this function exists to allow Python users to use ErrorModeLock as a context manager.
Re-acquire the underlying lock and set the global error mode to the
target_modepassed into the constructor.C++ users should avoid this function; it exists to allow Python users to use ErrorModeLock as a context manager.