• CMoReader


    #ifndef __E3GLOGLOADBYFILE_H__ 
    #define __E3GLOGLOADBYFILE_H__ 
      
    #include "PubCommonMemoryManager.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 "PubCommonFileFormatDefine.h" 
      
    CMoReader::CMoReader(Win32Tools::CMemoryManager* pMemMgr) 
        : m_nCount(0) 
        , 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(1) 
        { 
            // 依次追加的行 
            CMemLine* pNew = (CMemLine*)m_pMemMgr->GetMemory(sizeof(CMemLine)); 
            pNew = new (pNew) CMemLine; 
            if(false == ReadLine(pNew)) 
                break; 
            if(*(pNew->m_pLine) == '=') 
            { 
                if(3 <= ++m_nCount)  // 完整对象判断 
                { 
                    break; 
                } 
                continue; 
            } 
            if(*(pNew->m_pLine) != '' && (NUMBER_ZERO != m_nCount)) 
            { 
                pMemLine->m_pNextLine = pNew; 
                pMemLine = pNew; 
            } 
        } 
        if (3 != m_nCount)                  // 结尾非法对象处理 
        { 
            pOld->m_pNextLine = NULL; 
        } 
        pMemLine = pOld; 
        pMemLine = pMemLine->m_pNextLine; 
        m_nCount = 1; 
    } 
      
    bool CMoReader::IsEof() 
    { 
        return (*m_pReadPos == FILE_END_CHAR); 
    } 
      
    size_t CMoReader::GetBufSize(PCHAR pBuf) 
    { 
        size_t iRelt(0); 
        while(*pBuf++ != '') 
        { 
            ++iRelt; 
        } 
        return iRelt; 
    } 
      
    bool CMoReader::MoveToLineEnd() 
    { 
        // 移动到行尾 
      
        if(*m_pReadPos == '
    ' || *m_pReadPos == '' || *m_pReadPos == '
    ' || *m_pReadPos == FILE_END_CHAR) 
            return false; 
      
        do
        { 
            ++m_pReadPos; 
        } 
        while(*m_pReadPos != '
    ' && *m_pReadPos != '' && *m_pReadPos != '
    ' && *m_pReadPos != FILE_END_CHAR); 
        return true; 
    } 
      
    bool CMoReader::MoveToNextLine() 
    { 
        // 移动到下一行 
      
        MoveToLineEnd(); // 首先移动至行尾 
        if(*m_pReadPos == FILE_END_CHAR) 
            return false; 
      
        while(*m_pReadPos == '
    ' || *m_pReadPos == '
    ' || *m_pReadPos == '') 
        { 
            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 = ''; 
        return MoveToNextLine(); 
    } 
  • 相关阅读:
    通过ajax前端后台交互/登录页和注册页前端后台交互详解/前端后台交互基础应用/几个后台函数的基础应用/php文件函数基础应用/php字符传函数基础应用/php数组函数基础应用
    >>>---PHP中的OOP-->面对过程与面对对象基础概念与内容--(封装、继承、多态)
    基于HBuilder开发手机APP-主页/跳转页面/切换选项卡
    PHP基础学习
    JavaScript学习-js中的数组/Boolean类/字符串String类
    关于gulp中顺序执行任务
    AugularJS从入门到实践(三)
    AugularJS从入门到实践(二)
    用CSS实现响应式布局
    React+ANTD项目使用后的一些关于生命周期比较实用的心得
  • 原文地址:https://www.cnblogs.com/hongjiumu/p/3561511.html
Copyright © 2020-2023  润新知