CMoReader
#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的更多相关文章
随机推荐
- 在 ASP.NET Core 具体使用文档
			
https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/hosting?tabs=aspnetcore2x
 - mysql root 密码恢复
			
1.停止mysql服务 service mysql stop 2.启动mysql时不启动授权表,跳过权限验证使用空密码登陆 mysqld_safe --skip-grant-tables & ...
 - UFLDL 教程学习笔记(六)主成分分析
			
教程:http://ufldl.stanford.edu/tutorial/supervised/MultiLayerNeuralNetworks/ 以及这篇博文,写的很清楚:http://blog. ...
 - python 爬图
			
利用bs库进行爬取,在下载html时,使用代理user_agent来下载,并且下载次数是2次,当第一次下载失败后,并且http状态码是500-600之间,然后会重新下载一次 soup = Beauti ...
 - 记一次前端问题解决历程(Cannot read Property 'call' of undefined)
			
场景 echosong 回长沙两个多月了, 新公司的创业项目 App , 小程序, 公众号. 目前差app 没有 做完. 公众号在前端小美女同事 的主导下采用前端比较火的Vue 技术框架. 一直一来主 ...
 - PHP获取机器mac代码
			
废话不多话,直接上代码 <?php class GetMac { public $result = array(); public $macAddrs = array(); //所有mac地址 ...
 - day4 迭代器与生成器解析
			
一.迭代器 迭代器是访问集合元素的一种方式.其实迭代器就是一种列表,只是访问集合元素的时候比较特殊,具有一些特定功能,记忆功能,能够记住用户上一次的状态.迭代器是访问集合元素的一种方式.并且,迭代器只 ...
 - 【LOJ】#2016. 「SCOI2016」美味
			
题解 做了一下SCOI2015,于是决定搬运SCOI2016= v = 如果没有加法,我们可以向左向右节点查找 每个总权值是2^18 - 1,然后左右分,那么每次是一个完整的节点 如果有了加法,那么我 ...
 - Adsafe 导致win10 中窗口错位
			
域账号使用,出现上述情况,干掉后一切恢复正常... 还好家里的本地管理员账号使用一切正常,不然又被广告占领了
 - LoadRunner监控Linux的三种方法
			
方法一.LR + SiteScope/nmon 方法二.使用rstatd包 1.下载rpc.rstatd-4.0.1.tar.gz 2.解压缩 tar -zxvf rpc.rstatd-4.0.1.t ...