Use more make_unique

This commit is contained in:
Thomas Goyne 2014-04-22 16:34:18 -07:00
parent c53e8f6139
commit feec511227
12 changed files with 25 additions and 27 deletions

View file

@ -38,6 +38,7 @@
#include "utils.h" #include "utils.h"
#include <libaegisub/color.h> #include <libaegisub/color.h>
#include <libaegisub/util.h>
#include <boost/algorithm/string/join.hpp> #include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/predicate.hpp>
@ -113,7 +114,7 @@ template<> agi::Color AssOverrideParameter::Get<agi::Color>() const {
template<> AssDialogueBlockOverride *AssOverrideParameter::Get<AssDialogueBlockOverride*>() const { template<> AssDialogueBlockOverride *AssOverrideParameter::Get<AssDialogueBlockOverride*>() const {
if (!block.get()) { if (!block.get()) {
block.reset(new AssDialogueBlockOverride(Get<std::string>())); block = agi::util::make_unique<AssDialogueBlockOverride>(Get<std::string>());
block->ParseTags(); block->ParseTags();
} }
return block.get(); return block.get();

View file

@ -21,6 +21,8 @@
#include "ass_style.h" #include "ass_style.h"
#include "subtitle_format.h" #include "subtitle_format.h"
#include <libaegisub/util.h>
#include <algorithm> #include <algorithm>
#include <boost/algorithm/string/case_conv.hpp> #include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/predicate.hpp>
@ -103,12 +105,12 @@ void AssParser::ParseStyleLine(std::string const& data) {
void AssParser::ParseFontLine(std::string const& data) { void AssParser::ParseFontLine(std::string const& data) {
if (boost::starts_with(data, "fontname: ")) if (boost::starts_with(data, "fontname: "))
attach.reset(new AssAttachment(data, AssEntryGroup::FONT)); attach = agi::util::make_unique<AssAttachment>(data, AssEntryGroup::FONT);
} }
void AssParser::ParseGraphicsLine(std::string const& data) { void AssParser::ParseGraphicsLine(std::string const& data) {
if (boost::starts_with(data, "filename: ")) if (boost::starts_with(data, "filename: "))
attach.reset(new AssAttachment(data, AssEntryGroup::GRAPHIC)); attach = agi::util::make_unique<AssAttachment>(data, AssEntryGroup::GRAPHIC);
} }
void AssParser::AddLine(std::string const& data) { void AssParser::AddLine(std::string const& data) {

View file

@ -168,17 +168,9 @@ void AudioController::OpenAudio(agi::fs::path const& url)
} }
CloseAudio(); CloseAudio();
provider = std::move(new_provider);
try player = AudioPlayerFactory::GetAudioPlayer(new_provider.get(), context->parent);
{ provider = std::move(new_provider);
player = AudioPlayerFactory::GetAudioPlayer(provider.get(), context->parent);
}
catch (...)
{
provider.reset();
throw;
}
audio_url = url; audio_url = url;

View file

@ -186,7 +186,7 @@ namespace Automation4 {
} }
wxWindow* ExportFilter::GetConfigDialogWindow(wxWindow *parent, agi::Context *c) { wxWindow* ExportFilter::GetConfigDialogWindow(wxWindow *parent, agi::Context *c) {
config_dialog.reset(GenerateConfigDialog(parent, c)); config_dialog = GenerateConfigDialog(parent, c);
if (config_dialog) { if (config_dialog) {
std::string val = c->ass->GetScriptInfo(GetScriptSettingsIdentifier()); std::string val = c->ass->GetScriptInfo(GetScriptSettingsIdentifier());

View file

@ -71,7 +71,7 @@ namespace Automation4 {
std::unique_ptr<ScriptDialog> config_dialog; std::unique_ptr<ScriptDialog> config_dialog;
/// subclasses should implement this, producing a new ScriptDialog /// subclasses should implement this, producing a new ScriptDialog
virtual ScriptDialog* GenerateConfigDialog(wxWindow *parent, agi::Context *c) = 0; virtual std::unique_ptr<ScriptDialog> GenerateConfigDialog(wxWindow *parent, agi::Context *c) = 0;
protected: protected:
std::string GetScriptSettingsIdentifier(); std::string GetScriptSettingsIdentifier();

View file

@ -1093,7 +1093,7 @@ namespace Automation4 {
} }
} }
ScriptDialog* LuaExportFilter::GenerateConfigDialog(wxWindow *parent, agi::Context *c) std::unique_ptr<ScriptDialog> LuaExportFilter::GenerateConfigDialog(wxWindow *parent, agi::Context *c)
{ {
if (!has_config) if (!has_config)
return nullptr; return nullptr;
@ -1119,7 +1119,7 @@ namespace Automation4 {
config_dialog = new LuaDialog(L, false); config_dialog = new LuaDialog(L, false);
} }
return config_dialog; return std::unique_ptr<ScriptDialog>{config_dialog};
} }
LuaScriptFactory::LuaScriptFactory() LuaScriptFactory::LuaScriptFactory()

View file

@ -279,7 +279,7 @@ namespace Automation4 {
LuaDialog *config_dialog; LuaDialog *config_dialog;
protected: protected:
ScriptDialog* GenerateConfigDialog(wxWindow *parent, agi::Context *c) override; std::unique_ptr<ScriptDialog> GenerateConfigDialog(wxWindow *parent, agi::Context *c) override;
public: public:
LuaExportFilter(lua_State *L); LuaExportFilter(lua_State *L);

View file

@ -38,6 +38,7 @@
#include <libaegisub/dispatch.h> #include <libaegisub/dispatch.h>
#include <libaegisub/fs.h> #include <libaegisub/fs.h>
#include <libaegisub/path.h> #include <libaegisub/path.h>
#include <libaegisub/util.h>
#include <wx/button.h> #include <wx/button.h>
#include <wx/dirdlg.h> #include <wx/dirdlg.h>
@ -110,9 +111,9 @@ void FontsCollectorThread(AssFile *subs, agi::fs::path const& destination, FcMod
return; return;
} }
out.reset(new wxFFileOutputStream(destination.wstring())); out = agi::util::make_unique<wxFFileOutputStream>(destination.wstring());
if (out->IsOk()) if (out->IsOk())
zip.reset(new wxZipOutputStream(*out)); zip = agi::util::make_unique<wxZipOutputStream>(*out);
if (!out->IsOk() || !zip || !zip->IsOk()) { if (!out->IsOk() || !zip || !zip->IsOk()) {
AppendText(wxString::Format(_("* Failed to open %s.\n"), destination.wstring()), 2); AppendText(wxString::Format(_("* Failed to open %s.\n"), destination.wstring()), 2);

View file

@ -29,6 +29,7 @@
#include <libaegisub/line_iterator.h> #include <libaegisub/line_iterator.h>
#include <libaegisub/log.h> #include <libaegisub/log.h>
#include <libaegisub/path.h> #include <libaegisub/path.h>
#include <libaegisub/util.h>
#include <boost/format.hpp> #include <boost/format.hpp>
#include <boost/range/algorithm.hpp> #include <boost/range/algorithm.hpp>
@ -197,11 +198,11 @@ void HunspellSpellChecker::OnLanguageChanged() {
LOG_I("dictionary/file") << dic; LOG_I("dictionary/file") << dic;
hunspell.reset(new Hunspell(agi::fs::ShortName(aff).c_str(), agi::fs::ShortName(dic).c_str())); hunspell = agi::util::make_unique<Hunspell>(agi::fs::ShortName(aff).c_str(), agi::fs::ShortName(dic).c_str());
if (!hunspell) return; if (!hunspell) return;
conv.reset(new agi::charset::IconvWrapper("utf-8", hunspell->get_dic_encoding())); conv = agi::util::make_unique<agi::charset::IconvWrapper>("utf-8", hunspell->get_dic_encoding());
rconv.reset(new agi::charset::IconvWrapper(hunspell->get_dic_encoding(), "utf-8")); rconv = agi::util::make_unique<agi::charset::IconvWrapper>(hunspell->get_dic_encoding(), "utf-8");
userDicPath = config::path->Decode("?user/dictionaries")/str(boost::format("user_%s.dic") % language); userDicPath = config::path->Decode("?user/dictionaries")/str(boost::format("user_%s.dic") % language);
ReadUserDictionary(); ReadUserDictionary();

View file

@ -93,7 +93,7 @@ void SubtitlesPreview::SetText(std::string const& text) {
void SubtitlesPreview::SetColour(agi::Color col) { void SubtitlesPreview::SetColour(agi::Color col) {
if (col != back_color) { if (col != back_color) {
back_color = col; back_color = col;
vid.reset(new DummyVideoProvider(0.0, 10, bmp->GetWidth(), bmp->GetHeight(), back_color, true)); vid = agi::util::make_unique<DummyVideoProvider>(0.0, 10, bmp->GetWidth(), bmp->GetHeight(), back_color, true);
UpdateBitmap(); UpdateBitmap();
} }
} }
@ -127,7 +127,7 @@ void SubtitlesPreview::OnSize(wxSizeEvent &evt) {
int h = evt.GetSize().GetHeight(); int h = evt.GetSize().GetHeight();
bmp = agi::util::make_unique<wxBitmap>(w, h, -1); bmp = agi::util::make_unique<wxBitmap>(w, h, -1);
vid.reset(new DummyVideoProvider(0.0, 10, w, h, back_color, true)); vid = agi::util::make_unique<DummyVideoProvider>(0.0, 10, w, h, back_color, true);
try { try {
if (!progress) if (!progress)
progress = agi::util::make_unique<DialogProgress>(this); progress = agi::util::make_unique<DialogProgress>(this);

View file

@ -25,6 +25,7 @@
#include <libaegisub/io.h> #include <libaegisub/io.h>
#include <libaegisub/charset_conv.h> #include <libaegisub/charset_conv.h>
#include <libaegisub/util.h>
#include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
@ -36,7 +37,7 @@ TextFileWriter::TextFileWriter(agi::fs::path const& filename, std::string encodi
if (encoding.empty()) if (encoding.empty())
encoding = OPT_GET("App/Save Charset")->GetString(); encoding = OPT_GET("App/Save Charset")->GetString();
if (boost::iequals(encoding, "utf-8")) if (boost::iequals(encoding, "utf-8"))
conv.reset(new agi::charset::IconvWrapper("utf-8", encoding.c_str(), true)); conv = agi::util::make_unique<agi::charset::IconvWrapper>("utf-8", encoding.c_str(), true);
try { try {
// Write the BOM // Write the BOM

View file

@ -117,7 +117,7 @@ void VideoContext::SetVideo(const agi::fs::path &filename) {
if (!progress) if (!progress)
progress = new DialogProgress(context->parent); progress = new DialogProgress(context->parent);
auto old_matrix = context->ass->GetScriptInfo("YCbCr Matrix"); auto old_matrix = context->ass->GetScriptInfo("YCbCr Matrix");
provider.reset(new ThreadedFrameSource(filename, old_matrix, this, progress)); provider = agi::util::make_unique<ThreadedFrameSource>(filename, old_matrix, this, progress);
video_provider = provider->GetVideoProvider(); video_provider = provider->GetVideoProvider();
video_filename = filename; video_filename = filename;