Skip to content

Commit

Permalink
fix shared_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
Montellese committed May 24, 2017
1 parent 5d1b4e5 commit 3021828
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 32 deletions.
1 change: 1 addition & 0 deletions xbmc/Autorun.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#ifdef HAS_DVD_DRIVE

#include <memory>
#include <string>
#include <utility>
#include <vector>
Expand Down
1 change: 1 addition & 0 deletions xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAESettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#pragma once

#include <memory>
#include <string>
#include <vector>

Expand Down
2 changes: 1 addition & 1 deletion xbmc/linux/LinuxTimezone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void CLinuxTimezone::OnSettingChanged(std::shared_ptr<const CSetting> setting)
const std::string &settingId = setting->GetId();
if (settingId == CSettings::SETTING_LOCALE_TIMEZONE)
{
SetTimezone(std::static_pointer_cast<CSettingString>(setting)->GetValue());
SetTimezone(std::static_pointer_cast<const CSettingString>(setting)->GetValue());

CDateTime::ResetTimezoneBias();
}
Expand Down
1 change: 1 addition & 0 deletions xbmc/powermanagement/PowerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
*/

#include <memory>
#include <string>
#include <utility>
#include <vector>
Expand Down
46 changes: 23 additions & 23 deletions xbmc/settings/lib/Setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,20 +487,20 @@ bool CSettingList::SetValue(const SettingList &values)
m_values.clear();
m_values.insert(m_values.begin(), values.begin(), values.end());

if (!OnSettingChanging(shared_from_this()))
if (!OnSettingChanging(shared_from_base<CSettingList>()))
{
m_values = oldValues;

// the setting couldn't be changed because one of the
// callback handlers failed the OnSettingChanging()
// callback so we need to let all the callback handlers
// know that the setting hasn't changed
OnSettingChanging(shared_from_this());
OnSettingChanging(shared_from_base<CSettingList>());
return false;
}

m_changed = (toString(m_values) != toString(m_defaults));
OnSettingChanged(shared_from_this());
OnSettingChanged(shared_from_base<CSettingList>());
return true;
}

Expand Down Expand Up @@ -679,20 +679,20 @@ bool CSettingBool::SetValue(bool value)
bool oldValue = m_value;
m_value = value;

if (!OnSettingChanging(shared_from_this()))
if (!OnSettingChanging(shared_from_base<CSettingBool>()))
{
m_value = oldValue;

// the setting couldn't be changed because one of the
// callback handlers failed the OnSettingChanging()
// callback so we need to let all the callback handlers
// know that the setting hasn't changed
OnSettingChanging(shared_from_this());
OnSettingChanging(shared_from_base<CSettingBool>());
return false;
}

m_changed = m_value != m_default;
OnSettingChanged(shared_from_this());
OnSettingChanged(shared_from_base<CSettingBool>());
return true;
}

Expand Down Expand Up @@ -810,7 +810,7 @@ bool CSettingInt::Deserialize(const TiXmlNode *node, bool update /* = false */)
m_optionsFillerName = options->FirstChild()->ValueStr();
if (!m_optionsFillerName.empty())
{
m_optionsFiller = (IntegerSettingOptionsFiller)m_settingsManager->GetSettingOptionsFiller(shared_from_this());
m_optionsFiller = (IntegerSettingOptionsFiller)m_settingsManager->GetSettingOptionsFiller(shared_from_base<CSettingInt>());
if (m_optionsFiller == NULL)
CLog::Log(LOGWARNING, "CSettingInt: unknown options filler \"%s\" of \"%s\"", m_optionsFillerName.c_str(), m_id.c_str());
}
Expand Down Expand Up @@ -908,20 +908,20 @@ bool CSettingInt::SetValue(int value)
int oldValue = m_value;
m_value = value;

if (!OnSettingChanging(shared_from_this()))
if (!OnSettingChanging(shared_from_base<CSettingInt>()))
{
m_value = oldValue;

// the setting couldn't be changed because one of the
// callback handlers failed the OnSettingChanging()
// callback so we need to let all the callback handlers
// know that the setting hasn't changed
OnSettingChanging(shared_from_this());
OnSettingChanging(shared_from_base<CSettingInt>());
return false;
}

m_changed = m_value != m_default;
OnSettingChanged(shared_from_this());
OnSettingChanged(shared_from_base<CSettingInt>());
return true;
}

Expand Down Expand Up @@ -957,13 +957,13 @@ IntegerSettingOptions CSettingInt::UpdateDynamicOptions()

if (m_optionsFiller == NULL)
{
m_optionsFiller = (IntegerSettingOptionsFiller)m_settingsManager->GetSettingOptionsFiller(shared_from_this());
m_optionsFiller = (IntegerSettingOptionsFiller)m_settingsManager->GetSettingOptionsFiller(shared_from_base<CSettingInt>());
if (m_optionsFiller == NULL)
return options;
}

