Files
mir_server/server/LogicServer/misc/caches/CustomConfigCacher.h

149 lines
6.6 KiB
C
Raw Normal View History

2025-01-09 17:45:40 +08:00
#pragma once
using namespace FileHeaders;
class CCustomConfigCacher
{
public:
/****
*
*
*
* 326432
* 64
*
*
*
*+-----+--------+----------+-----------+--------------+
*||||1|N数据段... |
*+-----+--------+----------+-----------+--------------+
*******************************************************************/
typedef struct tagConfigDataCacheFileHeader
{
FILEIDENT Ident; //文件标志
FILEVERSION Version; //文件版本号
DWORD dwMemBlockCount;//内存块的数量
DWORD dwElementCount; //数据记录数量
DWORD dwSizeElement; //数据记录对象的大小
DWORD dwDataCRC32; //整个文件数据段的CRC32效验值
DWORD dwSourceCRC32; //生成缓存是的原始数据CRC32效验值
BYTE btPlatFormIdent;//用于保存文件生成时的处理器架构标志32位、64位
BYTE btReseve0[3]; //保留字节
BYTE btReseve[32]; //保留字节促使结构体大小为64字节
}CONF_DATA_CACHE_HDR, *PCONF_DATA_CACHE_HDR;
/***
*
****************************************/
typedef struct tagMemoryBlockRecord
{
char* lpMemoryBase; //内存起始地址
size_t dwMemorySize; //内存块字节大小
}MEM_BLOCK_REC, *PMEM_BLOCK_REC;
private:
//缓存文件读取环境结构
struct CacheReadEnvir
{
PCONF_DATA_CACHE_HDR pHdr; //文件头
void* pElements; //对象指针记录数组
PMEM_BLOCK_REC pMemBlocks; //内存块描述段
char* pDataSegment; //内存数据段
char* pNewMemory; //读取缓存的整合新内存段指针
};
public:
CCustomConfigCacher();
virtual ~CCustomConfigCacher();
public:
/*
* Comments:
* Param LPCTSTR sCacheFile:
* Param DWORD dwSourceCRC: CRC32效验值
* Param CObjectAllocator<char> & allocator:
* Param OUT void * * pElements:
* Param INT_PTR & nElementCount:
* @Return bool: CRC经对比后没有变化则读取缓存文件并将结果输
* pElementList以及nElementCount中allocator
* false
*/
bool LoadFromCache(LPCTSTR sCacheFile, DWORD dwSourceCRC,
CObjectAllocator<char> &allocator, OUT void** pElements, INT_PTR &nElementCount);
/*
* Comments:
* Param LPCTSTR sCacheFile:
* Param DWORD dwSourceCRC: CRC32效验值
* Param const CObjectAllocator<char> & allocator:
* Param const void * pElements:
* Param INT_PTR nElementCount:
* @Return bool: true否则返回false
*/
bool SaveToCache(LPCTSTR sCacheFile, DWORD dwSourceCRC,
const CObjectAllocator<char> &allocator, const void *pElements, INT_PTR nElementCount);
protected:
/**** ★★★★★★子类必须覆盖处理的函数集★★★★★★ ****/
/*
* Comments: dwSizeElement值
* Param const CONF_DATA_CACHE_HDR & hdr:
* @Return bool: truefalsefalse会导致放弃对缓存文件的读取
*/
virtual bool ValidateHeader(const CONF_DATA_CACHE_HDR& hdr) = 0;
/*
* Comments:
* Param LPVOID lpElement:
* @Return bool: truefalsefalse会导致终止对缓存文件的读取
* remarks:
*
* 便
*
* GetNewMemoryPtr函数传递旧的指针地址进行计算
*/
virtual bool AdjustElementPointers(LPVOID lpElement) = 0;
/*
* Comments: dwSizeElement
* Param CONF_DATA_CACHE_HDR & hdr:
* @Return void:
*/
virtual void FillHeaderData(CONF_DATA_CACHE_HDR& hdr) = 0;
protected:
/**** ★★★★★★以下为内部处理函数★★★★★★ ****/
/*
* Comments:
* Param CObjectAllocator<char> & allocator:
* Param OUT void * * pElements:
* Param INT_PTR & nElementCount:
* @Return bool:
*/
bool ReadCacheFile(CObjectAllocator<char> &allocator, OUT void** pElements, INT_PTR &nElementCount);
/*
* Comments: CRC有效性以及与新的源文件的CRC做对比
* Param DWORD dwSourceCRC:
* @Return bool: CRC一致truefalse
*/
bool ValidateCacheDataCRC(DWORD dwSourceCRC);
/*
* Comments:
* Param LPCVOID lpAddress:
* @Return void*:
*/
void* GetNewMemoryPtr(LPCVOID lpAddress);
/*
* Comments:
* @Return size_t:
*/
size_t CalcDataSize();
/*
* Comments:
* Param char * lpNewMemory:
* @Return void:
*/
void CopyBlockMemorys(char* lpNewMemory);
protected:
wylib::stream::CMemoryStream m_CacheStream; //缓存数据读写流
CacheReadEnvir* m_pCacheReadEnvir; //缓存文件读取环境,仅在读取缓存数据函数调用期间按有意义
};