libxr
Embedded C++ framework for bare-metal, RTOS and Linux
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
 
ScopedRestore & operator= (const ScopedRestore &)=delete
 

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 }

◆ ~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_); }

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