libxr  1.0
Want to be the best embedded framework
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).

Definition at line 57 of file layout.hpp.

58 {
59 uint8_t last_4bits = obj.data[BlockSize - 1] & 0x0F;
60 return last_4bits == 0x0F;
61 }

◆ 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 69 of file layout.hpp.

70 {
71 if (BlockSize == 0)
72 {
73 return false;
74 }
75
76 for (size_t i = 0; i < BlockSize - 1; ++i)
77 {
78 if (obj.data[i] != 0xFF)
79 {
80 return false;
81 }
82 }
83
84 uint8_t last_byte = obj.data[BlockSize - 1];
85 if ((last_byte & 0xF0) != 0xF0)
86 {
87 return false;
88 }
89
90 uint8_t last_4bits = last_byte & 0x0F;
91 if (!(last_4bits == 0x0F || last_4bits == 0x00))
92 {
93 return false;
94 }
95
96 return true;
97 }

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