libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::Flag::ScopedRestore< FlagT > Class Template Reference

作用域标志管理器:构造时写入指定值,析构时恢复原值 / Scoped flag restorer: set on entry, restore on exit More...

#include <flag.hpp>

Public Member Functions

 ScopedRestore (FlagT &flag, bool set_value=true)
 构造函数:写入 set_value 并保存旧值 / Constructor: set set_value and store previous value
 
 ~ScopedRestore ()
 析构函数:恢复旧值 / Destructor: restore previous value
 
 ScopedRestore (const ScopedRestore &)=delete
 禁用拷贝构造与拷贝赋值 / Copy construction and copy assignment are disabled
 
ScopedRestoreoperator= (const ScopedRestore &)=delete
 

Private Attributes

FlagT & flag_
 被管理的标志对象 / Managed flag instance
 
bool prev_
 进入作用域前的旧值 / Previous value before entering scope
 

Detailed Description

template<typename FlagT>
class LibXR::Flag::ScopedRestore< FlagT >

作用域标志管理器:构造时写入指定值,析构时恢复原值 / Scoped flag restorer: set on entry, restore on exit

适用于“进入作用域临时改变 flag,退出恢复”的场景。 Useful when temporarily changing a flag within a scope and restoring it on exit.

Template Parameters
FlagT支持 Exchange(bool)->bool 的标志类型 / Flag type that provides Exchange(bool)->bool

Definition at line 198 of file flag.hpp.

Constructor & Destructor Documentation

◆ ScopedRestore()

template<typename FlagT >
LibXR::Flag::ScopedRestore< FlagT >::ScopedRestore ( FlagT & flag,
bool set_value = true )
inlineexplicit

构造函数:写入 set_value 并保存旧值 / Constructor: set set_value and store previous value

Parameters
flag需要管理的标志对象 / Flag instance to manage
set_value构造时写入的值 / Value to set on construction

Definition at line 208 of file flag.hpp.

209 : flag_(flag), prev_(flag_.Exchange(set_value))
210 {
211 }
bool prev_
进入作用域前的旧值 / Previous value before entering scope
Definition flag.hpp:226
FlagT & flag_
被管理的标志对象 / Managed flag instance
Definition flag.hpp:225

◆ ~ScopedRestore()

template<typename FlagT >
LibXR::Flag::ScopedRestore< FlagT >::~ScopedRestore ( )
inline

析构函数:恢复旧值 / Destructor: restore previous value

Definition at line 216 of file flag.hpp.

216{ (void)flag_.Exchange(prev_); }

Field Documentation

◆ flag_

template<typename FlagT >
FlagT& LibXR::Flag::ScopedRestore< FlagT >::flag_
private

被管理的标志对象 / Managed flag instance

Definition at line 225 of file flag.hpp.

◆ prev_

template<typename FlagT >
bool LibXR::Flag::ScopedRestore< FlagT >::prev_
private

进入作用域前的旧值 / Previous value before entering scope

Definition at line 226 of file flag.hpp.


The documentation for this class was generated from the following file: