PageRenderTime 42ms CodeModel.GetById 18ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 1ms

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