doc: finish XTypes documentation

This commit is contained in:
yyc12345 2024-08-19 10:43:30 +08:00
parent 1483466211
commit 35d508b1b9
2 changed files with 123 additions and 82 deletions

View File

@ -41,7 +41,7 @@ namespace LibCmo::XContainer {
} }
template<bool _Cond> template<bool _Cond>
bool GeneralGetBitPosition(const XBitArray& ba, CKDWORD n, CKDWORD& got) { static bool GeneralGetBitPosition(const XBitArray& ba, CKDWORD n, CKDWORD& got) {
CKDWORD counter = 0; CKDWORD counter = 0;
for (size_t i = 0; i < ba.size(); ++i) { for (size_t i = 0; i < ba.size(); ++i) {
if (ba[i] == _Cond) { if (ba[i] == _Cond) {
@ -82,11 +82,11 @@ namespace LibCmo::XContainer {
} }
template<class _Ty> template<class _Ty>
constexpr bool GeneralXArrayCheck_TypeCheck() { static constexpr bool GeneralXArrayCheck_TypeCheck() {
return std::is_same_v<_Ty, CK2::CK_ID> || std::is_same_v<_Ty, CK2::ObjImpls::CKObject*>; return std::is_same_v<_Ty, CK2::CK_ID> || std::is_same_v<_Ty, CK2::ObjImpls::CKObject*>;
} }
template<class _Ty, bool _IsPre> template<class _Ty, bool _IsPre>
bool GeneralXArrayCheck_ItemCheck(const _Ty& item, CK2::CKContext* ctx) { static bool GeneralXArrayCheck_ItemCheck(const _Ty& item, CK2::CKContext* ctx) {
static_assert(GeneralXArrayCheck_TypeCheck<_Ty>()); static_assert(GeneralXArrayCheck_TypeCheck<_Ty>());
if (ctx == nullptr) return false; if (ctx == nullptr) return false;

View File

@ -13,206 +13,247 @@
namespace LibCmo::XContainer { namespace LibCmo::XContainer {
/** /**
@brief Class representation of a string (an array of character ended by NULL). * @brief The representation of an UTF8 string (an array of UTF8 character ended by a '\0').
@remark This class now use std::string. * @remarks
* \li This class now is implemented by \c std::u8string.
*/ */
using XString = std::u8string; using XString = std::u8string;
/** /**
@brief Set of bit flags. * @brief The representation of a set of bit flags (memory optimized to reduce occupied size).
@remark * @remarks
+ This class now use specialized std::vector<bool>. * \li This class is implemented by specialized \c std::vector<bool>.
* \li This class define a set of bit flags that may be treated as a virtual array but are stored in an efficient manner.
* \li The class has methods to set, clear and return the i-th bit, resize the array, etc.
*/ */
using XBitArray = std::vector<bool>; using XBitArray = std::vector<bool>;
/** /**
@brief Class representation of an array. * @brief The representation of an array.
@tparam T Element Type. * @tparam T Element type.
@remark * @remarks
+ This class now use std::vector<T>. * \li This class now use \c std::vector<T>.
+ XSArray, XClassArray now redirect to this. * \li XSArray now redirect to this. Because XSArray behaves exactly like the XArray,
* but it only occupies less memory. This feature also can be done by executing \c std::vector<T>::shrink_to_fit().
* \li XClassArray now redirect to this. Because it is designed to hold structure or class
* which have something specific to do on the construction, deletion or recopy.
* However this feature can be resolved by writing proper ctor, copy ctor, move ctor and dtor.
*/ */
template<typename T> template<typename T>
using XArray = std::vector<T>; using XArray = std::vector<T>;
/** /**
* @brief Double-linked list. * @brief The representation of an double-linked list.
* @tparam T Element Type. * @tparam T Element type.
*/ */
template<typename T> template<typename T>
using XList = std::list<T>; using XList = std::list<T>;
/** /**
@brief Container class for CKObject Id's. * @brief The representation of an CKObject ID array.
@remark * @remarks
+ This class use the template container XArray to contain object CK_ID's. * \li This class is implemented as \c XArray<CK2::CK_ID>
+ Supports for Check, Load, Save, Add, Remove, Find functions in the Object CK_ID array. * \li Supports for Check, Load, Save, Add, Remove, Find functions in the Object CK_ID array.
+ XSObjectArray now redirect to this. * \li XSObjectArray now redirect to this. See the relation between XArray and XSArray for more reason.
@todo May independ this class to implement the functions introduced in remarks. * \li CKObjectArray now redirect to this according to its requirements (use pointer or use ID).
* @see XObjectPointerArray
* @todo Add implementations of functions introduced in remarks to the patch namespace.
*/ */
using XObjectArray = XArray<CK2::CK_ID>; using XObjectArray = XArray<CK2::CK_ID>;
/** /**
@brief Container class for CKObject pointers. * @brief The representation of an CKObject pointer array.
@remark * @remarks
+ Exactly same as XObjectArray class, but uses XArray (Pre-allocated items) * \li This class is implemented as \c XArray<CK2::ObjImpls::CKObject*>
for storing pointers, and not IDs (more efficient to retrieve the objects). * \li Exactly same as XObjectArray class, but stores pointers, not IDs (more efficient to retrieve the objects).
+ Supports for Check, Load, Save, Add, Remove, Find functions in the CKObject Pointer array. * \li Supports for Check, Load, Save, Add, Remove, Find functions in the CKObject pointer array.
+ XSObjectPointerArray now redirect to this. * \li XSObjectPointerArray now redirect to this. See the relation between XArray and XSArray for more reason.
@todo May independ this class to implement the functions introduced in remarks. * \li CKObjectArray now redirect to this according to its requirements (use pointer or use ID).
@see XObjectArray, CKObjectArray * @see XObjectArray
* @todo Add implementations of functions introduced in remarks to the patch namespace.
*/ */
using XObjectPointerArray = XArray<CK2::ObjImpls::CKObject*>; using XObjectPointerArray = XArray<CK2::ObjImpls::CKObject*>;
/** /**
@brief Class representation of an Hash Table container. * @brief The representation of an hash table container.
@tparam K The type of the key * @tparam K The type of the key
@tparam T The type of element to insert * @tparam T The type of element to insert
@tparam H The hash function to hash the key * @tparam H The hash function to hash the key
@tparam Eq The equal function to the key * @tparam Eq The equal function to the key
@remark * @remarks
+ This class now use std::unordered_map<T>. * \li This class now is implemented by \c std::unordered_map<K,T,H,Eq>.
+ XNHashTable, XSHashTable now redirect to this. * \li XNHashTable now redirect to this. Because it seems like the old version of XHashTable.
* \li XSHashTable now redirect to this. See the relation between XArray and XSArray for more reason.
*/ */
template<class K, class T, class H = std::hash<K>, class Eq = std::equal_to<K>> 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>; using XHashTable = std::unordered_map<K, T, H, Eq>;
// ========== Patch Section ========== // ========== Patch Section ==========
/**
* @brief The patch namespace for XBitArray
* @details This namespace provides XBitArray functions which presented in original Virtools SDK,
* because XBitArray use standard library container as its implementation.
*/
namespace NSXBitArray { namespace NSXBitArray {
/** /**
* @brief Resize XBitArray to the new size. Initial value is false. * @brief Resize XBitArray to the new size. Initial value is false.
* @param ba The XBitArray * @param[in] ba The XBitArray to be resized.
* @param newsize New Size * @param[in] newsize New size (the count of bit flags, \b not the space in byte).
*/ */
void Resize(XBitArray& ba, CKDWORD newsize); void Resize(XBitArray& ba, CKDWORD newsize);
/** /**
* @brief Merge other XBitArray to this XBitArray with OR condition. * @brief Merge 2 XBitArray like performing <TT>thisba | thatba</TT> for each flags.
* @details
* This XBitArray will be resized at least equal with merged XBitArray if its size is lower than merged XBitArray * This XBitArray will be resized at least equal with merged XBitArray if its size is lower than merged XBitArray
* @param thisba This XBitArray * @param[in] thisba The merging XBitArray.
* @param thatba Other XBitArray will be merged. * If this XBitArray will be resized at least equal with merged XBitArray before merging.
* @param[in] thatba Other XBitArray will be merged.
*/ */
void Or(XBitArray& thisba, const XBitArray& thatba); void Or(XBitArray& thisba, const XBitArray& thatba);
/** /**
* @brief Check whether bit flag is set. * @brief Check whether bit flag is set.
* @param ba The XBitArray * @param[in] ba The XBitArray for checking
* @param n The check position. * @param[in] n The position for checking.
* @return True if set. False if not set or out of range. * @return True if set. False if not set or out of range.
*/ */
bool IsSet(const XBitArray& ba, CKDWORD n); bool IsSet(const XBitArray& ba, CKDWORD n);
/** /**
* @brief Set specified position to true in XBitArray. Auto resize if no space to set. * @brief Set specified position to true in XBitArray. Auto resize if no space to set.
* @param ba The XBitArray * @param[in] ba The XBitArray for setting.
* @param n The set position. * @param[in] n The position for setting.
*/ */
void Set(XBitArray& ba, CKDWORD n); void Set(XBitArray& ba, CKDWORD n);
/** /**
* @brief Unset specified position to true in XBitArray. If out of range, simply return. * @brief Unset specified position to true in XBitArray. Do nothing if out of range.
* @param ba The XBitArray * @param[in] ba The XBitArray for unsetting.
* @param n The unset position. * @param[in] n The position for unsetting.
*/ */
void Unset(XBitArray& ba, CKDWORD n); void Unset(XBitArray& ba, CKDWORD n);
/** /**
* @brief Returns the position of the n-th set(1) bit * @brief Find the n-th bit which is set(1) bit from the lowest position.
* @return false if not found. * @param[in] ba The The XBitArray for finding.
* @param[in] n N-th
* @param[out] got The position we found.
* @return True if we found, otherwise false.
*/ */
bool GetSetBitPosition(const XBitArray& ba, CKDWORD n, CKDWORD& got); bool GetSetBitPosition(const XBitArray& ba, CKDWORD n, CKDWORD& got);
/** /**
* @brief Returns the position of the n-th unset(0) bit * @brief Find the n-th bit which is unset(0) bit from the lowest position.
* @return false if not found. * @param[in] ba The The XBitArray for finding.
* @param[in] n N-th
* @param[out] got The position we found.
* @return True if we found, otherwise false.
*/ */
bool GetUnsetBitPosition(const XBitArray& ba, CKDWORD n, CKDWORD& got); bool GetUnsetBitPosition(const XBitArray& ba, CKDWORD n, CKDWORD& got);
} }
/**
* @brief The patch namespace for XString
* @details This namespace provides XString functions which presented in original Virtools SDK,
* because XString use standard library container as its implementation.
*/
namespace NSXString { namespace NSXString {
/** /**
* @brief Return CKSTRING statement of XString. * @brief Return CKSTRING representation of XString.
* @param strl The XString need to be output. * @param[in] strl The XString need to be output.
* @return Return the CKSTRING format of XString. if XString is blank, return nullptr. * @return Return the CKSTRING representation of XString.
* If XString is blank, return nullptr instead.
*/ */
CKSTRING ToCKSTRING(const XString& strl); CKSTRING ToCKSTRING(const XString& strl);
/** /**
* @brief Copy CKSTRING to XString. * @brief Copy CKSTRING representation to XString.
* @param strl The string dest. * @param[in] strl The string dest.
* @param s The CKSTRING need to be copied. Pass nullptr will clear string dest. * @param[in] s The CKSTRING need to be copied. nullptr will clear string dest.
*/ */
void FromCKSTRING(XString& strl, CKSTRING s); void FromCKSTRING(XString& strl, CKSTRING s);
} }
/**
* @brief The patch namespace for XObjectArray
* @details This namespace provides XObjectArray functions which presented in original Virtools SDK,
* because XObjectArray use standard library container as its implementation.
*/
namespace NSXObjectArray { namespace NSXObjectArray {
/** /**
* @brief Check Object ID validation and remove invalid IDs before deletion. * @brief Check Object ID validation and remove invalid IDs before deletion.
* @param objarray * @param[in] objarray The array to be checked.
* @param ctx * @param[in] ctx Associated CKContext.
*/ */
void PreDeletedCheck(XObjectArray& objarray, CK2::CKContext* ctx); void PreDeletedCheck(XObjectArray& objarray, CK2::CKContext* ctx);
/** /**
* @brief Check Object ID validation and remove invalid IDs after deletion. * @brief Check Object ID validation and remove invalid IDs after deletion.
* @param objarray * @param[in] objarray The array to be checked.
* @param ctx * @param[in] ctx Associated CKContext.
* @warning The performance of this function is extremely bad. Use this carefully.
*/ */
void PostDeletedCheck(XObjectArray& objarray, CK2::CKContext* ctx); void PostDeletedCheck(XObjectArray& objarray, CK2::CKContext* ctx);
/** /**
* @brief Check Object pointer validation and remove invalid pointers before deletion. * @brief Check Object pointer validation and remove invalid pointers before deletion.
* @param objarray * @param[in] objarray The array to be checked.
* @param ctx * @param[in] ctx Associated CKContext.
*/ */
void PreDeletedCheck(XList<CK2::CK_ID>& objarray, CK2::CKContext* ctx); void PreDeletedCheck(XList<CK2::CK_ID>& objarray, CK2::CKContext* ctx);
/** /**
* @brief Check Object pointer validation and remove invalid pointers after deletion. * @brief Check Object pointer validation and remove invalid pointers after deletion.
* @param objarray * @param[in] objarray The array to be checked.
* @param ctx * @param[in] ctx Associated CKContext.
* @remark The performance of this function is extremely low. Use it carefully. * @warning The performance of this function is extremely bad. Use this carefully.
*/ */
void PostDeletedCheck(XList<CK2::CK_ID>& objarray, CK2::CKContext* ctx); void PostDeletedCheck(XList<CK2::CK_ID>& objarray, CK2::CKContext* ctx);
} }
/**
* @brief The patch namespace for XObjectPointer
* @details This namespace provides XObjectPointer functions which presented in original Virtools SDK,
* because XObjectPointer use standard library container as its implementation.
*/
namespace NSXObjectPointerArray { namespace NSXObjectPointerArray {
/** /**
* @brief Inserts the object at the end of the array, if it is not yet present. * @brief Inserts the object at the end of the array, if it is not yet present.
* @param objarray * @param[in] objarray The array for adding.
* @param obj * @param[in] obj The CKObject to be added.
* @return True if the object was already present, false otherwise * @return True if the object was already present, false otherwise
*/ */
bool AddIfNotHere(XObjectPointerArray& objarray, CK2::ObjImpls::CKObject* obj); bool AddIfNotHere(XObjectPointerArray& objarray, CK2::ObjImpls::CKObject* obj);
/** /**
* @brief Check Object pointer validation and remove invalid pointers before deletion. * @brief Check Object pointer validation and remove invalid pointers before deletion.
* @param objarray * @param objarray The array to be checked.
* @param ctx * @param ctx Associated CKContext.
*/ */
void PreDeletedCheck(XObjectPointerArray& objarray, CK2::CKContext* ctx); void PreDeletedCheck(XObjectPointerArray& objarray, CK2::CKContext* ctx);
/** /**
* @brief Check Object pointer validation and remove invalid pointers after deletion. * @brief Check Object pointer validation and remove invalid pointers after deletion.
* @param objarray * @param objarray The array to be checked.
* @param ctx * @param ctx Associated CKContext.
* @remark The performance of this function is extremely low. Use it carefully. * @warning The performance of this function is extremely bad. Use this carefully.
*/ */
void PostDeletedCheck(XObjectPointerArray& objarray, CK2::CKContext* ctx); void PostDeletedCheck(XObjectPointerArray& objarray, CK2::CKContext* ctx);
/** /**
* @brief Check Object pointer validation and remove invalid pointers before deletion. * @brief Check Object pointer validation and remove invalid pointers before deletion.
* @param objarray * @param objarray The array to be checked.
* @param ctx * @param ctx Associated CKContext.
*/ */
void PreDeletedCheck(XList<CK2::ObjImpls::CKObject*>& objarray, CK2::CKContext* ctx); void PreDeletedCheck(XList<CK2::ObjImpls::CKObject*>& objarray, CK2::CKContext* ctx);
/** /**
* @brief Check Object pointer validation and remove invalid pointers after deletion. * @brief Check Object pointer validation and remove invalid pointers after deletion.
* @param objarray * @param objarray The array to be checked.
* @param ctx * @param ctx Associated CKContext.
* @remark The performance of this function is extremely low. Use it carefully. * @warning The performance of this function is extremely bad. Use this carefully.
*/ */
void PostDeletedCheck(XList<CK2::ObjImpls::CKObject*>& objarray, CK2::CKContext* ctx); void PostDeletedCheck(XList<CK2::ObjImpls::CKObject*>& objarray, CK2::CKContext* ctx);