refactor: Use unique_ptr for memory management

This commit is contained in:
Colin Wallace
2018-03-09 23:03:19 -08:00
parent d2c370a953
commit fd871e46c9
10 changed files with 141 additions and 127 deletions

View File

@@ -25,6 +25,7 @@
#ifndef AUDIO_PORT_H
#define AUDIO_PORT_H
#include <memory>
#include <QtCore/QString>
#include <QtCore/QMutex>
#include <QtCore/QMutexLocker>
@@ -79,7 +80,7 @@ public:
inline EffectChain * effects()
{
return m_effects;
return m_effects.get();
}
void setNextFxChannel( const fx_ch_t _chnl )
@@ -119,7 +120,7 @@ private:
QString m_name;
EffectChain * m_effects;
std::unique_ptr<EffectChain> m_effects;
PlayHandleList m_playHandles;
QMutex m_playHandleLock;

View File

@@ -25,12 +25,12 @@
#ifndef COMBOBOX_MODEL_H
#define COMBOBOX_MODEL_H
#include <QtCore/QVector>
#include <QtCore/QPair>
#include <memory>
#include <utility>
#include <vector>
#include "AutomatableModel.h"
class PixmapLoader;
#include "embed.h"
class EXPORT ComboBoxModel : public IntModel
@@ -49,7 +49,7 @@ public:
clear();
}
void addItem( const QString& item, PixmapLoader* loader = NULL );
void addItem( const QString& item, std::unique_ptr<PixmapLoader> loader = nullptr );
void clear();
@@ -62,7 +62,7 @@ public:
const PixmapLoader* currentData() const
{
return m_items[value()].second;
return m_items[value()].second.get();
}
const QString & itemText( int i ) const
@@ -72,7 +72,7 @@ public:
const PixmapLoader* itemPixmap( int i ) const
{
return m_items[qBound<int>( minValue(), i, maxValue() )].second;
return m_items[qBound<int>( minValue(), i, maxValue() )].second.get();
}
int size() const
@@ -82,9 +82,9 @@ public:
private:
typedef QPair<QString, PixmapLoader *> Item;
typedef std::pair<QString, std::unique_ptr<PixmapLoader> > Item;
QVector<Item> m_items;
std::vector<Item> m_items;
} ;

12
include/stdshims.h Normal file
View File

@@ -0,0 +1,12 @@
//! Shims for std:: functions that aren't available in the current C++ versions
//! we target.
#pragma once
/// Shim for http://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}