int bestMatchingValue = m_value;
m_optionsFiller(shared_from_this(), options, bestMatchingValue, m_optionsFillerData);
m_optionsFiller(shared_from_base<CSettingInt>(), options, bestMatchingValue, m_optionsFillerData);

if (bestMatchingValue != m_value)
SetValue(bestMatchingValue);
Expand All @@ -985,7 +985,7 @@ IntegerSettingOptions CSettingInt::UpdateDynamicOptions()
if (changed)
{
m_dynamicOptions = options;
OnSettingPropertyChanged(shared_from_this(), "options");
OnSettingPropertyChanged(shared_from_base<CSettingInt>(), "options");
}

return options;
Expand Down Expand Up @@ -1143,20 +1143,20 @@ bool CSettingNumber::SetValue(double value)
double oldValue = m_value;
m_value = value;

if (!OnSettingChanging(shared_from_this()))
if (!OnSettingChanging(shared_from_base<CSettingNumber>()))
{
m_value = oldValue;

// the setting couldn't be changed because one of the
// callback handlers failed the OnSettingChanging()
// callback so we need to let all the callback handlers
// know that the setting hasn't changed
OnSettingChanging(shared_from_this());
OnSettingChanging(shared_from_base<CSettingNumber>());
return false;
}

m_changed = m_value != m_default;
OnSettingChanged(shared_from_this());
OnSettingChanged(shared_from_base<CSettingNumber>());
return true;
}

