refactor project
This commit is contained in:
@ -1,30 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
#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);
|
||||
|
||||
}
|
49
LibCmo/XContainer/XTypes.cpp
Normal file
49
LibCmo/XContainer/XTypes.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
#include "XTypes.hpp"
|
||||
|
||||
namespace LibCmo::XContainer {
|
||||
|
||||
namespace NSXBitArray {
|
||||
|
||||
template<bool _Cond>
|
||||
bool GeneralGetBitPosition(const XBitArray& ba, CKDWORD n, CKDWORD& got) {
|
||||
CKDWORD counter = 0;
|
||||
for (size_t i = 0; i < ba.size(); ++i) {
|
||||
if (ba[i] == _Cond) {
|
||||
if (counter == n) {
|
||||
got = static_cast<CKDWORD>(i);
|
||||
return true;
|
||||
} else {
|
||||
++counter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GetSetBitPosition(const XBitArray& ba, CKDWORD n, CKDWORD& got) {
|
||||
return GeneralGetBitPosition<true>(ba, n, got);
|
||||
}
|
||||
|
||||
bool GetUnsetBitPosition(const XBitArray& ba, CKDWORD n, CKDWORD& got) {
|
||||
return GeneralGetBitPosition<false>(ba, n, got);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace NSXString {
|
||||
|
||||
CKSTRING ToCKSTRING(const XString& strl) {
|
||||
if (strl.empty()) return nullptr;
|
||||
else return strl.c_str();
|
||||
}
|
||||
|
||||
void FromCKSTRING(XString& strl, CKSTRING s) {
|
||||
if (s == nullptr) strl.clear();
|
||||
else strl = s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "../CK2/CKTypes.hpp"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <cstring>
|
||||
#include <cinttypes>
|
||||
#include "../CK2/CKTypes.hpp"
|
||||
|
||||
/**
|
||||
* @brief The X container part of LibCmo.
|
||||
@ -21,7 +19,9 @@ namespace LibCmo::XContainer {
|
||||
|
||||
/**
|
||||
@brief Set of bit flags.
|
||||
@remark This class now use specialized std::vector<bool>.
|
||||
@remark
|
||||
+ This class now use specialized std::vector<bool>.
|
||||
+ Do not use CKBOOL, because we want make sure it enable specialized std::vector<bool>.
|
||||
*/
|
||||
using XBitArray = std::vector<bool>;
|
||||
|
||||
@ -70,5 +70,40 @@ namespace LibCmo::XContainer {
|
||||
template<class K, class T, class H = std::hash<K>, class Eq = std::equal_to<K>>
|
||||
using XHashTable = std::unordered_map<K, T, H, Eq>;
|
||||
|
||||
// ========== Patch Section ==========
|
||||
|
||||
namespace NSXBitArray {
|
||||
|
||||
/**
|
||||
* @brief Returns the position of the n-th set(1) bit
|
||||
* @return false if not found.
|
||||
*/
|
||||
bool GetSetBitPosition(const XBitArray& ba, CKDWORD n, CKDWORD& got);
|
||||
/**
|
||||
* @brief Returns the position of the n-th unset(0) bit
|
||||
* @return false if not found.
|
||||
*/
|
||||
bool GetUnsetBitPosition(const XBitArray& ba, CKDWORD n, CKDWORD& got);
|
||||
|
||||
}
|
||||
|
||||
namespace NSXString {
|
||||
|
||||
/**
|
||||
* @brief Return CKSTRING statement of XString.
|
||||
* @param strl The XString need to be output.
|
||||
* @return Return the CKSTRING format of XString. if XString is blank, return nullptr.
|
||||
*/
|
||||
CKSTRING ToCKSTRING(const XString& strl);
|
||||
|
||||
/**
|
||||
* @brief Copy CKSTRING to XString.
|
||||
* @param strl The string dest.
|
||||
* @param s The CKSTRING need to be copied. Pass nullptr will clear string dest.
|
||||
*/
|
||||
void FromCKSTRING(XString& strl, CKSTRING s);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user