BVB Source Codes

CRYENGINE Show XmlSerializeHelper.cpp Source code

Return Download CRYENGINE: download XmlSerializeHelper.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /*************************************************************************
  4.    -------------------------------------------------------------------------
  5.    $Id$
  6.    $DateTime$
  7.    Description: Manages one-off reader/writer usages for Xml serialization
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - 02:06:2010: Created by Kevin Kirst
  12.  
  13. *************************************************************************/
  14.  
  15. #include "StdAfx.h"
  16. #include "XmlSerializeHelper.h"
  17.  
  18. //////////////////////////////////////////////////////////////////////////
  19. CXmlSerializedObject::CXmlSerializedObject(const char* szSection)
  20.         : m_nRefCount(0)
  21.         , m_sTag(szSection)
  22. {
  23.         assert(szSection && szSection[0]);
  24. }
  25.  
  26. //////////////////////////////////////////////////////////////////////////
  27. void CXmlSerializedObject::GetMemoryUsage(ICrySizer* pSizer) const
  28. {
  29.         pSizer->Add(*this);
  30.         if (m_XmlNode)
  31.         {
  32.                 m_XmlNode.GetMemoryUsage(pSizer);
  33.         }
  34. }
  35.  
  36. //////////////////////////////////////////////////////////////////////////
  37. bool CXmlSerializedObject::IsEmpty() const
  38. {
  39.         return (!m_XmlNode || (m_XmlNode->getChildCount() <= 0 && m_XmlNode->getNumAttributes() <= 0));
  40. }
  41.  
  42. //////////////////////////////////////////////////////////////////////////
  43. void CXmlSerializedObject::Reset()
  44. {
  45.         m_XmlNode = XmlNodeRef();
  46. }
  47.  
  48. //////////////////////////////////////////////////////////////////////////
  49. void CXmlSerializedObject::Serialize(TSerialize& serialize)
  50. {
  51.         serialize.Value(m_sTag.c_str(), m_XmlNode);
  52. }
  53.  
  54. //////////////////////////////////////////////////////////////////////////
  55. void CXmlSerializedObject::CreateRootNode()
  56. {
  57.         m_XmlNode = gEnv->pSystem->CreateXmlNode(m_sTag.c_str());
  58.         assert(m_XmlNode);
  59. }
  60.  
  61. //////////////////////////////////////////////////////////////////////////
  62. //////////////////////////////////////////////////////////////////////////
  63.  
  64. //////////////////////////////////////////////////////////////////////////
  65. CXmlSerializeHelper::CXmlSerializeHelper()
  66.         : m_nRefCount(1)
  67.         , m_pSerializer()
  68. {
  69.         m_pSerializer = GetISystem()->GetXmlUtils()->CreateXmlSerializer();
  70. }
  71.  
  72. //////////////////////////////////////////////////////////////////////////
  73. CXmlSerializeHelper::~CXmlSerializeHelper()
  74. {
  75.  
  76. }
  77.  
  78. //////////////////////////////////////////////////////////////////////////
  79. void CXmlSerializeHelper::GetMemoryUsage(ICrySizer* pSizer) const
  80. {
  81.         pSizer->Add(*this);
  82.         pSizer->AddObject(m_pSerializer);
  83. }
  84.  
  85. //////////////////////////////////////////////////////////////////////////
  86. _smart_ptr<ISerializedObject> CXmlSerializeHelper::CreateSerializedObject(const char* szSection)
  87. {
  88.         assert(szSection && szSection[0]);
  89.         return _smart_ptr<ISerializedObject>(new CXmlSerializedObject(szSection));
  90. }
  91.  
  92. //////////////////////////////////////////////////////////////////////////
  93. CXmlSerializedObject* CXmlSerializeHelper::GetXmlSerializedObject(ISerializedObject* pObject)
  94. {
  95.         assert(pObject);
  96.  
  97.         CXmlSerializedObject* pXmlObject = NULL;
  98.         if (pObject && CXmlSerializedObject::GUID == pObject->GetGUID())
  99.         {
  100.                 pXmlObject = static_cast<CXmlSerializedObject*>(pObject);
  101.                 assert(pXmlObject);
  102.         }
  103.  
  104.         return pXmlObject;
  105. }
  106.  
  107. //////////////////////////////////////////////////////////////////////////
  108. bool CXmlSerializeHelper::Write(ISerializedObject* pObject, TSerializeFunc serializeFunc, void* pArgument /*= NULL*/)
  109. {
  110.         assert(pObject);
  111.  
  112.         bool bResult = false;
  113.  
  114.         if (CXmlSerializedObject* pXmlObject = GetXmlSerializedObject(pObject))
  115.         {
  116.                 pXmlObject->CreateRootNode();
  117.                 ISerialize* pWriter = GetWriter(pXmlObject->GetXmlNode());
  118.  
  119.                 TSerialize stateWriter(pWriter);
  120.                 bResult = serializeFunc(stateWriter, pArgument);
  121.         }
  122.  
  123.         return bResult;
  124. }
  125.  
  126. //////////////////////////////////////////////////////////////////////////
  127. bool CXmlSerializeHelper::Read(ISerializedObject* pObject, TSerializeFunc serializeFunc, void* pArgument /*= NULL*/)
  128. {
  129.         assert(pObject);
  130.  
  131.         bool bResult = false;
  132.  
  133.         if (CXmlSerializedObject* pXmlObject = GetXmlSerializedObject(pObject))
  134.         {
  135.                 ISerialize* pReader = GetReader(pXmlObject->GetXmlNode());
  136.  
  137.                 TSerialize stateReader(pReader);
  138.                 bResult = serializeFunc(stateReader, pArgument);
  139.         }
  140.  
  141.         return bResult;
  142. }
  143.  
  144. //////////////////////////////////////////////////////////////////////////
  145. ISerialize* CXmlSerializeHelper::GetWriter(XmlNodeRef& node)
  146. {
  147.         return m_pSerializer->GetWriter(node);
  148. }
  149.  
  150. //////////////////////////////////////////////////////////////////////////
  151. ISerialize* CXmlSerializeHelper::GetReader(XmlNodeRef& node)
  152. {
  153.         return m_pSerializer->GetReader(node);
  154. }
  155.  
downloadXmlSerializeHelper.cpp 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