IXml.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <platform.h>
  10. #include <Cry_Math.h>
  11. #include <AzCore/IO/FileIO.h>
  12. template <class T>
  13. struct Color_tpl;
  14. typedef Color_tpl<uint8> ColorB;
  15. template <typename F>
  16. struct Vec2_tpl;
  17. typedef Vec2_tpl<f32> Vec2;
  18. template <typename F>
  19. struct Vec3_tpl;
  20. typedef Vec3_tpl<f32> Vec3;
  21. struct Vec4;
  22. template <typename F>
  23. struct Quat_tpl;
  24. typedef Quat_tpl<f32> Quat;
  25. template <typename F>
  26. struct Ang3_tpl;
  27. typedef Ang3_tpl<f32> Ang3;
  28. #if defined(QT_VERSION)
  29. #include <QColor>
  30. #include <QString>
  31. #elif defined(_AFX)
  32. #include "Util/GuidUtil.h"
  33. #endif
  34. #include <AzCore/Math/Guid.h>
  35. #include <AzCore/Math/Uuid.h>
  36. class QColor;
  37. class QString;
  38. class IXMLBinarySerializer;
  39. struct ISerialize;
  40. /*
  41. This is wrapper around expat library to provide DOM type of access for xml.
  42. Do not use IXmlNode class directly instead always use XmlNodeRef wrapper that
  43. takes care of memory management issues.
  44. Usage Example:
  45. -------------------------------------------------------
  46. void testXml(bool bReuseStrings)
  47. {
  48. XmlParser xml(bReuseStrings);
  49. XmlNodeRef root = xml.ParseFile("test.xml", true);
  50. if (root)
  51. {
  52. for (int i = 0; i < root->getChildCount(); ++i)
  53. {
  54. XmlNodeRef child = root->getChild(i);
  55. if (child->isTag("world"))
  56. {
  57. if (child->getAttr("name") == "blah")
  58. {
  59. ....
  60. }
  61. }
  62. }
  63. }
  64. }
  65. */
  66. // Summary:
  67. // Special string wrapper for xml nodes.
  68. class XmlString
  69. : public AZStd::string
  70. {
  71. public:
  72. XmlString() {};
  73. XmlString(const char* str)
  74. : AZStd::string(str) {}
  75. size_t GetAllocatedMemory() const
  76. {
  77. return sizeof(XmlString) + capacity() * sizeof(AZStd::string::value_type);
  78. }
  79. operator const char*() const
  80. {
  81. return c_str();
  82. }
  83. };
  84. // Summary:
  85. // XML string data.
  86. struct IXmlStringData
  87. {
  88. // <interfuscator:shuffle>
  89. virtual ~IXmlStringData(){}
  90. virtual void AddRef() = 0;
  91. virtual void Release() = 0;
  92. virtual const char* GetString() = 0;
  93. virtual size_t GetStringLength() = 0;
  94. // </interfuscator:shuffle>
  95. };
  96. class IXmlNode;
  97. // Summary:
  98. // XmlNodeRef, wrapper class implementing reference counting for IXmlNode.
  99. // See also:
  100. // IXmlNode
  101. class XmlNodeRef
  102. {
  103. private:
  104. IXmlNode* p;
  105. public:
  106. XmlNodeRef()
  107. : p(NULL) {}
  108. XmlNodeRef(IXmlNode* p_);
  109. XmlNodeRef(const XmlNodeRef& p_);
  110. ~XmlNodeRef();
  111. operator IXmlNode*() const {
  112. return p;
  113. }
  114. IXmlNode& operator*() const { return *p; }
  115. IXmlNode* operator->(void) const { return p; }
  116. XmlNodeRef& operator=(IXmlNode* newp);
  117. XmlNodeRef& operator=(const XmlNodeRef& newp);
  118. template<typename Sizer >
  119. void GetMemoryUsage(Sizer* pSizer) const
  120. {
  121. pSizer->AddObject(p);
  122. }
  123. //Support for range based for, and stl algorithms.
  124. class XmlNodeRefIterator begin();
  125. class XmlNodeRefIterator end();
  126. };
  127. // Summary:
  128. // IXmlNode class
  129. // Notes:
  130. // Never use IXmlNode directly instead use reference counted XmlNodeRef.
  131. // See also:
  132. // XmlNodeRef
  133. class IXmlNode
  134. {
  135. protected:
  136. int m_nRefCount;
  137. protected:
  138. // <interfuscator:shuffle>
  139. virtual void DeleteThis() = 0;
  140. virtual ~IXmlNode() {};
  141. // </interfuscator:shuffle>
  142. public:
  143. // <interfuscator:shuffle>
  144. // Summary:
  145. // Creates new XML node.
  146. virtual XmlNodeRef createNode(const char* tag) = 0;
  147. // Notes:
  148. // AddRef/Release need to be virtual to permit overloading from CXMLNodePool
  149. // Summary:
  150. // Reference counting.
  151. virtual void AddRef() { m_nRefCount++; };
  152. // Notes:
  153. // When ref count reach zero XML node dies.
  154. virtual void Release()
  155. {
  156. if (--m_nRefCount <= 0)
  157. {
  158. DeleteThis();
  159. }
  160. };
  161. virtual int GetRefCount() const { return m_nRefCount; };
  162. // Summary:
  163. // Gets XML node tag.
  164. virtual const char* getTag() const = 0;
  165. // Summary:
  166. // Sets XML node tag.
  167. virtual void setTag(const char* tag) = 0;
  168. // Summary:
  169. // Returns true if a given tag equal to node tag.
  170. virtual bool isTag(const char* tag) const = 0;
  171. // Summary:
  172. // Gets XML Node attributes.
  173. virtual int getNumAttributes() const = 0;
  174. // Summary:
  175. // Returns attribute key and value by attribute index.
  176. virtual bool getAttributeByIndex(int index, const char** key, const char** value) = 0;
  177. // Summary:
  178. // Copies attributes to this node from a given node.
  179. virtual void copyAttributes(XmlNodeRef fromNode) = 0;
  180. // Summary:
  181. // Gets XML Node attribute for specified key.
  182. // Return Value:
  183. // The value of the attribute if it exists, otherwise an empty string.
  184. virtual const char* getAttr(const char* key) const = 0;
  185. // Summary:
  186. // Gets XML Node attribute for specified key.
  187. // Return Value:
  188. // True if the attribute exists, false otherwise.
  189. virtual bool getAttr(const char* key, const char** value) const = 0;
  190. // Summary:
  191. // Checks if attributes with specified key exist.
  192. virtual bool haveAttr(const char* key) const = 0;
  193. // Summary:
  194. // Adds new child node.
  195. virtual void addChild(const XmlNodeRef& node) = 0;
  196. // Summary:
  197. // Creates new xml node and add it to childs list.
  198. virtual XmlNodeRef newChild(const char* tagName) = 0;
  199. // Summary:
  200. // Removes child node.
  201. virtual void removeChild(const XmlNodeRef& node) = 0;
  202. // Summary:
  203. // Removes all child nodes.
  204. virtual void removeAllChilds() = 0;
  205. // Summary:
  206. // Gets number of child XML nodes.
  207. virtual int getChildCount() const = 0;
  208. // Summary:
  209. // Gets XML Node child nodes.
  210. virtual XmlNodeRef getChild(int i) const = 0;
  211. // Summary:
  212. // Finds node with specified tag.
  213. virtual XmlNodeRef findChild(const char* tag) const = 0;
  214. // Summary:
  215. // Gets parent XML node.
  216. virtual XmlNodeRef getParent() const = 0;
  217. // Summary:
  218. // Sets parent XML node.
  219. virtual void setParent(const XmlNodeRef& inRef) = 0;
  220. // Summary:
  221. // Returns content of this node.
  222. virtual const char* getContent() const = 0;
  223. // Summary:
  224. // Sets content of this node.
  225. virtual void setContent(const char* str) = 0;
  226. // Summary:
  227. // Set line number in xml.
  228. virtual void setLine(int line) = 0;
  229. // Summary:
  230. // Returns XML of this node and sub nodes.
  231. // Notes:
  232. // IXmlStringData pointer must be release when string is not needed anymore.
  233. // See also:
  234. // IXmlStringData
  235. virtual IXmlStringData* getXMLData(int nReserveMem = 0) const = 0;
  236. // Summary:
  237. // Returns XML of this node and sub nodes.
  238. virtual XmlString getXML(int level = 0) const = 0;
  239. virtual bool saveToFile(const char* fileName) = 0;
  240. // Summary:
  241. // Sets new XML Node attribute (or override attribute with same key).
  242. //##@{
  243. virtual void setAttr(const char* key, const char* value) = 0;
  244. virtual void setAttr(const char* key, int value) = 0;
  245. virtual void setAttr(const char* key, unsigned int value) = 0;
  246. virtual void setAttr(const char* key, int64 value) = 0;
  247. virtual void setAttr(const char* key, uint64 value, bool useHexFormat = true) = 0;
  248. virtual void setAttr(const char* key, float value) = 0;
  249. virtual void setAttr(const char* key, double value) = 0;
  250. virtual void setAttr(const char* key, const Vec2& value) = 0;
  251. virtual void setAttr(const char* key, const Ang3& value) = 0;
  252. virtual void setAttr(const char* key, const Vec3& value) = 0;
  253. virtual void setAttr(const char* key, const Vec4& value) = 0;
  254. virtual void setAttr(const char* key, const Quat& value) = 0;
  255. #if defined(LINUX64) || defined(APPLE)
  256. // Compatibility functions, on Linux and Mac long int is the default int64_t
  257. ILINE void setAttr(const char* key, unsigned long int value, bool useHexFormat = true)
  258. {
  259. setAttr(key, (uint64)value, useHexFormat);
  260. }
  261. ILINE void setAttr(const char* key, long int value)
  262. {
  263. setAttr(key, (int64)value);
  264. }
  265. #endif
  266. virtual void setAttr([[maybe_unused]] const char* key, [[maybe_unused]] const QColor& color)
  267. {
  268. #if defined(QT_VERSION)
  269. setAttr(key, static_cast<unsigned long>(color.red() | (color.green() << 8) | (color.blue() << 16)));
  270. #endif
  271. }
  272. //##@}
  273. // Summary:
  274. // Inline Helpers.
  275. //##@{
  276. //##@}
  277. // Summary:
  278. // Deletes attribute.
  279. virtual void delAttr(const char* key) = 0;
  280. // Summary:
  281. // Removes all node attributes.
  282. virtual void removeAllAttributes() = 0;
  283. // Summary:
  284. // Gets attribute value of node.
  285. //##@{
  286. virtual bool getAttr(const char* key, int& value) const = 0;
  287. virtual bool getAttr(const char* key, unsigned int& value) const = 0;
  288. virtual bool getAttr(const char* key, int64& value) const = 0;
  289. virtual bool getAttr(const char* key, uint64& value, bool useHexFormat = true) const = 0;
  290. virtual bool getAttr(const char* key, float& value) const = 0;
  291. virtual bool getAttr(const char* key, double& value) const = 0;
  292. virtual bool getAttr(const char* key, Vec2& value) const = 0;
  293. virtual bool getAttr(const char* key, Ang3& value) const = 0;
  294. virtual bool getAttr(const char* key, Vec3& value) const = 0;
  295. virtual bool getAttr(const char* key, Vec4& value) const = 0;
  296. virtual bool getAttr(const char* key, Quat& value) const = 0;
  297. virtual bool getAttr(const char* key, bool& value) const = 0;
  298. virtual bool getAttr(const char* key, XmlString& value) const = 0;
  299. virtual bool getAttr(const char* key, ColorB& value) const = 0;
  300. #if defined(LINUX64) || defined(APPLE)
  301. // Compatibility functions, on Linux and Mac long int is the default int64_t
  302. ILINE bool getAttr(const char* key, unsigned long int& value, bool useHexFormat = true) const
  303. {
  304. return getAttr(key, (uint64&)value, useHexFormat);
  305. }
  306. ILINE bool getAttr(const char* key, long int& value) const
  307. {
  308. return getAttr(key, (int64&)value);
  309. }
  310. #endif
  311. // Notes:
  312. // Save in small memory chunks.
  313. virtual bool saveToFile(const char* fileName, size_t chunkSizeBytes, AZ::IO::HandleType fileHandle = AZ::IO::InvalidHandle) = 0;
  314. // </interfuscator:shuffle>
  315. //##@}
  316. // Summary:
  317. // Inline Helpers.
  318. //##@{
  319. #if !defined(LINUX64) && !defined(APPLE)
  320. bool getAttr(const char* key, long& value) const
  321. {
  322. int v;
  323. if (!getAttr(key, v))
  324. {
  325. return false;
  326. }
  327. value = static_cast<long>(v);
  328. return true;
  329. }
  330. bool getAttr(const char* key, unsigned long& value) const
  331. {
  332. int v;
  333. if (!getAttr(key, v))
  334. {
  335. return false;
  336. }
  337. value = static_cast<unsigned long>(v);
  338. return true;
  339. }
  340. void setAttr(const char* key, unsigned long value) { setAttr(key, (unsigned int)value); };
  341. void setAttr(const char* key, long value) { setAttr(key, (int)value); };
  342. #endif
  343. bool getAttr(const char* key, unsigned short& value) const
  344. {
  345. int v;
  346. if (!getAttr(key, v))
  347. {
  348. return false;
  349. }
  350. value = static_cast<unsigned short>(v);
  351. return true;
  352. }
  353. bool getAttr(const char* key, unsigned char& value) const
  354. {
  355. int v;
  356. if (!getAttr(key, v))
  357. {
  358. return false;
  359. }
  360. value = static_cast<unsigned char>(v);
  361. return true;
  362. }
  363. bool getAttr(const char* key, short& value) const
  364. {
  365. int v;
  366. if (!getAttr(key, v))
  367. {
  368. return false;
  369. }
  370. value = static_cast<short>(v);
  371. return true;
  372. }
  373. bool getAttr(const char* key, char& value) const
  374. {
  375. int v;
  376. if (!getAttr(key, v))
  377. {
  378. return false;
  379. }
  380. value = static_cast<char>(v);
  381. return true;
  382. }
  383. //##@}
  384. // Summary:
  385. // Gets QString attribute.
  386. bool getAttr([[maybe_unused]] const char* key, [[maybe_unused]] QString& value) const
  387. {
  388. #if defined(QT_VERSION)
  389. if (!haveAttr(key))
  390. {
  391. return false;
  392. }
  393. value = getAttr(key);
  394. return true;
  395. #else
  396. return false;
  397. #endif
  398. }
  399. bool getAttr([[maybe_unused]] const char* key, [[maybe_unused]] QColor& color) const
  400. {
  401. #if defined(QT_VERSION)
  402. if (!haveAttr(key))
  403. {
  404. return false;
  405. }
  406. int v;
  407. getAttr(key, v);
  408. color = QColor(v & 0xff, (v >> 8) & 0xff, (v >> 16) & 0xff);
  409. return true;
  410. #else
  411. return false;
  412. #endif
  413. }
  414. #if defined(QT_VERSION)
  415. // Summary:
  416. // Sets GUID attribute.
  417. void setAttr(const char* key, const GUID& value)
  418. {
  419. AZ::Uuid uuid;
  420. uuid = value;
  421. setAttr(key, uuid.ToString<AZStd::string>().c_str());
  422. };
  423. // Summary:
  424. // Gets GUID from attribute.
  425. bool getAttr(const char* key, GUID& value) const
  426. {
  427. if (!haveAttr(key))
  428. {
  429. return false;
  430. }
  431. const char* guidStr = getAttr(key);
  432. value = AZ::Uuid(guidStr);
  433. if (value.Data1 == 0)
  434. {
  435. memset(&value, 0, sizeof(value));
  436. // If bad GUID, use old guid system.
  437. value.Data1 = atoi(guidStr);
  438. }
  439. return true;
  440. }
  441. #elif defined(_AFX)
  442. // Summary:
  443. // Sets GUID attribute.
  444. void setAttr(const char* key, REFGUID value)
  445. {
  446. const char* str = GuidUtil::ToString(value);
  447. setAttr(key, str);
  448. };
  449. // Summary:
  450. // Gets GUID from attribute.
  451. bool getAttr(const char* key, GUID& value) const
  452. {
  453. if (!haveAttr(key))
  454. {
  455. return false;
  456. }
  457. const char* guidStr = getAttr(key);
  458. value = GuidUtil::FromString(guidStr);
  459. if (value.Data1 == 0)
  460. {
  461. memset(&value, 0, sizeof(value));
  462. // If bad GUID, use old guid system.
  463. value.Data1 = atoi(guidStr);
  464. }
  465. return true;
  466. }
  467. #endif
  468. // Summary:
  469. // Lets be friendly to him.
  470. friend class XmlNodeRef;
  471. };
  472. /*
  473. // Summary:
  474. // Inline Implementation of XmlNodeRef
  475. inline XmlNodeRef::XmlNodeRef(const char *tag, IXmlNode *node)
  476. {
  477. if (node)
  478. {
  479. p = node->createNode(tag);
  480. }
  481. else
  482. {
  483. p = new XmlNode(tag);
  484. }
  485. p->AddRef();
  486. }
  487. */
  488. //////////////////////////////////////////////////////////////////////////
  489. inline XmlNodeRef::XmlNodeRef(IXmlNode* p_)
  490. : p(p_)
  491. {
  492. if (p)
  493. {
  494. p->AddRef();
  495. }
  496. }
  497. inline XmlNodeRef::XmlNodeRef(const XmlNodeRef& p_)
  498. : p(p_.p)
  499. {
  500. if (p)
  501. {
  502. p->AddRef();
  503. }
  504. }
  505. inline XmlNodeRef::~XmlNodeRef()
  506. {
  507. if (p)
  508. {
  509. p->Release();
  510. }
  511. }
  512. inline XmlNodeRef& XmlNodeRef::operator=(IXmlNode* newp)
  513. {
  514. if (newp)
  515. {
  516. newp->AddRef();
  517. }
  518. if (p)
  519. {
  520. p->Release();
  521. }
  522. p = newp;
  523. return *this;
  524. }
  525. inline XmlNodeRef& XmlNodeRef::operator=(const XmlNodeRef& newp)
  526. {
  527. if (newp.p)
  528. {
  529. newp.p->AddRef();
  530. }
  531. if (p)
  532. {
  533. p->Release();
  534. }
  535. p = newp.p;
  536. return *this;
  537. }
  538. //XmlNodeRef can be treated as a container. Iterating through it, iterates through its children
  539. class XmlNodeRefIterator
  540. {
  541. public:
  542. XmlNodeRefIterator()
  543. : m_index(0)
  544. {
  545. }
  546. XmlNodeRefIterator(XmlNodeRef& parentNode, std::size_t index)
  547. : m_parentNode(parentNode)
  548. , m_index(index)
  549. {
  550. Update();
  551. }
  552. XmlNodeRefIterator& operator=(const XmlNodeRefIterator& other) = default;
  553. XmlNodeRefIterator& operator++()
  554. {
  555. ++m_index;
  556. Update();
  557. return *this;
  558. }
  559. XmlNodeRefIterator operator++(int)
  560. {
  561. XmlNodeRefIterator ret = *this;
  562. ++m_index;
  563. Update();
  564. return ret;
  565. }
  566. IXmlNode* operator*() const
  567. {
  568. return m_currentChildNode;
  569. }
  570. XmlNodeRefIterator& operator--()
  571. {
  572. --m_index;
  573. Update();
  574. return *this;
  575. }
  576. XmlNodeRefIterator operator--(int)
  577. {
  578. XmlNodeRefIterator ret = *this;
  579. --m_index;
  580. Update();
  581. return ret;
  582. }
  583. bool operator!=(const XmlNodeRefIterator& rhs) {
  584. return m_index != rhs.m_index;
  585. }
  586. private:
  587. friend void swap(XmlNodeRefIterator& lhs, XmlNodeRefIterator& rhs);
  588. friend bool operator==(const XmlNodeRefIterator& lhs, const XmlNodeRefIterator& rhs);
  589. friend bool operator!=(const XmlNodeRefIterator& lhs, const XmlNodeRefIterator& rhs);
  590. void Update()
  591. {
  592. if (m_index < m_parentNode->getChildCount())
  593. {
  594. m_currentChildNode = m_parentNode->getChild(static_cast<int>(m_index));
  595. }
  596. }
  597. XmlNodeRef m_parentNode;
  598. XmlNodeRef m_currentChildNode;
  599. std::size_t m_index; //default to first child, if no children then this will equal size which is what we use for the end iterator
  600. };
  601. inline void swap(XmlNodeRefIterator& lhs, XmlNodeRefIterator& rhs)
  602. {
  603. AZStd::swap(lhs.m_parentNode, rhs.m_parentNode);
  604. AZStd::swap(lhs.m_currentChildNode, rhs.m_currentChildNode);
  605. AZStd::swap(lhs.m_index, rhs.m_index);
  606. }
  607. inline bool operator==(const XmlNodeRefIterator& lhs, const XmlNodeRefIterator& rhs)
  608. {
  609. return lhs.m_index == rhs.m_index;
  610. }
  611. inline bool operator!=(const XmlNodeRefIterator& lhs, const XmlNodeRefIterator& rhs)
  612. {
  613. return lhs.m_index != rhs.m_index;
  614. }
  615. inline XmlNodeRefIterator XmlNodeRef::begin()
  616. {
  617. return XmlNodeRefIterator(*this, 0);
  618. }
  619. inline XmlNodeRefIterator XmlNodeRef::end()
  620. {
  621. return XmlNodeRefIterator(*this, (*this)->getChildCount());
  622. }
  623. //////////////////////////////////////////////////////////////////////////
  624. struct IXmlSerializer
  625. {
  626. // <interfuscator:shuffle>
  627. virtual ~IXmlSerializer(){}
  628. virtual void AddRef() = 0;
  629. virtual void Release() = 0;
  630. virtual ISerialize* GetWriter(XmlNodeRef& node) = 0;
  631. virtual ISerialize* GetReader(XmlNodeRef& node) = 0;
  632. // </interfuscator:shuffle>
  633. };
  634. //////////////////////////////////////////////////////////////////////////
  635. // Summary:
  636. // XML Parser interface.
  637. struct IXmlParser
  638. {
  639. virtual ~IXmlParser(){}
  640. virtual void AddRef() = 0;
  641. virtual void Release() = 0;
  642. // Summary:
  643. // Parses xml file.
  644. virtual XmlNodeRef ParseFile(const char* filename, bool bCleanPools) = 0;
  645. // Summary:
  646. // Parses xml from memory buffer.
  647. virtual XmlNodeRef ParseBuffer(const char* buffer, int nBufLen, bool bCleanPools, bool bSuppressWarnings = false) = 0;
  648. };
  649. //////////////////////////////////////////////////////////////////////////
  650. // Summary:
  651. // XML Table Reader interface.
  652. //
  653. // Can be used to read tables exported from Excel in .xml format. Supports
  654. // reading CryEngine's version of those Excel .xml tables (produced by RC).
  655. //
  656. // Usage:
  657. // p->Begin(rootNode);
  658. // while (p->ReadRow(...))
  659. // {
  660. // while (p->ReadCell(...))
  661. // {
  662. // ...
  663. // }
  664. // }
  665. struct IXmlTableReader
  666. {
  667. // <interfuscator:shuffle>
  668. virtual ~IXmlTableReader(){}
  669. virtual void Release() = 0;
  670. // Returns false if XML tree is not in supported table format.
  671. virtual bool Begin(XmlNodeRef rootNode) = 0;
  672. // Returns estimated number of rows (estimated number of ReadRow() calls returning true).
  673. // Returned number is equal *or greater* than real number, because it's impossible to
  674. // know real number in advance in case of Excel XML.
  675. virtual int GetEstimatedRowCount() = 0;
  676. // Prepares next row for reading by ReadCell().
  677. // Returns true and sets rowIndex if the row was prepared successfully.
  678. // Note: empty rows are skipped sometimes, so use returned rowIndex if you need
  679. // to know absolute row index.
  680. // Returns false if no rows left.
  681. virtual bool ReadRow(int& rowIndex) = 0;
  682. // Reads next cell in the current row.
  683. // Returns true and sets columnIndex, pContent, contenSize if the cell was read successfully.
  684. // Note: empty cells are skipped sometimes, so use returned cellIndex if you need
  685. // to know absolute cell index (i.e. column).
  686. // Returns false if no cells left in the row.
  687. virtual bool ReadCell(int& columnIndex, const char*& pContent, size_t& contentSize) = 0;
  688. // </interfuscator:shuffle>
  689. };
  690. //////////////////////////////////////////////////////////////////////////
  691. // Summary:
  692. // IXmlUtils structure.
  693. struct IXmlUtils
  694. {
  695. // <interfuscator:shuffle>
  696. virtual ~IXmlUtils(){}
  697. // Summary:
  698. // Loads xml file, returns 0 if load failed.
  699. virtual XmlNodeRef LoadXmlFromFile(const char* sFilename, bool bReuseStrings = false) = 0;
  700. // Summary:
  701. // Loads xml from memory buffer, returns 0 if load failed.
  702. virtual XmlNodeRef LoadXmlFromBuffer(const char* buffer, size_t size, bool bReuseStrings = false, bool bSuppressWarnings = false) = 0;
  703. // Summary:
  704. // Creates XML Writer for ISerialize interface.
  705. // See also:
  706. // IXmlSerializer
  707. virtual IXmlSerializer* CreateXmlSerializer() = 0;
  708. // Summary:
  709. // Creates XML Parser.
  710. // Notes:
  711. // WARNING!!!
  712. // IXmlParser does not normally support recursive XML loading, all nodes loaded by this parser are invalidated on loading new file.
  713. // This is a specialized interface for fast loading of many XMLs,
  714. // After use it must be released with call to Release method.
  715. virtual IXmlParser* CreateXmlParser() = 0;
  716. // Summary:
  717. // Creates XML Table reader.
  718. // Notes:
  719. // After use it must be released with call to Release method.
  720. virtual IXmlTableReader* CreateXmlTableReader() = 0;
  721. };