Expand Down Expand Up @@ -1246,7 +1246,7 @@ bool CSettingString::Deserialize(const TiXmlNode *node, bool update /* = false *
m_optionsFillerName = options->FirstChild()->ValueStr();
if (!m_optionsFillerName.empty())
{
m_optionsFiller = (StringSettingOptionsFiller)m_settingsManager->GetSettingOptionsFiller(shared_from_this());
m_optionsFiller = (StringSettingOptionsFiller)m_settingsManager->GetSettingOptionsFiller(shared_from_base<CSettingString>());
if (m_optionsFiller == NULL)
CLog::Log(LOGWARNING, "CSettingString: unknown options filler \"%s\" of \"%s\"", m_optionsFillerName.c_str(), m_id.c_str());
}
Expand Down Expand Up @@ -1317,20 +1317,20 @@ bool CSettingString::SetValue(const std::string &value)
std::string oldValue = m_value;
m_value = value;

if (!OnSettingChanging(shared_from_this()))
if (!OnSettingChanging(shared_from_base<CSettingString>()))
{
m_value = oldValue;

// the setting couldn't be changed because one of the
// callback handlers failed the OnSettingChanging()
// callback so we need to let all the callback handlers
// know that the setting hasn't changed
OnSettingChanging(shared_from_this());
OnSettingChanging(shared_from_base<CSettingString>());
return false;
}

m_changed = m_value != m_default;
OnSettingChanged(shared_from_this());
OnSettingChanged(shared_from_base<CSettingString>());
return true;
}

Expand Down Expand Up @@ -1366,13 +1366,13 @@ StringSettingOptions CSettingString::UpdateDynamicOptions()

if (m_optionsFiller == NULL)
{
m_optionsFiller = (StringSettingOptionsFiller)m_settingsManager->GetSettingOptionsFiller(shared_from_this());
m_optionsFiller = (StringSettingOptionsFiller)m_settingsManager->GetSettingOptionsFiller(shared_from_base<CSettingString>());
if (m_optionsFiller == NULL)
return options;
}

std::string bestMatchingValue = m_value;
m_optionsFiller(shared_from_this(), options, bestMatchingValue, m_optionsFillerData);
m_optionsFiller(shared_from_base<CSettingString>(), options, bestMatchingValue, m_optionsFillerData);

if (bestMatchingValue != m_value)
SetValue(bestMatchingValue);
Expand All @@ -1395,7 +1395,7 @@ StringSettingOptions CSettingString::UpdateDynamicOptions()
if (changed)
{
m_dynamicOptions = options;
OnSettingPropertyChanged(shared_from_this(), "options");
OnSettingPropertyChanged(shared_from_base<CSettingString>(), "options");
}

return options;
Expand Down
8 changes: 7 additions & 1 deletion xbmc/settings/lib/Setting.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ typedef std::vector<std::shared_ptr<CSetting>> SettingList;
*/
class CSetting : public ISetting,
protected ISettingCallback,
protected std::enable_shared_from_this<CSetting>
public std::enable_shared_from_this<CSetting>
{
public:
CSetting(const std::string &id, CSettingsManager *settingsManager = NULL);
Expand Down Expand Up @@ -132,6 +132,12 @@ class CSetting : public ISetting,

void Copy(const CSetting &setting);

template<class TSetting>
std::shared_ptr<TSetting> shared_from_base()
{
return std::static_pointer_cast<TSetting>(shared_from_this());
}

ISettingCallback *m_callback;
int m_label;
int m_help;
Expand Down
1 change: 1 addition & 0 deletions xbmc/settings/lib/SettingDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*
*/

#include <memory>
#include <string>
#include <utility>
#include <vector>
Expand Down
1 change: 1 addition & 0 deletions xbmc/settings/windows/GUIControlSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <stdlib.h>
#include <functional>
#include <memory>
#include <string>

#include "guilib/ISliderCallback.h"
Expand Down
14 changes: 7 additions & 7 deletions xbmc/video/dialogs/GUIDialogCMSSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,21 @@ void CGUIDialogCMSSettings::OnSettingChanged(std::shared_ptr<const CSetting> set

const std::string &settingId = setting->GetId();
if (settingId == SETTING_VIDEO_CMSENABLE)
CServiceBroker::GetSettings().SetBool(SETTING_VIDEO_CMSENABLE, (std::static_pointer_cast<CSettingBool>(setting)->GetValue()));
CServiceBroker::GetSettings().SetBool(SETTING_VIDEO_CMSENABLE, (std::static_pointer_cast<const CSettingBool>(setting)->GetValue()));
else if (settingId == SETTING_VIDEO_CMSMODE)
CServiceBroker::GetSettings().SetInt(SETTING_VIDEO_CMSMODE, static_cast<int>(std::static_pointer_cast<CSettingInt>(setting)->GetValue()));
CServiceBroker::GetSettings().SetInt(SETTING_VIDEO_CMSMODE, static_cast<int>(std::static_pointer_cast<const CSettingInt>(setting)->GetValue()));
else if (settingId == SETTING_VIDEO_CMS3DLUT)
CServiceBroker::GetSettings().SetString(SETTING_VIDEO_CMS3DLUT, static_cast<std::string>(std::static_pointer_cast<const CSettingString>(setting)->GetValue()));
else if (settingId == SETTING_VIDEO_CMSWHITEPOINT)
CServiceBroker::GetSettings().SetInt(SETTING_VIDEO_CMSWHITEPOINT, static_cast<int>(std::static_pointer_cast<CSettingInt>(setting)->GetValue()));
CServiceBroker::GetSettings().SetInt(SETTING_VIDEO_CMSWHITEPOINT, static_cast<int>(std::static_pointer_cast<const CSettingInt>(setting)->GetValue()));
else if (settingId == SETTING_VIDEO_CMSPRIMARIES)
CServiceBroker::GetSettings().SetInt(SETTING_VIDEO_CMSPRIMARIES, static_cast<int>(std::static_pointer_cast<CSettingInt>(setting)->GetValue()));
CServiceBroker::GetSettings().SetInt(SETTING_VIDEO_CMSPRIMARIES, static_cast<int>(std::static_pointer_cast<const CSettingInt>(setting)->GetValue()));
else if (settingId == SETTING_VIDEO_CMSGAMMAMODE)
CServiceBroker::GetSettings().SetInt(SETTING_VIDEO_CMSGAMMAMODE, static_cast<int>(std::static_pointer_cast<CSettingInt>(setting)->GetValue()));
CServiceBroker::GetSettings().SetInt(SETTING_VIDEO_CMSGAMMAMODE, static_cast<int>(std::static_pointer_cast<const CSettingInt>(setting)->GetValue()));
else if (settingId == SETTING_VIDEO_CMSGAMMA)
CServiceBroker::GetSettings().SetInt(SETTING_VIDEO_CMSGAMMA, static_cast<float>(std::static_pointer_cast<CSettingNumber>(setting)->GetValue())*100);
CServiceBroker::GetSettings().SetInt(SETTING_VIDEO_CMSGAMMA, static_cast<float>(std::static_pointer_cast<const CSettingNumber>(setting)->GetValue())*100);
else if (settingId == SETTING_VIDEO_CMSLUTSIZE)
CServiceBroker::GetSettings().SetInt(SETTING_VIDEO_CMSLUTSIZE, static_cast<int>(std::static_pointer_cast<CSettingInt>(setting)->GetValue()));
CServiceBroker::GetSettings().SetInt(SETTING_VIDEO_CMSLUTSIZE, static_cast<int>(std::static_pointer_cast<const CSettingInt>(setting)->GetValue()));
}

bool CGUIDialogCMSSettings::OnBack(int actionID)
Expand Down

0 comments on commit 3021828

Please sign in to comment.