[XAudio2] avoid leak + fix voice creation for closest match
[xbmc.git] / xbmc / DbUrl.cpp
blob170a736a97f598e3273b26e860b8b8f909480773
1 /*
2 * Copyright (C) 2012-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 #include "DbUrl.h"
11 #include "utils/URIUtils.h"
13 CDbUrl::CDbUrl()
15 Reset();
18 CDbUrl::~CDbUrl() = default;
20 void CDbUrl::Reset()
22 m_valid = false;
23 m_type.clear();
24 m_url.Reset();
25 m_options.clear();
28 std::string CDbUrl::ToString() const
30 if (!m_valid)
31 return "";
33 return m_url.Get();
36 bool CDbUrl::FromString(const std::string &dbUrl)
38 Reset();
40 m_url.Parse(dbUrl);
41 m_valid = parse();
43 if (!m_valid)
44 Reset();
46 return m_valid;
49 void CDbUrl::AppendPath(const std::string &subPath)
51 if (!m_valid || subPath.empty())
52 return;
54 m_url.SetFileName(URIUtils::AddFileToFolder(m_url.GetFileName(), subPath));
57 void CDbUrl::AddOption(const std::string &key, const char *value)
59 if (!validateOption(key, value))
60 return;
62 CUrlOptions::AddOption(key, value);
63 updateOptions();
66 void CDbUrl::AddOption(const std::string &key, const std::string &value)
68 if (!validateOption(key, value))
69 return;
71 CUrlOptions::AddOption(key, value);
72 updateOptions();
75 void CDbUrl::AddOption(const std::string &key, int value)
77 if (!validateOption(key, value))
78 return;
80 CUrlOptions::AddOption(key, value);
81 updateOptions();
84 void CDbUrl::AddOption(const std::string &key, float value)
86 if (!validateOption(key, value))
87 return;
89 CUrlOptions::AddOption(key, value);
90 updateOptions();
93 void CDbUrl::AddOption(const std::string &key, double value)
95 if (!validateOption(key, value))
96 return;
98 CUrlOptions::AddOption(key, value);
99 updateOptions();
102 void CDbUrl::AddOption(const std::string &key, bool value)
104 if (!validateOption(key, value))
105 return;
107 CUrlOptions::AddOption(key, value);
108 updateOptions();
111 void CDbUrl::AddOptions(const std::string &options)
113 CUrlOptions::AddOptions(options);
114 updateOptions();
117 void CDbUrl::RemoveOption(const std::string &key)
119 CUrlOptions::RemoveOption(key);
120 updateOptions();
123 bool CDbUrl::validateOption(const std::string &key, const CVariant &value)
125 return !key.empty();
128 void CDbUrl::updateOptions()
130 // Update the options string in the CURL object
131 std::string options = GetOptionsString();
132 if (!options.empty())
133 options = "?" + options;
135 m_url.SetOptions(options);