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的更多相关文章
随机推荐
- JSP基础与提高(一).md
JSP基础 JSP的由来 1.1. 为什么有JSP规范 Servlet技术产生以后,在使用过程中存在一个很大的问题,即为了表现页面的效果而需要输出大量的HTML标签,这些标签在Servlet中表现为一 ...
- java1.8环境配置+win10系统
Java环境配置相关 Java jdk 1.8版本的环境配置和1.7版本 存在一些差异,当然不同的操作系统可能会对jdk配置有一定的变化.本文我主要说1.8版本的jdk在window10 系统上的配置 ...
- 如何在 JavaScript 中检查字符串是否包含子字符串?
如何在 JavaScript 中检查字符串是否包含子字符串? // var test4 = _.includes(string, substring); 该方法需要此文件 <script src ...
- 【WPF】生成二维码
第一步,下载Google的ZXing类库,以便引用: BitMatrix bitMatrix; private void Button_Click_1(object sender, RoutedEve ...
- GNU Wget 1.19.4 for Windows
资源地址:https://eternallybored.org/misc/wget/ 然后将工具目录加入环境变量
- HDU 3074.Multiply game-区间乘法-线段树(单点更新、区间查询),上推标记取模
Multiply game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- Python类总结-多态及鸭子类型
Python天生支持多态. 什么是多态: 一类事务的多种形态. 多态的一个例子 class Alipay(): def pay(self,money): print('用支付宝支付了%s元' % mo ...
- Lock接口简介
在Java多线程编程中,我们经常使用synchronized关键字来实现同步,控制多线程对变量的访问,来避免并发问题. 但是有的时候,synchronized关键字会显得过于沉重,不够灵活.synch ...
- DateFormat 线程安全
SimpleDateformat 线程不安全 SimpleDateFormat 继承自 DateFormat, SimpleDateFormat中的parse方法override父类DateForma ...
- 【伪暴力+智商剪枝】Codeforces Round #489 (Div. 2) D
失踪人口突然回归……orz.题解还是有必要写的,虽然估计只有自己(?自己也不一定看得懂)看得懂. 题目链接:http://codeforces.com/contest/992/problem/D 题目 ...