#ifndef __E3GLOGLOADBYFILE_H__
#define __E3GLOGLOADBYFILE_H__ #include "PubCommon\MemoryManager.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 "PubCommon\FileFormatDefine.h" CMoReader::CMoReader(Win32Tools::CMemoryManager* pMemMgr)
: m_nCount()
, 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()
{
// 依次追加的行
CMemLine* pNew = (CMemLine*)m_pMemMgr->GetMemory(sizeof(CMemLine));
pNew = new (pNew) CMemLine;
if(false == ReadLine(pNew))
break;
if(*(pNew->m_pLine) == '=')
{
if( <= ++m_nCount) // 完整对象判断
{
break;
}
continue;
}
if(*(pNew->m_pLine) != '\0' && (NUMBER_ZERO != m_nCount))
{
pMemLine->m_pNextLine = pNew;
pMemLine = pNew;
}
}
if ( != m_nCount) // 结尾非法对象处理
{
pOld->m_pNextLine = NULL;
}
pMemLine = pOld;
pMemLine = pMemLine->m_pNextLine;
m_nCount = ;
} bool CMoReader::IsEof()
{
return (*m_pReadPos == FILE_END_CHAR);
} size_t CMoReader::GetBufSize(PCHAR pBuf)
{
size_t iRelt();
while(*pBuf++ != '\0')
{
++iRelt;
}
return iRelt;
} bool CMoReader::MoveToLineEnd()
{
// 移动到行尾 if(*m_pReadPos == '\r' || *m_pReadPos == '\0' || *m_pReadPos == '\n' || *m_pReadPos == FILE_END_CHAR)
return false; do
{
++m_pReadPos;
}
while(*m_pReadPos != '\r' && *m_pReadPos != '\0' && *m_pReadPos != '\n' && *m_pReadPos != FILE_END_CHAR);
return true;
} bool CMoReader::MoveToNextLine()
{
// 移动到下一行 MoveToLineEnd(); // 首先移动至行尾
if(*m_pReadPos == FILE_END_CHAR)
return false; while(*m_pReadPos == '\r' || *m_pReadPos == '\n' || *m_pReadPos == '\0')
{
if(*m_pReadPos == FILE_END_CHAR)
return false;
++m_pReadPos;
}
return true;
} bool CMoReader::ReadLine(CMemLine*& pMemLine)
{
// 读取一行数据 char* pBegin = m_pReadPos;
if(MoveToLineEnd() == false)
return false;
char* pEnd = m_pReadPos;
size_t iSize = pEnd - pBegin;
pMemLine->m_pLine = pBegin;
pMemLine->m_iLength = iSize;
*pEnd = '\0';
return MoveToNextLine();
}

CMoReader的更多相关文章

随机推荐

  1. Delphi 通过字符串实例化类

    通过字符串创建窗体类对象 1.需要在程序初始化的时候将类注册,注册到对象 RegGroups:(TRegGroups)中,以便查找. 注册类使用的函数:RegisterClass ,窗体初始化操作放在 ...

  2. HDU 1217 Arbitrage(Bellman-Ford判断负环+Floyd)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 题目大意:问你是否可以通过转换货币从中获利 如下面这组样例: USDollar 0.5 Brit ...

  3. Mybatis基础及入门案例

    这几天正在对SSM框架的知识进行一个回顾加深,有很多东西学的囫囵吞枣,所以利用一些时间进一步的学习.首先大概了解一下mybatis的使用,再通过一个案例来学习它. 什么是MyBatis Mybatis ...

  4. day3修改配置文件

    有如下配置文件,在指定文件位置添加一条新的记录: global log 127.0.0.1 local2 daemon maxconn log 127.0.0.1 local2 info defaul ...

  5. python3环境下面bytes类型转换成字典类型实例

    场景:通过http://tool.chinaz.com/tools/httptest.aspx在线HTTP接口测试工具获取接口的返回信息 { "status": 0, " ...

  6. ubuntu sublime text 3 build 3083 license

    经验证:sublime text 3 3083可用 ----- BEGIN LICENSE -----Andrew WeberSingle User LicenseEA7E-855605813A03D ...

  7. C#后台获取ajax传来的xml格式数据值

    前台: var xml = "<root>"; if(Name!=null) { xml += "<name>"+Name +" ...

  8. Java 继承内部类

    大家有没有想过内部类究竟能不能被继承呢? public class Main { public static void main(String[] args){ Outer outer = new O ...

  9. git团队开发常用命令

    Git >>>>>>>>>>>> git clone <项目地址,http(s)> 把云端的项目克隆到本地 git ...

  10. Android之 内容提供器(1)——使用内容提供器访问其它程序共享的数据

    (下面内容是阅读郭霖大神的<第一行代码>总结的) 1 概述 内容提供器是Android实现跨程序共享数据的标准方式. 内容提供器的的使用方法有两种, 一是使用已有的内容提供器对其他程序的数 ...