• 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(); 
    } 
  • 相关阅读:
    Emacs for OIer 的一些配置
    CF1336E Chiori and Doll Picking 【线性代数,组合计数】
    CF605E Intergalaxy Trips 【贪心,动态规划,期望】
    Luogu6329 【模板】点分树 | 震波
    [SDOI2014]数表
    [BZOJ4403]序列统计
    [BZOJ5099]Pionek
    SP1812 LCS2
    SA & SAM
    [HAOI2016]找相同字符
  • 原文地址:https://www.cnblogs.com/hongjiumu/p/3561511.html
Copyright © 2020-2023  润新知