2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "utils/XBMCTinyXML.h"
24 static bool HasChild(const TiXmlNode
* pRootNode
, const char* strTag
);
25 static bool HasChild(const tinyxml2::XMLNode
* rootNode
, const char* tag
);
27 static bool GetHex(const TiXmlNode
* pRootNode
, const char* strTag
, uint32_t& dwHexValue
);
28 static bool GetUInt(const TiXmlNode
* pRootNode
, const char* strTag
, uint32_t& dwUIntValue
);
29 static bool GetLong(const TiXmlNode
* pRootNode
, const char* strTag
, long& lLongValue
);
30 static bool GetFloat(const TiXmlNode
* pRootNode
, const char* strTag
, float& value
);
31 static bool GetDouble(const TiXmlNode
* pRootNode
, const char* strTag
, double& value
);
32 static bool GetInt(const TiXmlNode
* pRootNode
, const char* strTag
, int& iIntValue
);
33 static bool GetBoolean(const TiXmlNode
* pRootNode
, const char* strTag
, bool& bBoolValue
);
35 static bool GetHex(const tinyxml2::XMLNode
* rootNode
, const char* tag
, uint32_t& value
);
36 static bool GetUInt(const tinyxml2::XMLNode
* rootNode
, const char* tag
, uint32_t& value
);
37 static bool GetLong(const tinyxml2::XMLNode
* rootNode
, const char* tag
, long& value
);
38 static bool GetFloat(const tinyxml2::XMLNode
* rootNode
, const char* tag
, float& value
);
39 static bool GetDouble(const tinyxml2::XMLNode
* rootNode
, const char* tag
, double& value
);
40 static bool GetInt(const tinyxml2::XMLNode
* rootNode
, const char* tag
, int& value
);
41 static bool GetBoolean(const tinyxml2::XMLNode
* rootNode
, const char* tag
, bool& value
);
43 /*! \brief Get a string value from the xml tag
44 If the specified tag isn't found strStringvalue is not modified and will contain whatever
45 value it had before the method call.
47 \param[in] pRootNode the xml node that contains the tag
48 \param[in] strTag the xml tag to read from
49 \param[in,out] strStringValue where to store the read string
50 \return true on success, false if the tag isn't found
52 static bool GetString(const TiXmlNode
* pRootNode
, const char* strTag
, std::string
& strStringValue
);
53 static bool GetString(const tinyxml2::XMLNode
* rootNode
, const char* tag
, std::string
& value
);
55 /*! \brief Get a string value from the xml tag
57 \param[in] pRootNode the xml node that contains the tag
58 \param[in] strTag the tag to read from
60 \return the value in the specified tag or an empty string if the tag isn't found
62 static std::string
GetString(const TiXmlNode
* pRootNode
, const char* strTag
);
63 static std::string
GetString(const tinyxml2::XMLNode
* rootNode
, const char* tag
);
64 /*! \brief Get multiple tags, concatenating the values together.
67 <tag clear="true">value2</tag>
70 into value2<sep>...<sep>valuen, appending it to the value string. Note that <value1> is overwritten by the clear="true" tag.
72 \param rootNode the parent containing the <tag>'s.
73 \param tag the <tag> in question.
74 \param separator the separator to use when concatenating values.
75 \param value [out] the resulting string. Remains untouched if no <tag> is available, else is appended (or cleared based on the clear parameter).
76 \param clear if true, clears the string prior to adding tags, if tags are available. Defaults to false.
78 static bool GetAdditiveString(const TiXmlNode
* rootNode
, const char* tag
, const std::string
& separator
, std::string
& value
, bool clear
= false);
79 static bool GetStringArray(const TiXmlNode
* rootNode
, const char* tag
, std::vector
<std::string
>& arrayValue
, bool clear
= false, const std::string
& separator
= "");
80 static bool GetPath(const TiXmlNode
* pRootNode
, const char* strTag
, std::string
& strStringValue
);
81 static bool GetFloat(const TiXmlNode
* pRootNode
, const char* strTag
, float& value
, const float min
, const float max
);
82 static bool GetUInt(const TiXmlNode
* pRootNode
, const char* strTag
, uint32_t& dwUIntValue
, const uint32_t min
, const uint32_t max
);
83 static bool GetInt(const TiXmlNode
* pRootNode
, const char* strTag
, int& iIntValue
, const int min
, const int max
);
84 static bool GetDate(const TiXmlNode
* pRootNode
, const char* strTag
, CDateTime
& date
);
85 static bool GetDateTime(const TiXmlNode
* pRootNode
, const char* strTag
, CDateTime
& dateTime
);
87 static bool GetAdditiveString(const tinyxml2::XMLNode
* rootNode
,
89 const std::string
& separator
,
92 static bool GetStringArray(const tinyxml2::XMLNode
* rootNode
,
94 std::vector
<std::string
>& value
,
96 const std::string
& separator
= "");
97 static bool GetPath(const tinyxml2::XMLNode
* rootNode
, const char* tag
, std::string
& value
);
98 static bool GetFloat(const tinyxml2::XMLNode
* rootNode
,
103 static bool GetUInt(const tinyxml2::XMLNode
* rootNode
,
109 const tinyxml2::XMLNode
* rootNode
, const char* tag
, int& value
, const int min
, const int max
);
110 static bool GetDate(const tinyxml2::XMLNode
* rootNode
, const char* tag
, CDateTime
& date
);
111 static bool GetDateTime(const tinyxml2::XMLNode
* rootNode
, const char* tag
, CDateTime
& dateTime
);
112 /*! \brief Fetch a std::string copy of an attribute, if it exists. Cannot distinguish between empty and non-existent attributes.
113 \param element the element to query.
114 \param tag the name of the attribute.
115 \return the attribute, if it exists, else an empty string
117 static std::string
GetAttribute(const TiXmlElement
*element
, const char *tag
);
118 static std::string
GetAttribute(const tinyxml2::XMLElement
* element
, const char* tag
);
120 static TiXmlNode
* SetString(TiXmlNode
* pRootNode
, const char *strTag
, const std::string
& strValue
);
121 static void SetAdditiveString(TiXmlNode
* pRootNode
, const char *strTag
, const std::string
& strSeparator
, const std::string
& strValue
);
122 static void SetStringArray(TiXmlNode
* pRootNode
, const char *strTag
, const std::vector
<std::string
>& arrayValue
);
123 static TiXmlNode
* SetInt(TiXmlNode
* pRootNode
, const char *strTag
, int value
);
124 static TiXmlNode
* SetFloat(TiXmlNode
* pRootNode
, const char *strTag
, float value
);
125 static TiXmlNode
* SetDouble(TiXmlNode
* pRootNode
, const char* strTag
, double value
);
126 static void SetBoolean(TiXmlNode
* pRootNode
, const char *strTag
, bool value
);
127 static void SetHex(TiXmlNode
* pRootNode
, const char *strTag
, uint32_t value
);
128 static void SetPath(TiXmlNode
* pRootNode
, const char *strTag
, const std::string
& strValue
);
129 static void SetLong(TiXmlNode
* pRootNode
, const char *strTag
, long iValue
);
130 static void SetDate(TiXmlNode
* pRootNode
, const char *strTag
, const CDateTime
& date
);
131 static void SetDateTime(TiXmlNode
* pRootNode
, const char *strTag
, const CDateTime
& dateTime
);
133 static tinyxml2::XMLNode
* SetString(tinyxml2::XMLNode
* rootNode
,
135 const std::string
& value
);
136 static void SetAdditiveString(tinyxml2::XMLNode
* rootNode
,
138 const std::string
& separator
,
139 const std::string
& value
);
140 static void SetStringArray(tinyxml2::XMLNode
* rootNode
,
142 const std::vector
<std::string
>& value
);
143 static tinyxml2::XMLNode
* SetInt(tinyxml2::XMLNode
* rootNode
, const char* tag
, int value
);
144 static tinyxml2::XMLNode
* SetFloat(tinyxml2::XMLNode
* rootNode
, const char* tag
, float value
);
145 static tinyxml2::XMLNode
* SetDouble(tinyxml2::XMLNode
* rootNode
, const char* tag
, double value
);
146 static void SetBoolean(tinyxml2::XMLNode
* rootNode
, const char* tag
, bool value
);
147 static void SetHex(tinyxml2::XMLNode
* rootNode
, const char* tag
, uint32_t value
);
148 static void SetPath(tinyxml2::XMLNode
* rootNode
, const char* tag
, const std::string
& value
);
149 static void SetLong(tinyxml2::XMLNode
* rootNode
, const char* tag
, long value
);
150 static void SetDate(tinyxml2::XMLNode
* rootNode
, const char* tag
, const CDateTime
& date
);
151 static void SetDateTime(tinyxml2::XMLNode
* rootNode
, const char* tag
, const CDateTime
& dateTime
);
153 static const int path_version
= 1;