#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. 记一次spring boot中MongoDB Prematurely reached end of stream的异常解决

    在spring boot项目中使用了mongodb,当一段时间没有操作mongodb,下次操作mongodb时就会出现异常.异常如下: org.springframework.data.mongodb ...

  2. windows下phpstrom中xdebug的使用

    https://laravel-china.org/articles/16425/windows-phpstorm-xdebug-breakpoint-debugging

  3. ajax跨域的解决办法

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="content-type" content ...

  4. struct中长度为0的数组用途与原理

    前言 在标准C和C++中,长度为0的数组是被禁止使用的.不过在GNUC中,存在一个非常奇怪的用法,那就是长度为0的数组,比如Array[0]; 很多人可能觉得不可思议,长度为0的数组是没有什么意义的, ...

  5. 交通运输线(LCA)

    题目大意: 战后有很多城市被严重破坏,我们需要重建城市.然而,有些建设材料只能在某些地方产生.因此,我们必须通过城市交通,来运送这些材料的城市.由于大部分道路已经在战争期间完全遭到破坏,可能有两个城市 ...

  6. 深度学习方法(七):最新SqueezeNet 模型详解,CNN模型参数降低50倍,压缩461倍!

    欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld. 技术交流QQ群:433250724,欢迎对算法.技术感兴趣的同学加入. 继续前面关于深度学习CNN经典模型的 ...

  7. Linux文件系统的详解

    这里以 EXT2 文件系统为例 在Linux下,一个磁盘的最前面是MBR,大小为512Byte 在每一个分区下,第一部分是boot sector,接下来是super block,再接下来是inode, ...

  8. 微信小程序之wepy自动化架构搭建(fly+wepy-plugin-replace)

    前言 本文章秉着自动化工程项目的思想搭建的,基础架子完全按照wepy官网搭建,在基础上增加配置达到自动化项目.新增动flxio拦截器自动处理接口,新增根据环境变量来改变运行时的参数. Fly.js 小 ...

  9. LoadRunner截取字符串操作

    LoadRunner截取字符串操作 在使用LoadRunner winsockets协议写脚本,遇到下面问题: 在接收到的查询数据库的结果中我要取红色部份用于下面的select recv buf60 ...

  10. bzoj 1110 贪心 + 进制转换

    思路:感觉脑洞好大啊... 因为每两个砝码其中一个都是另一个的倍数,我们可以知道砝码的种数很少,我们将所有容器的 容量都转换成用这些砝码的重量的进制表示,然后将所有砝码排序,然后贪心地取,取到不能再取 ...