Kill scoped_ptr in favor of unique_ptr

This commit is contained in:
Thomas Goyne 2013-06-10 06:58:13 -07:00
parent 9133f17e82
commit 72d4577d7d
43 changed files with 191 additions and 224 deletions

View file

@ -17,6 +17,7 @@
/// @ingroup libaegisub
#include <libaegisub/charset_conv.h>
#include <memory>
namespace agi { namespace charset {
@ -26,7 +27,7 @@ namespace agi { namespace charset {
/// it's not used by anything but old subtitle formats
class Converter6937 : public Converter {
/// Converter to UCS-4 so that we only have to deal with unicode codepoints
agi::scoped_ptr<IconvWrapper> to_ucs4;
std::unique_ptr<IconvWrapper> to_ucs4;
/// Should unsupported characters be replaced with '?'
const bool subst;

View file

@ -118,7 +118,7 @@ namespace {
size_t nul_size(const char* encoding) {
// We need a character set to convert from with a known encoding of NUL
// UTF-8 seems like the obvious choice
agi::scoped_ptr<agi::charset::Converter> cd(get_converter(false, "UTF-8", encoding));
std::unique_ptr<agi::charset::Converter> cd(get_converter(false, "UTF-8", encoding));
char dbuff[4];
char sbuff[] = "";

View file

@ -78,9 +78,6 @@ Options::Options(agi::fs::path const& file, const std::string& default_config, c
Options::~Options() {
if ((setting & FLUSH_SKIP) != FLUSH_SKIP)
Flush();
for (auto option_value : values | boost::adaptors::map_values)
delete option_value;
}
void Options::ConfigNext(std::istream& stream) {
@ -117,7 +114,7 @@ void Options::LoadConfig(std::istream& stream, bool ignore_errors) {
OptionValue* Options::Get(const std::string &name) {
auto index = values.find(name);
if (index != values.end())
return index->second;
return index->second.get();
LOG_E("option/get") << "agi::Options::Get Option not found: (" << name << ")";
throw OptionErrorNotFound("Option value not found: " + name);

View file

@ -27,7 +27,7 @@
#include <libaegisub/color.h>
#include <libaegisub/log.h>
#include <libaegisub/option_value.h>
#include <libaegisub/scoped_ptr.h>
#include <libaegisub/util.h>
#include <boost/algorithm/string/predicate.hpp>
@ -60,7 +60,7 @@ void ConfigVisitor::Visit(const json::Object& object) {
}
template<class OptionValueType, class ValueType>
OptionValue *ConfigVisitor::ReadArray(json::Array const& src, std::string const& array_type, void (OptionValueType::*)(const std::vector<ValueType>&)) {
std::unique_ptr<OptionValue> ConfigVisitor::ReadArray(json::Array const& src, std::string const& array_type, void (OptionValueType::*)(const std::vector<ValueType>&)) {
std::vector<ValueType> arr;
arr.reserve(src.size());
@ -77,7 +77,7 @@ OptionValue *ConfigVisitor::ReadArray(json::Array const& src, std::string const&
arr.push_back(ValueType(obj.begin()->second));
}
return new OptionValueType(name, arr);
return util::make_unique<OptionValueType>(name, arr);
}
void ConfigVisitor::Visit(const json::Array& array) {
@ -109,11 +109,11 @@ void ConfigVisitor::Visit(const json::Array& array) {
}
void ConfigVisitor::Visit(const json::Integer& number) {
AddOptionValue(new OptionValueInt(name, number));
AddOptionValue(util::make_unique<OptionValueInt>(name, number));
}
void ConfigVisitor::Visit(const json::Double& number) {
AddOptionValue(new OptionValueDouble(name, number));
AddOptionValue(util::make_unique<OptionValueDouble>(name, number));
}
void ConfigVisitor::Visit(const json::String& string) {
@ -123,39 +123,34 @@ void ConfigVisitor::Visit(const json::String& string) {
(size >= 10 && boost::starts_with(string, "rgb(")) ||
((size == 9 || size == 10) && boost::starts_with(string, "&H")))
{
AddOptionValue(new OptionValueColor(name, string));
AddOptionValue(util::make_unique<OptionValueColor>(name, string));
} else {
AddOptionValue(new OptionValueString(name, string));
AddOptionValue(util::make_unique<OptionValueString>(name, string));
}
}
void ConfigVisitor::Visit(const json::Boolean& boolean) {
AddOptionValue(new OptionValueBool(name, boolean));
AddOptionValue(util::make_unique<OptionValueBool>(name, boolean));
}
void ConfigVisitor::Visit(const json::Null& null) {
Error<OptionJsonValueNull>("Attempt to read null value");
}
void ConfigVisitor::AddOptionValue(OptionValue* opt) {
void ConfigVisitor::AddOptionValue(std::unique_ptr<OptionValue>&& opt) {
if (!opt) {
assert(ignore_errors);
return;
}
OptionValueMap::iterator it = values.find(name);
auto it = values.find(name);
if (it == values.end())
values[name] = opt;
else if (replace) {
delete it->second;
it->second = opt;
}
values[name] = std::move(opt);
else if (replace)
it->second = std::move(opt);
else {
try {
// Ensure than opt is deleted at the end of this function even if the Set
// method throws
agi::scoped_ptr<OptionValue> auto_opt(opt);
values[name]->Set(opt);
values[name]->Set(opt.get());
}
catch (agi::OptionValueError const& e) {
if (ignore_errors)

View file

@ -21,6 +21,7 @@
#include "libaegisub/cajun/elements.h"
#include "libaegisub/cajun/visitor.h"
#include <memory>
#include <vector>
namespace agi {
@ -46,9 +47,9 @@ class ConfigVisitor : public json::ConstVisitor {
void Error(const char *message);
template<class OptionValueType, class ValueType>
OptionValue *ReadArray(json::Array const& src, std::string const& array_type, void (OptionValueType::*set_list)(const std::vector<ValueType>&));
std::unique_ptr<OptionValue> ReadArray(json::Array const& src, std::string const& array_type, void (OptionValueType::*set_list)(const std::vector<ValueType>&));
void AddOptionValue(OptionValue* opt);
void AddOptionValue(std::unique_ptr<OptionValue>&& opt);
public:
ConfigVisitor(OptionValueMap &val, const std::string &member_name, bool ignore_errors = false, bool replace = false);

View file

@ -19,11 +19,11 @@
#pragma once
#include <cstring>
#include <memory>
#include <string>
#include <vector>
#include <libaegisub/exception.h>
#include <libaegisub/scoped_ptr.h>
namespace agi {
namespace charset {
@ -48,7 +48,7 @@ struct Converter {
class IconvWrapper {
size_t toNulLen;
size_t fromNulLen;
agi::scoped_ptr<Converter> conv;
std::unique_ptr<Converter> conv;
public:
/// @brief Create a converter

View file

@ -21,6 +21,7 @@
#include <boost/filesystem/path.hpp>
#include <iosfwd>
#include <map>
#include <memory>
#include <libaegisub/exception.h>
#include <libaegisub/fs_fwd.h>
@ -38,10 +39,7 @@ DEFINE_SIMPLE_EXCEPTION_NOINNER(OptionErrorDuplicateKey, OptionError, "options/d
class OptionValue;
/// This is a cool trick: make a class un-copyable, in this case we always want
/// to update our *original* map, this will ensure that it is always updated in
/// every situation.
class OptionValueMap : public std::map<std::string,OptionValue*> {
class OptionValueMap : public std::map<std::string, std::unique_ptr<OptionValue>> {
private:
OptionValueMap(const OptionValueMap& x);
OptionValueMap& operator=(const OptionValueMap& x);

View file

@ -19,33 +19,6 @@
#pragma once
namespace agi {
/// @class scoped_ptr
/// @brief auto_ptr without the transfer of ownership semantics
template<class T>
class scoped_ptr {
T* ptr;
scoped_ptr(scoped_ptr const&);
scoped_ptr& operator=(scoped_ptr const&);
typedef T *scoped_ptr<T>::*unspecified_bool_type;
public:
typedef T element_type;
T& operator*() const {return *ptr; }
T* operator->() const { return ptr; }
T* get() const { return ptr; }
operator unspecified_bool_type() const { return ptr ? &scoped_ptr<T>::ptr : 0; }
void reset(T *p = 0) {
delete ptr;
ptr = p;
}
explicit scoped_ptr(T *ptr = 0) : ptr(ptr){ }
~scoped_ptr() { delete ptr; }
};
/// A generic scoped holder for non-pointer handles
template<class T, class Del = void(*)(T)>
class scoped_holder {
@ -73,5 +46,4 @@ public:
~scoped_holder() { if (value) destructor(value); }
};
}

View file

@ -19,9 +19,9 @@
/// @ingroup audio_ui
///
#include <libaegisub/scoped_ptr.h>
#include <libaegisub/signal.h>
#include <memory>
#include <set>
#include <unordered_map>
#include <vector>
@ -78,7 +78,7 @@ class AudioKaraoke : public wxWindow {
/// Currently active dialogue line
AssDialogue *active_line;
/// Karaoke data
agi::scoped_ptr<AssKaraoke> kara;
std::unique_ptr<AssKaraoke> kara;
/// Current line's stripped text with spaces added between each syllable
std::vector<wxString> spaced_text;

View file

@ -33,17 +33,15 @@
///
#ifdef WITH_ALSA
#include <alsa/asoundlib.h>
#include "include/aegisub/audio_player.h"
#include <libaegisub/scoped_ptr.h>
#include <alsa/asoundlib.h>
#include <memory>
struct PlaybackState;
class AlsaPlayer : public AudioPlayer {
agi::scoped_ptr<PlaybackState> ps;
std::unique_ptr<PlaybackState> ps;
pthread_t thread;
public:

View file

@ -44,6 +44,7 @@
#include "utils.h"
#include <libaegisub/log.h>
#include <libaegisub/util.h>
#include <algorithm>
@ -138,7 +139,7 @@ void AudioSpectrumRenderer::RecreateCache()
if (provider)
{
size_t block_count = (size_t)((provider->GetNumSamples() + (size_t)(1<<derivation_dist) - 1) >> derivation_dist);
cache.reset(new AudioSpectrumCache(block_count, this));
cache = agi::util::make_unique<AudioSpectrumCache>(block_count, this);
#ifdef WITH_FFTW3
dft_input = fftw_alloc_real(2<<derivation_size);

View file

@ -34,12 +34,11 @@
/// Calculate and render a frequency-power spectrum for PCM audio data.
#include <cstdint>
#include <memory>
#include <vector>
#include "audio_renderer.h"
#include <libaegisub/scoped_ptr.h>
#ifdef WITH_FFTW3
#include <fftw3.h>
#endif
@ -57,7 +56,7 @@ class AudioSpectrumRenderer : public AudioRendererBitmapProvider {
friend struct AudioSpectrumCacheBlockFactory;
/// Internal cache management for the spectrum
agi::scoped_ptr<AudioSpectrumCache> cache;
std::unique_ptr<AudioSpectrumCache> cache;
/// Colour tables used for rendering
std::vector<AudioColorScheme> colors;

View file

@ -108,7 +108,7 @@ namespace Automation4 {
/// makes a Lua representation of AssEntry and places on the top of the stack
static void AssEntryToLua(lua_State *L, AssEntry *e);
/// assumes a Lua representation of AssEntry on the top of the stack, and creates an AssEntry object of it
static AssEntry *LuaToAssEntry(lua_State *L);
static std::unique_ptr<AssEntry> LuaToAssEntry(lua_State *L);
/// @brief Signal that the script using this file is now done running
/// @param set_undo If there's any uncommitted changes to the file,
@ -186,7 +186,7 @@ namespace Automation4 {
/// A lua-generated dialog or panel in the export options dialog
class LuaDialog : public ScriptDialog {
/// Controls in this dialog
std::vector<LuaDialogControl*> controls;
std::vector<std::unique_ptr<LuaDialogControl>> controls;
/// The names and IDs of buttons in this dialog if non-default ones were used
std::vector<std::pair<int, std::string>> buttons;
@ -200,7 +200,6 @@ namespace Automation4 {
public:
LuaDialog(lua_State *L, bool include_buttons);
~LuaDialog();
/// Push the values of the controls in this dialog onto the lua stack
/// in a single table

View file

@ -45,13 +45,14 @@
#include "utils.h"
#include <libaegisub/exception.h>
#include <libaegisub/scoped_ptr.h>
#include <libaegisub/util.h>
#include <algorithm>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/range/adaptor/indirected.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <cassert>
#include <memory>
namespace {
DEFINE_SIMPLE_EXCEPTION_NOINNER(BadField, Automation4::MacroRunError, "automation/macro/bad_field")
@ -219,7 +220,7 @@ namespace Automation4 {
}
}
AssEntry *LuaAssFile::LuaToAssEntry(lua_State *L)
std::unique_ptr<AssEntry> LuaAssFile::LuaToAssEntry(lua_State *L)
{
// assume an assentry table is on the top of the stack
// convert it to a real AssEntry object, and pop the table from the stack
@ -235,14 +236,14 @@ namespace Automation4 {
boost::to_lower(lclass);
lua_pop(L, 1);
AssEntry *result = 0;
std::unique_ptr<AssEntry> result;
try {
if (lclass == "info")
result = new AssInfo(get_string_field(L, "key", "info"), get_string_field(L, "value", "info"));
result = agi::util::make_unique<AssInfo>(get_string_field(L, "key", "info"), get_string_field(L, "value", "info"));
else if (lclass == "style") {
AssStyle *sty = new AssStyle;
result = sty;
result.reset(sty);
sty->name = get_string_field(L, "name", "style");
sty->font = get_string_field(L, "fontname", "style");
sty->fontsize = get_double_field(L, "fontsize", "style");
@ -270,7 +271,7 @@ namespace Automation4 {
}
else if (lclass == "dialogue") {
AssDialogue *dia = new AssDialogue;
result = dia;
result.reset(dia);
dia->Comment = get_bool_field(L, "comment", "dialogue");
dia->Layer = get_int_field(L, "layer", "dialogue");
@ -292,9 +293,8 @@ namespace Automation4 {
return result;
}
catch (agi::Exception const& e) {
delete result;
luaL_error(L, e.GetMessage().c_str());
return 0;
return nullptr;
}
}
@ -373,11 +373,11 @@ namespace Automation4 {
// replace line at index n or delete
if (!lua_isnil(L, 3)) {
// insert
AssEntry *e = LuaToAssEntry(L);
modification_type |= modification_mask(e);
auto e = LuaToAssEntry(L);
modification_type |= modification_mask(e.get());
CheckBounds(n);
lines_to_delete.push_back(lines[n - 1]);
lines[n - 1] = e;
lines[n - 1] = e.release();
}
else {
// delete
@ -453,8 +453,8 @@ namespace Automation4 {
for (int i = 1; i <= n; i++) {
lua_pushvalue(L, i);
AssEntry *e = LuaToAssEntry(L);
modification_type |= modification_mask(e);
auto e = LuaToAssEntry(L);
modification_type |= modification_mask(e.get());
// Find the appropriate place to put it
auto it = lines.end();
@ -468,11 +468,11 @@ namespace Automation4 {
if (it == lines.end() || (*it)->Group() != e->Group()) {
// The new entry belongs to a group that doesn't exist yet, so
// create it at the end of the file
lines.push_back(e);
lines.push_back(e.release());
}
else {
// Append the entry to the end of the existing group
lines.insert(++it, e);
lines.insert(++it, e.release());
}
}
}
@ -497,9 +497,9 @@ namespace Automation4 {
std::vector<AssEntry *> new_entries(n - 1, nullptr);
for (int i = 2; i <= n; i++) {
lua_pushvalue(L, i);
AssEntry *e = LuaToAssEntry(L);
modification_type |= modification_mask(e);
new_entries[i - 2] = e;
auto e = LuaToAssEntry(L);
modification_type |= modification_mask(e.get());
new_entries[i - 2] = e.release();
lua_pop(L, 1);
}
lines.insert(lines.begin() + before - 1, new_entries.begin(), new_entries.end());
@ -536,7 +536,7 @@ namespace Automation4 {
int LuaAssFile::LuaParseKaraokeData(lua_State *L)
{
agi::scoped_ptr<AssEntry> e(LuaToAssEntry(L));
auto e = LuaToAssEntry(L);
AssDialogue *dia = dynamic_cast<AssDialogue*>(e.get());
luaL_argcheck(L, dia, 1, "Subtitle line must be a dialogue line");

View file

@ -44,6 +44,8 @@
#include "utils.h"
#include "validators.h"
#include <libaegisub/util.h>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
@ -432,34 +434,34 @@ namespace Automation4 {
std::string controlclass = get_field(L, "class");
boost::to_lower(controlclass);
LuaDialogControl *ctl;
std::unique_ptr<LuaDialogControl> ctl;
// Check control class and create relevant control
if (controlclass == "label")
ctl = new LuaControl::Label(L);
ctl = agi::util::make_unique<LuaControl::Label>(L);
else if (controlclass == "edit")
ctl = new LuaControl::Edit(L);
ctl = agi::util::make_unique<LuaControl::Edit>(L);
else if (controlclass == "intedit")
ctl = new LuaControl::IntEdit(L);
ctl = agi::util::make_unique<LuaControl::IntEdit>(L);
else if (controlclass == "floatedit")
ctl = new LuaControl::FloatEdit(L);
ctl = agi::util::make_unique<LuaControl::FloatEdit>(L);
else if (controlclass == "textbox")
ctl = new LuaControl::Textbox(L);
ctl = agi::util::make_unique<LuaControl::Textbox>(L);
else if (controlclass == "dropdown")
ctl = new LuaControl::Dropdown(L);
ctl = agi::util::make_unique<LuaControl::Dropdown>(L);
else if (controlclass == "checkbox")
ctl = new LuaControl::Checkbox(L);
ctl = agi::util::make_unique<LuaControl::Checkbox>(L);
else if (controlclass == "color")
ctl = new LuaControl::Color(L, false);
ctl = agi::util::make_unique<LuaControl::Color>(L, false);
else if (controlclass == "coloralpha")
ctl = new LuaControl::Color(L, true);
ctl = agi::util::make_unique<LuaControl::Color>(L, true);
else if (controlclass == "alpha")
// FIXME
ctl = new LuaControl::Edit(L);
ctl = agi::util::make_unique<LuaControl::Edit>(L);
else
luaL_error(L, "bad control table entry");
controls.push_back(ctl);
controls.emplace_back(std::move(ctl));
});
if (include_buttons && lua_istable(L, 2)) {
@ -483,15 +485,11 @@ namespace Automation4 {
}
}
LuaDialog::~LuaDialog() {
delete_clear(controls);
}
wxWindow* LuaDialog::CreateWindow(wxWindow *parent) {
window = new wxPanel(parent);
auto s = new wxGridBagSizer(4, 4);
for (auto c : controls)
for (auto& c : controls)
s->Add(c->Create(window), wxGBPosition(c->y, c->x),
wxGBSpan(c->height, c->width), c->GetSizerFlags());
@ -556,7 +554,7 @@ namespace Automation4 {
// Then read controls back
lua_newtable(L);
for (auto control : controls) {
for (auto& control : controls) {
control->LuaReadBack(L);
lua_setfield(L, -2, control->name.c_str());
}
@ -568,7 +566,7 @@ namespace Automation4 {
std::string res;
// Format into "name1:value1|name2:value2|name3:value3"
for (auto control : controls) {
for (auto& control : controls) {
if (control->CanSerialiseValue()) {
if (!res.empty())
res += "|";
@ -589,7 +587,7 @@ namespace Automation4 {
std::string value = cur.substr(pos + 1);
// Hand value to all controls matching name
for (auto control : controls) {
for (auto& control : controls) {
if (control->name == name && control->CanSerialiseValue())
control->UnserialiseValue(value);
}

View file

@ -97,7 +97,6 @@ BaseGrid::BaseGrid(wxWindow* parent, agi::Context *context, const wxSize& size,
, batch_level(0)
, batch_active_line_changed(false)
, seek_listener(context->videoController->AddSeekListener(std::bind(&BaseGrid::Refresh, this, false, nullptr)))
, context_menu(0)
, yPos(0)
, context(context)
{
@ -140,7 +139,6 @@ BaseGrid::BaseGrid(wxWindow* parent, agi::Context *context, const wxSize& size,
BaseGrid::~BaseGrid() {
ClearMaps();
delete context_menu;
}
BEGIN_EVENT_TABLE(BaseGrid,wxWindow)
@ -759,7 +757,7 @@ void BaseGrid::OnContextMenu(wxContextMenuEvent &evt) {
wxPoint pos = evt.GetPosition();
if (pos == wxDefaultPosition || ScreenToClient(pos).y > lineHeight) {
if (!context_menu) context_menu = menu::GetMenu("grid_context", context);
menu::OpenPopupMenu(context_menu, this);
menu::OpenPopupMenu(context_menu.get(), this);
}
else {
const wxString strings[] = {

View file

@ -36,6 +36,7 @@
#pragma once
#include <map>
#include <memory>
#include <vector>
#include <wx/grid.h>
@ -85,7 +86,7 @@ class BaseGrid : public wxWindow, public SubtitleSelectionController {
agi::signal::Connection seek_listener;
/// Cached grid body context menu
wxMenu *context_menu;
std::unique_ptr<wxMenu> context_menu;
void OnContextMenu(wxContextMenuEvent &evt);
void OnHighlightVisibleChange(agi::OptionValue const& opt);

View file

@ -55,7 +55,7 @@ namespace {
}
void operator()(agi::Context *c) {
c->videoDisplay->SetTool(new T(c->videoDisplay, c));
c->videoDisplay->SetTool(agi::util::make_unique<T>(c->videoDisplay, c));
}
};

View file

@ -46,7 +46,9 @@
#include "utils.h"
#include <libaegisub/scoped_ptr.h>
#include <libaegisub/util.h>
#include <memory>
#include <vector>
#include <wx/bitmap.h>
@ -429,7 +431,7 @@ void ColorPickerScreenDropper::DropFromScreenXY(int x, int y) {
class DialogColorPicker : public wxDialog {
agi::scoped_ptr<PersistLocation> persist;
std::unique_ptr<PersistLocation> persist;
agi::Color cur_color; ///< Currently selected colour
@ -663,7 +665,7 @@ DialogColorPicker::DialogColorPicker(wxWindow *parent, agi::Color initial_color,
SetSizerAndFit(main_sizer);
persist.reset(new PersistLocation(this, "Tool/Colour Picker"));
persist = agi::util::make_unique<PersistLocation>(this, "Tool/Colour Picker");
// Fill the controls
int mode = OPT_GET("Tool/Colour Picker/Mode")->GetInt();

View file

@ -45,6 +45,8 @@
#include "video_context.h"
#include "video_display.h"
#include <libaegisub/util.h>
#include <boost/filesystem/path.hpp>
#include <wx/sizer.h>
@ -79,7 +81,7 @@ DialogDetachedVideo::DialogDetachedVideo(agi::Context *context)
videoBox->SetMinSize(wxSize(1,1));
SetMinSize(wxSize(1,1));
persist.reset(new PersistLocation(this, "Video/Detached"));
persist = agi::util::make_unique<PersistLocation>(this, "Video/Detached");
int display_index = wxDisplay::GetFromWindow(this);
// Ensure that the dialog is no larger than the screen

View file

@ -32,9 +32,9 @@
/// @ingroup main_ui
///
#include <memory>
#include <wx/dialog.h>
#include <libaegisub/scoped_ptr.h>
#include <libaegisub/signal.h>
namespace agi { struct Context; }
@ -47,7 +47,7 @@ class DialogDetachedVideo : public wxDialog {
VideoDisplay *old_display;
wxWindow *old_slider;
agi::signal::Connection video_open;
agi::scoped_ptr<PersistLocation> persist;
std::unique_ptr<PersistLocation> persist;
void OnClose(wxCloseEvent &);
/// Minimize event handler to hack around a wx bug

View file

@ -32,10 +32,9 @@
/// @ingroup export
///
#include <memory>
#include <wx/dialog.h>
#include <libaegisub/scoped_ptr.h>
class AssExporter;
namespace agi { struct Context; }
class wxCheckListBox;
@ -47,7 +46,7 @@ class DialogExport : public wxDialog {
agi::Context *c;
/// The export transform engine
agi::scoped_ptr<AssExporter> exporter;
std::unique_ptr<AssExporter> exporter;
/// The description of the currently selected export filter
wxTextCtrl *filter_description;

View file

@ -28,6 +28,7 @@
#include "text_file_writer.h"
#include <libaegisub/charset_conv.h>
#include <libaegisub/util.h>
#include <boost/lexical_cast.hpp>
#include <boost/regex.hpp>
@ -212,15 +213,16 @@ agi::vfr::Framerate EbuExportSettings::GetFramerate() const {
}
}
agi::charset::IconvWrapper *EbuExportSettings::GetTextEncoder() const {
std::unique_ptr<agi::charset::IconvWrapper> EbuExportSettings::GetTextEncoder() const {
using namespace agi;
switch (text_encoding) {
case iso6937_2: return new agi::charset::IconvWrapper("utf-8", "ISO-6937-2");
case iso8859_5: return new agi::charset::IconvWrapper("utf-8", "ISO-8859-5");
case iso8859_6: return new agi::charset::IconvWrapper("utf-8", "ISO-8859-6");
case iso8859_7: return new agi::charset::IconvWrapper("utf-8", "ISO-8859-7");
case iso8859_8: return new agi::charset::IconvWrapper("utf-8", "ISO-8859-8");
case utf8: return new agi::charset::IconvWrapper("utf-8", "utf-8");
default: return new agi::charset::IconvWrapper("utf-8", "ISO-8859-1");
case iso6937_2: return util::make_unique<charset::IconvWrapper>("utf-8", "ISO-6937-2");
case iso8859_5: return util::make_unique<charset::IconvWrapper>("utf-8", "ISO-8859-5");
case iso8859_6: return util::make_unique<charset::IconvWrapper>("utf-8", "ISO-8859-6");
case iso8859_7: return util::make_unique<charset::IconvWrapper>("utf-8", "ISO-8859-7");
case iso8859_8: return util::make_unique<charset::IconvWrapper>("utf-8", "ISO-8859-8");
case utf8: return util::make_unique<charset::IconvWrapper>("utf-8", "utf-8");
default: return util::make_unique<charset::IconvWrapper>("utf-8", "ISO-8859-1");
}
}

View file

@ -19,10 +19,11 @@
/// @see dialog_export_ebu3264.cpp
/// @ingroup subtitle_io export
#include <wx/dialog.h>
#include <libaegisub/vfr.h>
#include <memory>
#include <wx/dialog.h>
namespace agi { namespace charset { class IconvWrapper; } }
#pragma pack(push, 1)
@ -100,7 +101,7 @@ public:
agi::vfr::Framerate GetFramerate() const;
/// Get a charset encoder for the current text encoding
agi::charset::IconvWrapper *GetTextEncoder() const;
std::unique_ptr<agi::charset::IconvWrapper> GetTextEncoder() const;
/// Load saved export settings from options
/// @param prefix Option name prefix

View file

@ -19,7 +19,7 @@
/// @ingroup secondary_ui
///
#include <libaegisub/scoped_ptr.h>
#include <memory>
#include <wx/dialog.h>
@ -30,7 +30,7 @@ class wxComboBox;
class DialogSearchReplace : public wxDialog {
agi::Context *c;
agi::scoped_ptr<SearchReplaceSettings> settings;
std::unique_ptr<SearchReplaceSettings> settings;
bool has_replace;
wxComboBox *find_edit;
wxComboBox *replace_edit;

View file

@ -22,12 +22,12 @@
#include "selection_controller.h"
#include <libaegisub/fs_fwd.h>
#include <libaegisub/scoped_ptr.h>
#include <libaegisub/signal.h>
#include <libaegisub/vfr.h>
#include <boost/filesystem/path.hpp>
#include <deque>
#include <memory>
#include <wx/dialog.h>
@ -44,10 +44,11 @@ namespace json {
}
class DialogShiftTimes : public wxDialog {
wxDECLARE_NO_COPY_CLASS(DialogShiftTimes); // clang + libc++ herps a derp without this
agi::Context *context;
agi::fs::path history_filename;
agi::scoped_ptr<json::Array> history;
std::unique_ptr<json::Array> history;
agi::vfr::Framerate fps;
agi::signal::Connection timecodes_loaded_slot;
agi::signal::Connection selected_set_changed_slot;

View file

@ -34,14 +34,6 @@
#include "config.h"
#include <algorithm>
#include <wx/bmpbuttn.h>
#include <wx/fontenum.h>
#include <wx/msgdlg.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include "ass_dialogue.h"
#include "ass_file.h"
#include "ass_style.h"
@ -61,6 +53,15 @@
#include "validators.h"
#include <libaegisub/of_type_adaptor.h>
#include <libaegisub/util.h>
#include <algorithm>
#include <wx/bmpbuttn.h>
#include <wx/fontenum.h>
#include <wx/msgdlg.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
/// Style rename helper that walks a file searching for a style and optionally
/// updating references to it
@ -156,7 +157,7 @@ DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Con
style = this->style = new AssStyle;
}
work.reset(new AssStyle(*style));
work = agi::util::make_unique<AssStyle>(*style);
SetIcon(GETICON(style_toolbutton_16));
@ -375,7 +376,7 @@ DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Con
StyleName->SetInsertionPoint(0);
StyleName->SetInsertionPoint(-1);
persist.reset(new PersistLocation(this, "Tool/Style Editor", true));
persist = agi::util::make_unique<PersistLocation>(this, "Tool/Style Editor", true);
Bind(wxEVT_CHILD_FOCUS, &DialogStyleEditor::OnChildFocus, this);

View file

@ -32,14 +32,14 @@
/// @ingroup style_editor
///
#include <memory>
#include <wx/checkbox.h>
#include <wx/combobox.h>
#include <wx/radiobox.h>
#include <wx/spinctrl.h>
#include <wx/textctrl.h>
#include <libaegisub/scoped_ptr.h>
namespace agi { struct Context; }
class AssStyle;
class AssStyleStorage;
@ -49,7 +49,7 @@ class SubtitlesPreview;
class DialogStyleEditor : public wxDialog {
agi::Context *c;
agi::scoped_ptr<PersistLocation> persist;
std::unique_ptr<PersistLocation> persist;
/// If true, the style was just created and so the user should not be
/// asked if they want to change any existing lines should they rename
@ -61,7 +61,7 @@ class DialogStyleEditor : public wxDialog {
/// Copy of style passed to the subtitles preview to avoid making changes
/// before Apply is clicked
agi::scoped_ptr<AssStyle> work;
std::unique_ptr<AssStyle> work;
/// The style storage style is in, if applicable
AssStyleStorage *store;

View file

@ -220,7 +220,7 @@ DialogStyleManager::DialogStyleManager(agi::Context *context)
SetSizerAndFit(MainSizer);
// Position window
persist.reset(new PersistLocation(this, "Tool/Style Manager"));
persist = agi::util::make_unique<PersistLocation>(this, "Tool/Style Manager");
// Populate lists
LoadCatalog();

View file

@ -32,6 +32,7 @@
/// @ingroup style_editor
///
#include <memory>
#include <vector>
#include <wx/button.h>
@ -39,7 +40,6 @@
#include <wx/dialog.h>
#include <wx/listbox.h>
#include <libaegisub/scoped_ptr.h>
#include <libaegisub/signal.h>
#include "ass_style_storage.h"
@ -53,7 +53,7 @@ class PersistLocation;
class DialogStyleManager : public wxDialog {
agi::Context *c; ///< Project context
agi::scoped_ptr<PersistLocation> persist;
std::unique_ptr<PersistLocation> persist;
agi::signal::Connection commit_connection;
agi::signal::Connection active_line_connection;

View file

@ -19,7 +19,6 @@
/// @ingroup tools_ui
///
#include "config.h"
#include "dialog_styling_assistant.h"
@ -38,6 +37,8 @@
#include "persist_location.h"
#include "video_context.h"
#include <libaegisub/util.h>
#include <wx/checkbox.h>
#include <wx/colour.h>
#include <wx/listbox.h>
@ -136,7 +137,7 @@ DialogStyling::DialogStyling(agi::Context *context)
SetSizerAndFit(main_sizer);
persist.reset(new PersistLocation(this, "Tool/Styling Assistant"));
persist = agi::util::make_unique<PersistLocation>(this, "Tool/Styling Assistant");
Bind(wxEVT_ACTIVATE, &DialogStyling::OnActivate, this);
Bind(wxEVT_CHAR_HOOK, &DialogStyling::OnCharHook, this);

View file

@ -21,11 +21,10 @@
#include "selection_controller.h"
#include <memory>
#include <wx/dialog.h>
#include <wx/event.h>
#include <libaegisub/scoped_ptr.h>
namespace agi { struct Context; }
class AssDialogue;
class PersistLocation;
@ -58,7 +57,7 @@ class DialogStyling : public wxDialog {
AssDialogue *active_line;
agi::scoped_ptr<PersistLocation> persist;
std::unique_ptr<PersistLocation> persist;
public:
void Commit(bool next);

View file

@ -39,6 +39,8 @@
#include "utils.h"
#include "video_context.h"
#include <libaegisub/util.h>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/predicate.hpp>
@ -152,7 +154,7 @@ DialogTranslation::DialogTranslation(agi::Context *c)
SetSizerAndFit(main_sizer);
persist.reset(new PersistLocation(this, "Tool/Translation Assistant"));
persist = agi::util::make_unique<PersistLocation>(this, "Tool/Translation Assistant");
Bind(wxEVT_KEY_DOWN, &DialogTranslation::OnKeyDown, this);

View file

@ -21,10 +21,10 @@
#include <wx/dialog.h>
#include <libaegisub/exception.h>
#include <libaegisub/scoped_ptr.h>
#include <libaegisub/signal.h>
#include <boost/ptr_container/ptr_vector.hpp>
#include <memory>
namespace agi { struct Context; }
class AssDialogue;
@ -62,7 +62,7 @@ class DialogTranslation : public wxDialog {
SubsTextEditCtrl *translated_text;
wxCheckBox *seek_video;
agi::scoped_ptr<PersistLocation> persist;
std::unique_ptr<PersistLocation> persist;
void OnPlayAudioButton(wxCommandEvent &);
void OnPlayVideoButton(wxCommandEvent &);

View file

@ -19,10 +19,9 @@
/// @ingroup hotkey configuration_ui
///
#include <memory>
#include <wx/dataview.h>
#include <libaegisub/scoped_ptr.h>
class HotkeyModelItem;
class HotkeyModelRoot;
class Preferences;
@ -30,7 +29,7 @@ class Preferences;
/// @class HotkeyDataViewModel
/// @brief A wxDataViewModel for hotkeys
class HotkeyDataViewModel : public wxDataViewModel {
agi::scoped_ptr<HotkeyModelRoot> root;
std::unique_ptr<HotkeyModelRoot> root;
Preferences *parent;
bool has_pending_changes;

View file

@ -16,6 +16,7 @@
/// @brief Dynamic menu and toolbar generator.
/// @ingroup menu toolbar
#include <memory>
#include <string>
#include <libaegisub/exception.h>
@ -46,7 +47,7 @@ namespace menu {
/// Throws:
/// UnknownMenu if no menu with the given name was found
/// BadMenu if there is a menu with the given name, but it is invalid
wxMenu *GetMenu(std::string const& name, agi::Context *c);
std::unique_ptr<wxMenu> GetMenu(std::string const& name, agi::Context *c);
/// @brief Open a popup menu at the mouse
/// @param menu Menu to open

View file

@ -34,6 +34,7 @@
#include <libaegisub/json.h>
#include <libaegisub/log.h>
#include <libaegisub/path.h>
#include <libaegisub/util.h>
#include <algorithm>
#include <deque>
@ -437,7 +438,7 @@ namespace menu {
void GetMenuBar(std::string const& name, wxFrame *window, agi::Context *c) {
menu_items const& items = get_menu(name);
std::unique_ptr<CommandMenuBar> menu(new CommandMenuBar(c));
auto menu = agi::util::make_unique<CommandMenuBar>(c);
for (auto const& item : items) {
std::string submenu, disp;
read_entry(item, "submenu", &submenu);
@ -475,12 +476,12 @@ namespace menu {
menu.release();
}
wxMenu *GetMenu(std::string const& name, agi::Context *c) {
std::unique_ptr<wxMenu> GetMenu(std::string const& name, agi::Context *c) {
CommandMenu *menu = new CommandMenu(c);
build_menu(name, c, &menu->cm, menu);
menu->Bind(wxEVT_MENU_OPEN, &CommandManager::OnMenuOpen, &menu->cm);
menu->Bind(wxEVT_COMMAND_MENU_SELECTED, &CommandManager::OnMenuClick, &menu->cm);
return menu;
return std::unique_ptr<wxMenu>(menu);
}
void OpenPopupMenu(wxMenu *menu, wxWindow *parent_window) {

View file

@ -57,6 +57,7 @@
#include <libaegisub/dispatch.h>
#include <libaegisub/of_type_adaptor.h>
#include <libaegisub/util.h>
#include <functional>
#include <unordered_set>
@ -218,7 +219,7 @@ SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context)
connections.push_back(context->selectionController->AddSelectionListener(&SubsEditBox::OnSelectedSetChanged, this));
connections.push_back(context->initialLineState->AddChangeListener(&SubsEditBox::OnLineInitialTextChanged, this));
textSelectionController.reset(new ScintillaTextSelectionController(edit_ctrl));
textSelectionController = agi::util::make_unique<ScintillaTextSelectionController>(edit_ctrl);
context->textSelectionController = textSelectionController.get();
edit_ctrl->SetFocus();
}

View file

@ -36,13 +36,13 @@
#include <deque>
#include <boost/container/map.hpp>
#include <boost/flyweight/flyweight_fwd.hpp>
#include <memory>
#include <vector>
#include <wx/combobox.h>
#include <wx/panel.h>
#include <wx/timer.h>
#include <libaegisub/scoped_ptr.h>
#include <libaegisub/signal.h>
#include "selection_controller.h"
@ -200,7 +200,7 @@ class SubsEditBox : public wxPanel {
SubsTextEditCtrl *edit_ctrl;
wxTextCtrl *secondary_editor;
agi::scoped_ptr<TextSelectionController> textSelectionController;
std::unique_ptr<TextSelectionController> textSelectionController;
public:
/// @brief Constructor

View file

@ -25,13 +25,6 @@
#include "subtitle_format_ebu3264.h"
#include <libaegisub/charset_conv.h>
#include <libaegisub/exception.h>
#include <libaegisub/io.h>
#include <libaegisub/line_wrap.h>
#include <libaegisub/of_type_adaptor.h>
#include <libaegisub/scoped_ptr.h>
#include "aegisub_endian.h"
#include "ass_dialogue.h"
#include "ass_file.h"
@ -41,6 +34,12 @@
#include "options.h"
#include "text_file_writer.h"
#include <libaegisub/charset_conv.h>
#include <libaegisub/exception.h>
#include <libaegisub/io.h>
#include <libaegisub/line_wrap.h>
#include <libaegisub/of_type_adaptor.h>
#include <boost/algorithm/string/replace.hpp>
namespace
@ -469,8 +468,8 @@ namespace
std::vector<BlockTTI> create_blocks(std::vector<EbuSubtitle> const& subs_list, EbuExportSettings const& export_settings)
{
agi::scoped_ptr<agi::charset::IconvWrapper> encoder(export_settings.GetTextEncoder());
agi::vfr::Framerate fps = export_settings.GetFramerate();
auto encoder = export_settings.GetTextEncoder();
auto fps = export_settings.GetFramerate();
// Teletext captions are 1-23; Open subtitles are 0-99
uint8_t min_row = 0;

View file

@ -34,21 +34,6 @@
#include "config.h"
#include <algorithm>
#include <wx/combobox.h>
#include <wx/dataobj.h>
#include <wx/dcclient.h>
#include <wx/menu.h>
#include <wx/textctrl.h>
#include <wx/toolbar.h>
#ifdef HAVE_OPENGL_GL_H
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#include "video_display.h"
#include "ass_file.h"
@ -67,6 +52,23 @@
#include "video_frame.h"
#include "visual_tool.h"
#include <libaegisub/util.h>
#include <algorithm>
#include <wx/combobox.h>
#include <wx/dataobj.h>
#include <wx/dcclient.h>
#include <wx/menu.h>
#include <wx/textctrl.h>
#include <wx/toolbar.h>
#ifdef HAVE_OPENGL_GL_H
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
/// Attribute list for gl canvases; set the canvases to doublebuffered rgba with an 8 bit stencil buffer
int attribList[] = { WX_GL_RGBA , WX_GL_DOUBLEBUFFER, WX_GL_STENCIL_SIZE, 8, 0 };
@ -147,9 +149,9 @@ bool VideoDisplay::InitContext() {
return false;
if (!glContext)
glContext.reset(new wxGLContext(this));
glContext = agi::util::make_unique<wxGLContext>(this);
SetCurrent(*glContext.get());
SetCurrent(*glContext);
return true;
}
@ -163,7 +165,7 @@ void VideoDisplay::Render() try {
return;
if (!videoOut)
videoOut.reset(new VideoOutGL);
videoOut = agi::util::make_unique<VideoOutGL>();
if (!tool)
cmd::call("video/tool/cross", con);
@ -369,7 +371,7 @@ void VideoDisplay::OnMouseWheel(wxMouseEvent& event) {
}
void VideoDisplay::OnContextMenu(wxContextMenuEvent&) {
if (!context_menu.get()) context_menu.reset(menu::GetMenu("video_context", con));
if (!context_menu.get()) context_menu = menu::GetMenu("video_context", con);
SetCursor(wxNullCursor);
menu::OpenPopupMenu(context_menu.get(), this);
}
@ -405,12 +407,12 @@ void VideoDisplay::SetZoomFromBoxText(wxCommandEvent &) {
SetZoom(value / 100.);
}
void VideoDisplay::SetTool(VisualToolBase *new_tool) {
void VideoDisplay::SetTool(std::unique_ptr<VisualToolBase>&& new_tool) {
toolBar->ClearTools();
toolBar->Realize();
toolBar->Show(false);
tool.reset(new_tool);
tool = std::move(new_tool);
tool->SetToolbar(toolBar);
// Update size as the new typesetting tool may have changed the subtoolbar size

View file

@ -32,19 +32,15 @@
/// @ingroup video main_ui
///
#include <deque>
#include <memory>
#include <wx/glcanvas.h>
#include <typeinfo>
#include <libaegisub/scoped_ptr.h>
#include <libaegisub/signal.h>
#include "vector2d.h"
#include <deque>
#include <memory>
#include <typeinfo>
#include <wx/glcanvas.h>
// Prototypes
class AegiVideoFrame;
struct FrameReadyEvent;
@ -68,7 +64,7 @@ class VideoDisplay : public wxGLCanvas {
agi::Context *con;
agi::scoped_ptr<wxMenu> context_menu;
std::unique_ptr<wxMenu> context_menu;
/// The size of the video in screen at the current zoom level, which may not
/// be the same as the actual client size of the display
@ -91,15 +87,15 @@ class VideoDisplay : public wxGLCanvas {
double zoomValue;
/// The video renderer
agi::scoped_ptr<VideoOutGL> videoOut;
std::unique_ptr<VideoOutGL> videoOut;
/// The active visual typesetting tool
agi::scoped_ptr<VisualToolBase> tool;
std::unique_ptr<VisualToolBase> tool;
/// The toolbar used by individual typesetting tools
wxToolBar* toolBar;
/// The OpenGL context for this display
agi::scoped_ptr<wxGLContext> glContext;
std::unique_ptr<wxGLContext> glContext;
/// The dropdown box for selecting zoom levels
wxComboBox *zoomBox;
@ -164,7 +160,7 @@ public:
/// Get the last seen position of the mouse in script coordinates
Vector2D GetMousePosition() const;
void SetTool(VisualToolBase *new_tool);
void SetTool(std::unique_ptr<VisualToolBase>&& new_tool);
bool ToolIsType(std::type_info const& type) const;

View file

@ -19,18 +19,18 @@
/// @ingroup visual_ts
///
#include <libaegisub/scoped_ptr.h>
#include "visual_feature.h"
#include "visual_tool.h"
#include <memory>
class OpenGLText;
/// @class VisualToolCross
/// @brief A crosshair which shows the current mouse position and on double-click
/// shifts the selected lines to the clicked point
class VisualToolCross : public VisualTool<VisualDraggableFeature> {
agi::scoped_ptr<OpenGLText> gl_text;
std::unique_ptr<OpenGLText> gl_text;
void OnDoubleClick();
void Draw();