almost finish CKGroup
This commit is contained in:
30
LibCmo/XContainer/XBitArray.cpp
Normal file
30
LibCmo/XContainer/XBitArray.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include "XBitArray.hpp"
|
||||
|
||||
namespace LibCmo::XContainer::XBitArrayPatch {
|
||||
|
||||
template<bool _Cond>
|
||||
bool GeneralGetBitPosition(XBitArray& ba, CK2::CKDWORD n, CK2::CKDWORD& got) {
|
||||
CK2::CKDWORD counter = 0;
|
||||
for (size_t i = 0; i < ba.size(); ++i) {
|
||||
if (ba[i] == _Cond) {
|
||||
if (counter == n) {
|
||||
got = static_cast<CK2::CKDWORD>(i);
|
||||
return true;
|
||||
} else {
|
||||
++counter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GetSetBitPosition(XBitArray& ba, CK2::CKDWORD n, CK2::CKDWORD& got) {
|
||||
return GeneralGetBitPosition<true>(ba, n, got);
|
||||
}
|
||||
|
||||
bool GetUnsetBitPosition(XBitArray& ba, CK2::CKDWORD n, CK2::CKDWORD& got) {
|
||||
return GeneralGetBitPosition<false>(ba, n, got);
|
||||
}
|
||||
|
||||
}
|
17
LibCmo/XContainer/XBitArray.hpp
Normal file
17
LibCmo/XContainer/XBitArray.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "XTypes.hpp"
|
||||
|
||||
namespace LibCmo::XContainer::XBitArrayPatch {
|
||||
|
||||
/**
|
||||
* @brief Returns the position of the n-th set(1) bit
|
||||
* @return false if not found.
|
||||
*/
|
||||
bool GetSetBitPosition(XBitArray& ba, CK2::CKDWORD n, CK2::CKDWORD& got);
|
||||
/**
|
||||
* @brief Returns the position of the n-th unset(0) bit
|
||||
* @return false if not found.
|
||||
*/
|
||||
bool GetUnsetBitPosition(XBitArray& ba, CK2::CKDWORD n, CK2::CKDWORD& got);
|
||||
|
||||
}
|
Reference in New Issue
Block a user