#ifndef __E3GLOGLOADBYFILE_H__ #define __E3GLOGLOADBYFILE_H__ #include "PubCommonMemoryManager.h" #include "PubCommon.h" //------------------------ // 读取内存中的 LOG 文件 //------------------------ class CMoReader { public: CMoReader(Win32Tools::CMemoryManager* pMemMgr); virtual ~CMoReader(void); public: bool LoadFile(char* pFileMemory); void GetMemLine(CMemLine*& pMemLine); bool IsEof(); private: size_t GetBufSize(PCHAR pBuf); bool ReadLine(CMemLine*& pMemLine); // 读取一行数据 bool MoveToLineEnd(); // 移动到行尾 bool MoveToNextLine(); // 移动到下一行 private: char* m_pMemory; // 文件流的位置 char* m_pReadPos; // 当前读取的位置 int m_nCount; // 总计读取的行数 private: Win32Tools::CMemoryManager* m_pMemMgr; }; #endif
#include "stdafx.h" #include "MoReader.h" #include "PubCommonFileFormatDefine.h" CMoReader::CMoReader(Win32Tools::CMemoryManager* pMemMgr) : m_nCount(0) , m_pMemMgr(pMemMgr) , m_pMemory(NULL) , m_pReadPos(NULL) { } CMoReader::~CMoReader(void) { } bool CMoReader::LoadFile(char* pFileMemory) { // 加载信息 if(pFileMemory == NULL) return false; m_pMemory = pFileMemory; m_pReadPos = pFileMemory; return true; } void CMoReader::GetMemLine(CMemLine*& pMemLine) { // 首行数据 pMemLine = (CMemLine*)m_pMemMgr->GetMemory(sizeof(CMemLine)); pMemLine = new (pMemLine) CMemLine; CMemLine* pOld = pMemLine; while(1) { // 依次追加的行 CMemLine* pNew = (CMemLine*)m_pMemMgr->GetMemory(sizeof(CMemLine)); pNew = new (pNew) CMemLine; if(false == ReadLine(pNew)) break; if(*(pNew->m_pLine) == '=') { if(3 <= ++m_nCount) // 完整对象判断 { break; } continue; } if(*(pNew->m_pLine) != '