prepare some functions

This commit is contained in:
yyc12345 2023-03-08 10:56:43 +08:00
parent bf0fca756b
commit f3cb9b1a07
2 changed files with 108 additions and 8 deletions

View File

@ -121,7 +121,7 @@ namespace LibCmo::CK2 {
size_t CKStateChunk::GetCeilDwordSize(size_t char_size) { size_t CKStateChunk::GetCeilDwordSize(size_t char_size) {
return (char_size + 3) >> 3; return (char_size + 3) >> 2;
} }
bool CKStateChunk::ResizeBuffer(CKDWORD new_dwsize) { bool CKStateChunk::ResizeBuffer(CKDWORD new_dwsize) {
@ -430,6 +430,22 @@ namespace LibCmo::CK2 {
return true; return true;
} }
/* ========== Complex Data Read Functions ==========*/
bool CKStateChunk::ReadObjectID(CK_ID* id) {
return false;
}
bool CKStateChunk::ReadManagerInt(CKGUID* guid, CKINT* intval) {
return false;
}
CKStateChunk* CKStateChunk::ReadSubChunk(void) {
return nullptr;
}
/* ========== Buffer Functions ==========*/
bool CKStateChunk::ReadNoSizeBuffer(CKDWORD size_in_byte, void* allocatedBuf) { bool CKStateChunk::ReadNoSizeBuffer(CKDWORD size_in_byte, void* allocatedBuf) {
if (allocatedBuf == nullptr) return false; if (allocatedBuf == nullptr) return false;
return this->ReadByteData(allocatedBuf, size_in_byte); return this->ReadByteData(allocatedBuf, size_in_byte);
@ -465,6 +481,23 @@ namespace LibCmo::CK2 {
return true; return true;
} }
/* ========== Sequence Functions ==========*/
bool CKStateChunk::ReadObjectIDSequence(std::vector<CK_ID>* ls) {
return false;
}
bool CKStateChunk::ReadManagerIntSequence(CKGUID* guid, std::vector<CKINT>* ls) {
return false;
}
bool CKStateChunk::ReadSubChunkSequence(std::vector<CKStateChunk*>* ls) {
return false;
}
bool CKStateChunk::ReadObjectArray(std::vector<CK_ID>* ls) {
return false;
}
#pragma endregion #pragma endregion

View File

@ -135,18 +135,39 @@ namespace LibCmo::CK2 {
return ReadString(&strl); return ReadString(&strl);
} }
/* ========== Complex Data Read Functions ==========*/
bool ReadObjectID(CK_ID* id);
inline bool ReadObjectID(CK_ID& id) {
return ReadObjectID(&id);
}
bool ReadManagerInt(CKGUID* guid, CKINT* intval);
inline bool ReadManagerInt(CKGUID& guid, CKINT& intval) {
return ReadManagerInt(&guid, &intval);
}
/// <summary>
/// Read sub chunk
/// <para>Return nullptr if failed.</para>
/// <para>Returned CKStateChunk should be manually released!</para>
/// </summary>
/// <param name=""></param>
/// <returns></returns>
CKStateChunk* ReadSubChunk(void);
/* ========== Buffer Functions ==========*/ /* ========== Buffer Functions ==========*/
/* /*
Buffer related function implements: Buffer related function implements:
ReadBuffer(void**) Read Byte based size. ReadBuffer(void**) Read Byte based size. -> ReadBuffer
ReadAndFillBuffer(int, void*) User give Byte based size. ReadAndFillBuffer(int, void*) User give Byte based size. -> ReadNoSizeBuffer
ReadAndFillBuffer(void*) Read Byte based size. ReadAndFillBuffer(void*) Read Byte based size. -> ReadBuffer
ReadAndFillBuffer_LEndian(int, void*) User give Byte based size. ReadAndFillBuffer_LEndian(int, void*) User give Byte based size. -> ReadNoSizeBuffer
ReadAndFillBuffer_LEndian(void*) Read Byte based size. ReadAndFillBuffer_LEndian(void*) Read Byte based size. -> ReadBuffer
ReadAndFillBuffer_LEndian16(int, void*) User give Byte based size. ReadAndFillBuffer_LEndian16(int, void*) User give Byte based size. -> ReadNoSizeBuffer
ReadAndFillBuffer_LEndian16(void*) Read Byte based size. ReadAndFillBuffer_LEndian16(void*) Read Byte based size. -> ReadBuffer
*/ */
/// <summary> /// <summary>
@ -171,6 +192,52 @@ namespace LibCmo::CK2 {
/* ========== Sequence Functions ==========*/ /* ========== Sequence Functions ==========*/
/// <summary>
/// Read Object ID Sequence
/// <para>The combination using of StartReadSequence(), ReadObjectID(), and ReadObject() redirect to this.</para>
/// </summary>
/// <param name="ls"></param>
/// <returns></returns>
bool ReadObjectIDSequence(std::vector<CK_ID>* ls);
inline bool ReadObjectIDSequence(std::vector<CK_ID>& ls) {
return ReadObjectIDSequence(&ls);
}
/// <summary>
/// Read Manager Sequence
/// <para>The combination using of StartManagerReadSequence() and ReadManagerIntSequence() redirect to this.</para>
/// </summary>
/// <param name="guid"></param>
/// <param name="ls"></param>
/// <returns></returns>
bool ReadManagerIntSequence(CKGUID* guid, std::vector<CKINT>* ls);
inline bool ReadManagerIntSequence(CKGUID& guid, std::vector<CKINT>& ls) {
return ReadManagerIntSequence(&guid, &ls);
}
/// <summary>
/// Read Sub Chunk Sequence
/// <para>The combination using of StartReadSequence() and ReadSubChunk() redirect to this.</para>
/// <para>The item of returned CKStateChunk* list should be manually released!</para>
/// </summary>
/// <param name="ls"></param>
/// <returns></returns>
bool ReadSubChunkSequence(std::vector<CKStateChunk*>* ls);
inline bool ReadSubChunkSequence(std::vector<CKStateChunk*>& ls) {
return ReadSubChunkSequence(&ls);
}
/// <summary>
/// Read Object Array (actually still is CK_ID)
/// <para>ReadXObjectArray() and ReadObjectArray() redirect to this.</para>
/// </summary>
/// <param name="ls"></param>
/// <returns></returns>
bool ReadObjectArray(std::vector<CK_ID>* ls);
inline bool ReadObjectArray(std::vector<CK_ID>& ls) {
return ReadObjectArray(&ls);
}
//int ReadInt(); //int ReadInt();
//int StartReadSequence(); //int StartReadSequence();
//CK_ID ReadObjectID(); //CK_ID ReadObjectID();