/xbmc/utils/XMLUtils.h

http://github.com/xbmc/xbmc · C Header · 95 lines · 42 code · 11 blank · 42 comment · 0 complexity · 738b20762b0c0d37499eb89fd82ddff7 MD5 · raw file

  1. /*
  2. * Copyright (C) 2005-2018 Team Kodi
  3. * This file is part of Kodi - https://kodi.tv
  4. *
  5. * SPDX-License-Identifier: GPL-2.0-or-later
  6. * See LICENSES/README.md for more information.
  7. */
  8. #pragma once
  9. #include "utils/XBMCTinyXML.h"
  10. #include <stdint.h>
  11. #include <string>
  12. #include <vector>
  13. class CDateTime;
  14. class XMLUtils
  15. {
  16. public:
  17. static bool HasChild(const TiXmlNode* pRootNode, const char* strTag);
  18. static bool GetHex(const TiXmlNode* pRootNode, const char* strTag, uint32_t& dwHexValue);
  19. static bool GetUInt(const TiXmlNode* pRootNode, const char* strTag, uint32_t& dwUIntValue);
  20. static bool GetLong(const TiXmlNode* pRootNode, const char* strTag, long& lLongValue);
  21. static bool GetFloat(const TiXmlNode* pRootNode, const char* strTag, float& value);
  22. static bool GetDouble(const TiXmlNode* pRootNode, const char* strTag, double& value);
  23. static bool GetInt(const TiXmlNode* pRootNode, const char* strTag, int& iIntValue);
  24. static bool GetBoolean(const TiXmlNode* pRootNode, const char* strTag, bool& bBoolValue);
  25. /*! \brief Get a string value from the xml tag
  26. If the specified tag isn't found strStringvalue is not modified and will contain whatever
  27. value it had before the method call.
  28. \param[in] pRootNode the xml node that contains the tag
  29. \param[in] strTag the xml tag to read from
  30. \param[in,out] strStringValue where to store the read string
  31. \return true on success, false if the tag isn't found
  32. */
  33. static bool GetString(const TiXmlNode* pRootNode, const char* strTag, std::string& strStringValue);
  34. /*! \brief Get a string value from the xml tag
  35. \param[in] pRootNode the xml node that contains the tag
  36. \param[in] strTag the tag to read from
  37. \return the value in the specified tag or an empty string if the tag isn't found
  38. */
  39. static std::string GetString(const TiXmlNode* pRootNode, const char* strTag);
  40. /*! \brief Get multiple tags, concatenating the values together.
  41. Transforms
  42. <tag>value1</tag>
  43. <tag clear="true">value2</tag>
  44. ...
  45. <tag>valuen</tag>
  46. into value2<sep>...<sep>valuen, appending it to the value string. Note that <value1> is overwritten by the clear="true" tag.
  47. \param rootNode the parent containing the <tag>'s.
  48. \param tag the <tag> in question.
  49. \param separator the separator to use when concatenating values.
  50. \param value [out] the resulting string. Remains untouched if no <tag> is available, else is appended (or cleared based on the clear parameter).
  51. \param clear if true, clears the string prior to adding tags, if tags are available. Defaults to false.
  52. */
  53. static bool GetAdditiveString(const TiXmlNode* rootNode, const char* tag, const std::string& separator, std::string& value, bool clear = false);
  54. static bool GetStringArray(const TiXmlNode* rootNode, const char* tag, std::vector<std::string>& arrayValue, bool clear = false, const std::string& separator = "");
  55. static bool GetPath(const TiXmlNode* pRootNode, const char* strTag, std::string& strStringValue);
  56. static bool GetFloat(const TiXmlNode* pRootNode, const char* strTag, float& value, const float min, const float max);
  57. static bool GetUInt(const TiXmlNode* pRootNode, const char* strTag, uint32_t& dwUIntValue, const uint32_t min, const uint32_t max);
  58. static bool GetInt(const TiXmlNode* pRootNode, const char* strTag, int& iIntValue, const int min, const int max);
  59. static bool GetDate(const TiXmlNode* pRootNode, const char* strTag, CDateTime& date);
  60. static bool GetDateTime(const TiXmlNode* pRootNode, const char* strTag, CDateTime& dateTime);
  61. /*! \brief Fetch a std::string copy of an attribute, if it exists. Cannot distinguish between empty and non-existent attributes.
  62. \param element the element to query.
  63. \param tag the name of the attribute.
  64. \return the attribute, if it exists, else an empty string
  65. */
  66. static std::string GetAttribute(const TiXmlElement *element, const char *tag);
  67. static TiXmlNode* SetString(TiXmlNode* pRootNode, const char *strTag, const std::string& strValue);
  68. static void SetAdditiveString(TiXmlNode* pRootNode, const char *strTag, const std::string& strSeparator, const std::string& strValue);
  69. static void SetStringArray(TiXmlNode* pRootNode, const char *strTag, const std::vector<std::string>& arrayValue);
  70. static TiXmlNode* SetInt(TiXmlNode* pRootNode, const char *strTag, int value);
  71. static TiXmlNode* SetFloat(TiXmlNode* pRootNode, const char *strTag, float value);
  72. static TiXmlNode* SetDouble(TiXmlNode* pRootNode, const char* strTag, double value);
  73. static void SetBoolean(TiXmlNode* pRootNode, const char *strTag, bool value);
  74. static void SetHex(TiXmlNode* pRootNode, const char *strTag, uint32_t value);
  75. static void SetPath(TiXmlNode* pRootNode, const char *strTag, const std::string& strValue);
  76. static void SetLong(TiXmlNode* pRootNode, const char *strTag, long iValue);
  77. static void SetDate(TiXmlNode* pRootNode, const char *strTag, const CDateTime& date);
  78. static void SetDateTime(TiXmlNode* pRootNode, const char *strTag, const CDateTime& dateTime);
  79. static const int path_version = 1;
  80. };