BVB Source Codes

CRYENGINE Show XMLCPB_Reader.h Source code

Return Download CRYENGINE: download XMLCPB_Reader.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /*************************************************************************
  4. *************************************************************************/
  5.  
  6. #pragma once
  7. #ifndef XMLCPB_READER_H
  8.         #define XMLCPB_READER_H
  9.  
  10.         #include "XMLCPB_StringTableReader.h"
  11.         #include "XMLCPB_AttrSetTableReader.h"
  12.         #include "XMLCPB_NodeLiveReader.h"
  13.         #include "XMLCPB_BufferReader.h"
  14.         #include <CryCore/Platform/IPlatformOS.h>
  15.  
  16. namespace XMLCPB {
  17.  
  18. // CReader should not be used directly from outside. use CReaderInterface instead.
  19.  
  20. class CReader
  21. {
  22. public:
  23.         static _smart_ptr<IGeneralMemoryHeap> CreateHeap();
  24.  
  25. public:
  26.  
  27.         explicit CReader(IGeneralMemoryHeap* pHeap);
  28.         ~CReader();
  29.  
  30.         CNodeLiveReaderRef         GetRoot();
  31.         CNodeLiveReaderRef         CreateNodeRef();
  32.         bool                       ReadBinaryFile(const char* pFileName);
  33.         bool                       ReadBinaryMemory(const uint8* pData, uint32 uSize);
  34.         void                       SaveTestFiles();
  35.         uint32                     GetTotalDataSize() const     { return m_totalSize; }
  36.         uint32                     GetNodesDataSize() const     { return m_nodesDataSize; }
  37.         uint32                     GetNumNodes() const          { return m_numNodes; }
  38.  
  39.         const CStringTableReader&  GetAttrNamesTable() const    { return m_tableAttrNames; }
  40.         const CStringTableReader&  GetStrDataTable() const      { return m_tableStrData; }
  41.         const CStringTableReader&  GetTagsTable() const         { return m_tableTags; }
  42.         const CAttrSetTableReader& GetDataTypeSetsTable() const { return m_tableAttrSets; }
  43.         const CNodeLiveReader&     ActivateLiveNodeFromCompact(NodeGlobalID nodeId);
  44.         CNodeLiveReader*           GetNodeLive(NodeLiveID nodeId);
  45.         void                       FreeNodeLive(NodeLiveID nodeId);
  46.         template<class T>
  47.         FlatAddr                   ReadFromBuffer(FlatAddr addr, T& data);
  48.         template<class T>
  49.         FlatAddr                   ReadFromBufferEndianAware(FlatAddr addr, T& data);
  50.         FlatAddr                   ReadFromBuffer(FlatAddr addr, uint8*& rdata, uint32 len);
  51.         void                       ReadDataFromFile(IPlatformOS::ISaveReaderPtr& pOSSaveReader, void* pDst, uint32 numBytes);
  52.         void                       ReadDataFromMemory(const uint8* pData, uint32 dataSize, void* pDst, uint32 numBytes, uint32& outReadLoc);
  53.         FlatAddr                   GetAddrNode(NodeGlobalID id) const;
  54.         const uint8*               GetPointerFromFlatAddr(FlatAddr addr) const { return m_buffer.GetPointer(addr); }
  55.  
  56. private:
  57.  
  58.         void CheckErrorFlag(IPlatformOS::EFileOperationCode code);
  59.         void ReadDataFromFileInternal(IPlatformOS::ISaveReaderPtr& pOSSaveReader, void* pSrc, uint32 numBytes);
  60.         void ReadDataFromZLibBuffer(IPlatformOS::ISaveReaderPtr& pOSSaveReader, uint8*& pDst, uint32& numBytesToRead);
  61.         void CreateNodeAddressTables();
  62.  
  63.         #ifdef XMLCPB_CHECK_FILE_INTEGRITY
  64.         bool CheckFileCorruption(IPlatformOS::ISaveReaderPtr& pOSSaveReader, const SFileHeader& fileHeader, uint32 totalSize);
  65.         #endif
  66.  
  67. private:
  68.         typedef DynArray<CNodeLiveReader, int, NArray::SmallDynStorage<NAlloc::GeneralHeapAlloc>> LiveNodesVec;
  69.         typedef DynArray<FlatAddr, int, NArray::SmallDynStorage<NAlloc::GeneralHeapAlloc>>        FlatAddrVec;
  70.  
  71.         _smart_ptr<IGeneralMemoryHeap> m_pHeap;
  72.         LiveNodesVec                   m_liveNodes;
  73.         SBufferReader                  m_buffer;
  74.         uint32                         m_firstFreeLiveNode;
  75.         CStringTableReader             m_tableTags;
  76.         CStringTableReader             m_tableAttrNames;
  77.         CStringTableReader             m_tableStrData;
  78.         CAttrSetTableReader            m_tableAttrSets;
  79.         uint32                         m_maxNumActiveNodes;
  80.         uint32                         m_numActiveNodes;
  81.         uint32                         m_totalSize;
  82.         uint32                         m_nodesDataSize;
  83.         uint8*                         m_pZLibBuffer;                // zlib output uncompressed data buffer
  84.         uint8*                         m_pZLibCompressedBuffer;      // zlib input compressed data buffer
  85.         uint32                         m_ZLibBufferSizeWithData;     // how much of m_pZLibBuffer is filled with actual data
  86.         uint32                         m_ZLibBufferSizeAlreadyRead;  // how much of m_pZLibBuffer is already been read
  87.         uint32                         m_numNodes;
  88.         bool                           m_errorReading;
  89.         FlatAddrVec                    m_nodesAddrTable;     // stores the address of each node. Index is the NodeGlobalId (which is the order in the big buffer)
  90.  
  91.         static int                     MAX_NUM_LIVE_NODES;
  92. };
  93.  
  94. template<class T>
  95. FlatAddr CReader::ReadFromBuffer(FlatAddr addr, T& data)
  96. {
  97.         uint8* pDst = (uint8*)(&data);
  98.  
  99.         m_buffer.CopyTo(pDst, addr, sizeof(T));
  100.  
  101.         return addr + sizeof(T);
  102. }
  103.  
  104. template<class T>
  105. FlatAddr CReader::ReadFromBufferEndianAware(FlatAddr addr, T& data)
  106. {
  107.         uint8* pDst = (uint8*)(&data);
  108.  
  109.         m_buffer.CopyTo(pDst, addr, sizeof(T));
  110.  
  111.         SwapIntegerValue(data);
  112.  
  113.         return addr + sizeof(T);
  114. }
  115.  
  116. //////////////////////////////////////////////////////////////////////////
  117.  
  118. inline FlatAddr CReader::GetAddrNode(NodeGlobalID id) const
  119. {
  120.         assert(id < m_numNodes);
  121.  
  122.         FlatAddr addr = m_nodesAddrTable[id];
  123.         return addr;
  124. }
  125.  
  126. }  // end namespace
  127.  
  128. #endif
  129.  
downloadXMLCPB_Reader.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top