mirror of
https://github.com/espressif/openthread.git
synced 2026-07-26 05:53:45 +00:00
[bit-vector] refactor methods (#5302)
This commit refactors BitVector to use one method for setting or clearing masks.
This commit is contained in:
@@ -59,7 +59,7 @@ namespace ot {
|
||||
* @tparam N Specifies the number of bits.
|
||||
*
|
||||
*/
|
||||
template <uint16_t N> class BitVector : public Equatable<BitVector<N>>
|
||||
template <uint16_t N> class BitVector : public Equatable<BitVector<N>>, public Clearable<BitVector<N>>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -81,34 +81,23 @@ public:
|
||||
* This method sets the mask of a given index.
|
||||
*
|
||||
* @param[in] aIndex The index.
|
||||
* @param[in] aValue TRUE to set the mask, or FALSE to clear the mask.
|
||||
*
|
||||
*/
|
||||
void Set(uint16_t aIndex)
|
||||
void Set(uint16_t aIndex, bool aValue)
|
||||
{
|
||||
OT_ASSERT(aIndex < N);
|
||||
|
||||
mMask[aIndex / 8] |= 0x80 >> (aIndex % 8);
|
||||
if (aValue)
|
||||
{
|
||||
mMask[aIndex / 8] |= 0x80 >> (aIndex % 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
mMask[aIndex / 8] &= ~(0x80 >> (aIndex % 8));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* This method clears the mask of a given index.
|
||||
*
|
||||
* @param[in] aIndex The index.
|
||||
*
|
||||
*/
|
||||
void Clear(uint16_t aIndex)
|
||||
{
|
||||
OT_ASSERT(aIndex < N);
|
||||
|
||||
mMask[aIndex / 8] &= ~(0x80 >> (aIndex % 8));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method clears all indexes.
|
||||
*
|
||||
*/
|
||||
void ClearAll(void) { memset(mMask, 0, sizeof(mMask)); }
|
||||
|
||||
/**
|
||||
* This method returns if any mask is set.
|
||||
*
|
||||
|
||||
@@ -642,12 +642,12 @@ bool Message::GetChildMask(uint16_t aChildIndex) const
|
||||
|
||||
void Message::ClearChildMask(uint16_t aChildIndex)
|
||||
{
|
||||
GetMetadata().mChildMask.Clear(aChildIndex);
|
||||
GetMetadata().mChildMask.Set(aChildIndex, false);
|
||||
}
|
||||
|
||||
void Message::SetChildMask(uint16_t aChildIndex)
|
||||
{
|
||||
GetMetadata().mChildMask.Set(aChildIndex);
|
||||
GetMetadata().mChildMask.Set(aChildIndex, true);
|
||||
}
|
||||
|
||||
bool Message::IsChildPending(void) const
|
||||
|
||||
@@ -157,8 +157,8 @@ void Child::ClearIp6Addresses(void)
|
||||
mMeshLocalIid.Clear();
|
||||
memset(mIp6Address, 0, sizeof(mIp6Address));
|
||||
#if OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE
|
||||
mMlrToRegisterMask.ClearAll();
|
||||
mMlrRegisteredMask.ClearAll();
|
||||
mMlrToRegisterMask.Clear();
|
||||
mMlrRegisteredMask.Clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -318,23 +318,8 @@ void Child::SetAddressMlrState(const Ip6::Address &aAddress, MlrState aState)
|
||||
|
||||
addressIndex = static_cast<uint16_t>(&aAddress - mIp6Address);
|
||||
|
||||
if (aState == kMlrStateToRegister)
|
||||
{
|
||||
mMlrToRegisterMask.Set(addressIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
mMlrToRegisterMask.Clear(addressIndex);
|
||||
}
|
||||
|
||||
if (aState == kMlrStateRegistered)
|
||||
{
|
||||
mMlrRegisteredMask.Set(addressIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
mMlrRegisteredMask.Clear(addressIndex);
|
||||
}
|
||||
mMlrToRegisterMask.Set(addressIndex, aState == kMlrStateToRegister);
|
||||
mMlrRegisteredMask.Set(addressIndex, aState == kMlrStateRegistered);
|
||||
}
|
||||
#endif // OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user