Merge pull request #26293 from the-black-eagle/mka_read_more_tags
[xbmc.git] / xbmc / addons / addoninfo / AddonExtensions.h
blob2ea20117556f0130e6baeb02a7c88941d01fa671
1 /*
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.
7 */
9 #pragma once
11 #include <stdlib.h>
12 #include <string>
13 #include <vector>
15 namespace ADDON
18 class CAddonInfoBuilder;
19 class CAddonDatabaseSerializer;
21 struct SExtValue
23 explicit SExtValue(const std::string& strValue) : str(strValue) { }
24 const std::string& asString() const { return str; }
25 bool asBoolean() const;
26 int asInteger() const { return std::atoi(str.c_str()); }
27 float asFloat() const { return static_cast<float>(std::atof(str.c_str())); }
28 bool empty() const { return str.empty(); }
29 const std::string str;
32 class CExtValues;
33 class CAddonExtensions;
34 typedef std::vector<std::pair<std::string, CAddonExtensions>> EXT_ELEMENTS;
35 typedef std::vector<std::pair<std::string, SExtValue>> EXT_VALUE;
36 typedef std::vector<std::pair<std::string, CExtValues>> EXT_VALUES;
38 class CExtValues : public EXT_VALUE
40 public:
41 CExtValues(const EXT_VALUE& values) : EXT_VALUE(values) { }
43 const SExtValue GetValue(const std::string& id) const
45 for (const auto& value : *this)
47 if (value.first == id)
48 return value.second;
50 return SExtValue("");
54 class CAddonExtensions
56 public:
57 CAddonExtensions() = default;
58 ~CAddonExtensions() = default;
60 const SExtValue GetValue(const std::string& id) const;
61 const EXT_VALUES& GetValues() const;
62 const CAddonExtensions* GetElement(const std::string& id) const;
63 const EXT_ELEMENTS GetElements(const std::string& id = "") const;
65 void Insert(const std::string& id, const std::string& value);
67 private:
68 friend class CAddonInfoBuilder;
69 friend class CAddonDatabaseSerializer;
71 std::string m_point;
72 EXT_VALUES m_values;
73 EXT_ELEMENTS m_children;
76 } /* namespace ADDON */