1 #ifndef UTILMM_AUTOFLAG_H 2 #define UTILMM_AUTOFLAG_H 4 #include <boost/noncopyable.hpp> 12 :
private boost::noncopyable
19 auto_flag(
int& field,
int mask,
bool value =
true,
bool restore_old =
true)
20 : m_field(field), m_mask(mask)
21 , m_restore(restore_old ?
get() : !value)
28 bool get() {
return (m_field & m_mask) == m_mask; }
30 { m_field = (m_field & ~m_mask) | (m_mask * static_cast<int>(value)); }
37 :
private boost::noncopyable
43 struct safe_bool_struct
45 typedef void (safe_bool_struct::*safe_bool)();
52 auto_flag(
bool& flag,
bool init =
true,
bool restore_old =
true)
53 : m_flag(flag), m_restore(restore_old ? flag : !init)
63 bool get()
const {
return m_flag; }
65 operator safe_bool()
const {
return m_flag ? &safe_bool_struct::method : 0; }
~auto_flag()
Definition: auto_flag.hh:26
Definition: auto_flag.hh:11
auto_flag(bool &flag, bool init=true, bool restore_old=true)
Definition: auto_flag.hh:52
Definition: auto_flag.hh:6
bool get()
Definition: auto_flag.hh:28
auto_flag(int &field, int mask, bool value=true, bool restore_old=true)
Definition: auto_flag.hh:19
~auto_flag()
Definition: auto_flag.hh:59