use unique_ptr in SettingChanges

This commit is contained in:
Hannes Janetzek 2015-07-03 15:22:56 +02:00
parent e32999b599
commit a7c6cdcbc1
2 changed files with 8 additions and 9 deletions

View File

@ -127,7 +127,10 @@ void EmitterState::StartedGroup(GroupType::value type) {
std::unique_ptr<Group> pGroup(new Group(type)); std::unique_ptr<Group> pGroup(new Group(type));
// transfer settings (which last until this group is done) // transfer settings (which last until this group is done)
pGroup->modifiedSettings = m_modifiedSettings; //
// NB: if pGroup->modifiedSettings == m_modifiedSettings,
// m_modifiedSettings is not changed!
pGroup->modifiedSettings = std::move(m_modifiedSettings);
// set up group // set up group
if (GetFlowType(type) == Block) if (GetFlowType(type) == Block)

View File

@ -62,10 +62,6 @@ class SettingChanges : private noncopyable {
void clear() { void clear() {
restore(); restore();
for (setting_changes::const_iterator it = m_settingChanges.begin();
it != m_settingChanges.end(); ++it)
delete *it;
m_settingChanges.clear(); m_settingChanges.clear();
} }
@ -76,22 +72,22 @@ class SettingChanges : private noncopyable {
} }
void push(std::unique_ptr<SettingChangeBase> pSettingChange) { void push(std::unique_ptr<SettingChangeBase> pSettingChange) {
m_settingChanges.push_back(pSettingChange.release()); m_settingChanges.push_back(std::move(pSettingChange));
} }
// like std::unique_ptr - assignment is transfer of ownership // like std::unique_ptr - assignment is transfer of ownership
SettingChanges& operator=(SettingChanges& rhs) { SettingChanges& operator=(SettingChanges&& rhs) {
if (this == &rhs) if (this == &rhs)
return *this; return *this;
clear(); clear();
m_settingChanges = rhs.m_settingChanges; m_settingChanges = std::move(rhs.m_settingChanges);
rhs.m_settingChanges.clear(); rhs.m_settingChanges.clear();
return *this; return *this;
} }
private: private:
typedef std::vector<SettingChangeBase*> setting_changes; typedef std::vector<std::unique_ptr<SettingChangeBase>> setting_changes;
setting_changes m_settingChanges; setting_changes m_settingChanges;
}; };
} }