libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
BlockBoolUtil< BlockSize > Class Template Reference

读写对齐布尔位图块的工具 Helpers for reading and writing aligned boolean flag blocks. More...

#include <layout.hpp>

Static Public Member Functions

static void SetFlag (BlockBoolData< BlockSize > &obj, bool value)
 把一个布尔值编码进位图块 / Encode one boolean value into a flag block.
 
static bool ReadFlag (const BlockBoolData< BlockSize > &obj)
 从位图块读取布尔值 / Decode one boolean value from a flag block.
 
static bool Valid (const BlockBoolData< BlockSize > &obj)
 检查位图块内容是否仍是合法编码 / Check whether a flag block still contains a valid encoding.
 

Detailed Description

template<size_t BlockSize>
class BlockBoolUtil< BlockSize >

读写对齐布尔位图块的工具 Helpers for reading and writing aligned boolean flag blocks.

Template Parameters
BlockSize位图块字节数 / Flag-block size in bytes.

Definition at line 35 of file layout.hpp.

Member Function Documentation

◆ ReadFlag()

template<size_t BlockSize>
static bool BlockBoolUtil< BlockSize >::ReadFlag ( const BlockBoolData< BlockSize > & obj)
inlinestatic

从位图块读取布尔值 / Decode one boolean value from a flag block.

Parameters
obj待读取位图块 / Flag block to inspect.
Returns
解码出的布尔值 / Decoded boolean value.
Note
标志只会从 true(擦除态)写成 false,且只写一次;只要有一位已被编程, 就说明这次写入已经开始,因此只有整块都是 0xFF 才读作 true。被掉电打断的 写入读作它要写成的 false。 A flag is written at most once, from true (erased) to false; any programmed bit means that write has started, so only a fully erased block reads as true, and a write cut by a power loss reads as the false it was writing.

Definition at line 64 of file layout.hpp.

65 {
66 for (size_t i = 0; i < BlockSize; ++i)
67 {
68 if (obj.data[i] != 0xFF)
69 {
70 return false;
71 }
72 }
73 return true;
74 }

◆ SetFlag()

template<size_t BlockSize>
static void BlockBoolUtil< BlockSize >::SetFlag ( BlockBoolData< BlockSize > & obj,
bool value )
inlinestatic

把一个布尔值编码进位图块 / Encode one boolean value into a flag block.

Parameters
obj目标位图块 / Target flag block.
value待编码布尔值 / Boolean value to encode.

Definition at line 43 of file layout.hpp.

44 {
45 Memory::FastSet(obj.data, 0xFF, BlockSize);
46 if (!value)
47 {
48 obj.data[BlockSize - 1] &= 0xF0;
49 }
50 }

◆ Valid()

template<size_t BlockSize>
static bool BlockBoolUtil< BlockSize >::Valid ( const BlockBoolData< BlockSize > & obj)
inlinestatic

检查位图块内容是否仍是合法编码 / Check whether a flag block still contains a valid encoding.

Parameters
obj待检查位图块 / Flag block to validate.
Returns
若编码合法则返回 true / Returns true when the encoding is valid.

Definition at line 82 of file layout.hpp.

83 {
84 if (BlockSize == 0)
85 {
86 return false;
87 }
88
89 for (size_t i = 0; i < BlockSize - 1; ++i)
90 {
91 if (obj.data[i] != 0xFF)
92 {
93 return false;
94 }
95 }
96
97 uint8_t last_byte = obj.data[BlockSize - 1];
98 if ((last_byte & 0xF0) != 0xF0)
99 {
100 return false;
101 }
102
103 uint8_t last_4bits = last_byte & 0x0F;
104 if (!(last_4bits == 0x0F || last_4bits == 0x00))
105 {
106 return false;
107 }
108
109 return true;
110 }

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