#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. mac上卸载mysql

    在终端输入一下命令 sudo rm /usr/local/mysqlsudo rm -rf /usr/local/mysql*sudo rm -rf /Library/StartupItems/MyS ...

  2. 报错:/application/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory

    启动zabbix_server时报错: /application/zabbix/sbin/zabbix_server: error while loading shared libraries: li ...

  3. java版云笔记(九)之动态sql

    SQL 首先,所谓SQL的动态和静态,是指SQL语句在何时被编译和执行,二者都是用在SQL嵌入式编程中的,这里所说的嵌入式是指将SQL语句嵌入在高级语言中,而不是针对于单片机的那种嵌入式编程. 静态S ...

  4. NOIP填坑计划

    斗地主 华容道 开车旅行 疫情控制 飞扬的小鸟 Mayan游戏 天天爱跑步

  5. python基础(7)--深浅拷贝、函数

    1.深浅拷贝 在Python中将一个变量的值传递给另外一个变量通常有三种:赋值.浅拷贝.深拷贝 Python数据类型可氛围基本数据类型包括整型.字符串.布尔及None等,还有一种由基本数据类型作为最基 ...

  6. csu 1767(循环节)

    1767: 想打架吗?算我一个!所有人,都过来!(2) Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 99  Solved: 18[Submit][St ...

  7. C++的黑科技(深入探索C++对象模型)

    周二面了腾讯,之前只投了TST内推,貌似就是TST面试了 其中有一个问题,“如何产生一个不能被继承的类”,这道题我反反复复只想到,将父类的构造函数私有,让子类不能调用,最后归结出一个单例模式,但面试官 ...

  8. 洛谷 P1359 租用游艇 题解

    题目传送门 这道题还是上模板啦~~SPFA大法好(本人还是懒得打邻接表) 一道橙题: 上代码: #include<bits/stdc++.h> using namespace std; ] ...

  9. 完全禁用Wordpress的升级功能

    wordpress自己带有一个自动升级的功能,也就是说,如果wp检测到官方已经有新的升级可用的话他就会自己升级上去.这可能对于某些场合是个不错的功能,但是对于一些已经对系统大量魔改或者对插件稳定性不抱 ...

  10. CentOS7 logstash配置部署

    (1)logstash介绍 `Logstash是一个开源的数据收集引擎,可以水平伸缩,而且logstash是整个ELK当中拥有最多插件的一个组件,其可以接收来自不同源的数据并统一输入到指定的且可以是不 ...