libcmo21/LibCmo/CK2/CKGlobals.hpp

80 lines
2.8 KiB
C++
Raw Normal View History

2023-08-22 15:30:26 +08:00
#pragma once
2023-08-31 12:37:23 +08:00
#include "CKDefines.hpp"
2023-08-22 15:30:26 +08:00
namespace LibCmo::CK2 {
// ========== Compression utilities ==========
/**
* @brief Compress a buffer
* @param[in] Data A pointer to the buffer to coompress
* @param[in] size Size of the source buffer.
* @param[out] NewSize A reference that will be filled with the size of the compressed buffer. 0 if failed.
* @param[in] compressionlevel 0-9
* @return
* A pointer to the compressed buffer. nullptr if failed.
* The return pointer should be freed by `delete[]` manually.
* @remark
* The size of allocated return value may greater than the passed value of NewSize.
* NewSize only indicate the size of the part storing useful data in return value.
* @see CKUnPackData, CKComputeDataCRC
*/
2023-08-28 21:21:40 +08:00
void* CKPackData(const void* Data, CKDWORD size, CKDWORD& NewSize, CKINT compressionlevel);
2023-08-22 15:30:26 +08:00
/**
* @brief Decompress a buffer
* @param[in] DestSize Expected size of the decompressed buffer.
* @param[in] SrcBuffer Compressed buffer.
* @param[in] SrcSize Size of the compressed buffer.
* @return
* A pointer to the decompressed buffer or nullptr if there was a error.
* The return pointer should be freed by `delete[]` manually.
* @see CKPackData, CKComputeDataCRC
*/
2023-08-28 21:21:40 +08:00
void* CKUnPackData(CKDWORD DestSize, const void* SrcBuffer, CKDWORD SrcSize);
2023-08-22 15:30:26 +08:00
/**
* @brief Computes a CRC for a buffer.
* @param[in] data A pointer to the buffer to create a CRC for.
* @param[in] size Size of the source buffer.
* @param[in] PreviousCRC
* The first time a CRC is computed this value should be 0,
* but it can be use to compute a single CRC for a several buffers
* by using the currently computed CRC for previous buffers in this value.
* @return CRC of the buffer.
* @see CKPackData, CKUnPackData
*/
CKDWORD CKComputeDataCRC(const void* data, CKDWORD size, CKDWORD PreviousCRC = 0);
2023-09-04 22:58:53 +08:00
// ========== String Utilities ==========
bool CKStrEqual(CKSTRING str1, CKSTRING str2);
// ========== Numberic Utilities ==========
/*
The convenient sizeof which return CKDWORD, not size_t.
*/
#define CKSizeof(_Ty) (static_cast<LibCmo::CK2::CKDWORD>(sizeof(_Ty)))
2023-08-23 16:04:58 +08:00
// ========== CKClass Registration ==========
2023-08-28 17:04:28 +08:00
2023-09-01 12:19:06 +08:00
CK_CLASSID CKClassGetNewIdentifier();
2023-08-23 16:04:58 +08:00
void CKClassRegister(CK_CLASSID cid, CK_CLASSID parentCid,
CKClassCreationFct createFct, CKClassReleaseFct relFct, CKClassNameFct nameFct);
// ========== Class Hierarchy Management ==========
2023-08-28 17:04:28 +08:00
2023-09-01 12:19:06 +08:00
CKDWORD CKGetClassCount();
2023-08-23 16:04:58 +08:00
const CKClassDesc* CKGetClassDesc(CK_CLASSID cid);
CKSTRING CKClassIDToString(CK_CLASSID cid);
bool CKIsChildClassOf(CK_CLASSID child, CK_CLASSID parent);
2023-08-23 16:04:58 +08:00
CK_CLASSID CKGetParentClassID(CK_CLASSID child);
CK_CLASSID CKGetCommonParent(CK_CLASSID cid1, CK_CLASSID cid2);
// ========== Initializations functions ==========
CKERROR CKStartUp();
CKERROR CKShutdown();
2023-08-22 15:30:26 +08:00
}