diff --git a/aegilib/aegilib.vcproj b/aegilib/aegilib.vcproj index c62dd0d9b..b63836671 100644 --- a/aegilib/aegilib.vcproj +++ b/aegilib/aegilib.vcproj @@ -227,6 +227,10 @@ RelativePath=".\include\aegilib\tokenizer.h" > + + diff --git a/aegilib/include/aegilib/action.h b/aegilib/include/aegilib/action.h index ca3097a16..dfba3cda0 100644 --- a/aegilib/include/aegilib/action.h +++ b/aegilib/include/aegilib/action.h @@ -47,15 +47,15 @@ namespace Aegilib { class Action { private: ActionType type; - void* data; + shared_ptr data; int par1; public: Action(); - Action(ActionType type,void* data,int par1); + Action(ActionType type,shared_ptr data,int par1); ActionType GetType() { return type; } - void* GetData() { return data; } + shared_ptr GetData() { return data; } int GetLineNumber() { return par1; } }; }; diff --git a/aegilib/include/aegilib/aegilib.h b/aegilib/include/aegilib/aegilib.h index d985b5e29..dd03f7d81 100644 --- a/aegilib/include/aegilib/aegilib.h +++ b/aegilib/include/aegilib/aegilib.h @@ -34,6 +34,7 @@ // #pragma once +#include "tr1.h" #include "exception.h" #include "model.h" #include "view.h" diff --git a/aegilib/include/aegilib/format.h b/aegilib/include/aegilib/format.h index 53b512a40..3d9260457 100644 --- a/aegilib/include/aegilib/format.h +++ b/aegilib/include/aegilib/format.h @@ -35,6 +35,7 @@ #pragma once #include "aegistring.h" +#include "tr1.h" namespace Aegilib { // Prototypes @@ -49,7 +50,7 @@ namespace Aegilib { virtual String GetName() const = 0; virtual StringArray GetReadExtensions() const = 0; virtual StringArray GetWriteExtensions() const = 0; - virtual FormatHandler* GetHandler(Model &model) const = 0; + virtual shared_ptr GetHandler(Model &model) const = 0; virtual bool CanStoreText() const { return false; } virtual bool CanStoreImages() const { return false; } @@ -65,5 +66,6 @@ namespace Aegilib { virtual int GetTimingPrecision() const { return 10; } // In milliseconds virtual int GetMaxTime() const { return 36000000-10; } // In milliseconds, default 9h 59min 59.99s }; + typedef shared_ptr FormatPtr; }; diff --git a/aegilib/include/aegilib/format_handler.h b/aegilib/include/aegilib/format_handler.h index 9c7af0d51..2ad27b56f 100644 --- a/aegilib/include/aegilib/format_handler.h +++ b/aegilib/include/aegilib/format_handler.h @@ -35,15 +35,18 @@ #pragma once #include "aegistring.h" +#include "tr1.h" namespace Aegilib { // Format handler interface class FormatHandler { - public: + protected: virtual ~FormatHandler() {} + public: virtual void Load(wxInputStream &file,const String encoding) = 0; }; + typedef shared_ptr FormatHandlerPtr; }; diff --git a/aegilib/include/aegilib/format_manager.h b/aegilib/include/aegilib/format_manager.h index 556e25feb..c6abce0e8 100644 --- a/aegilib/include/aegilib/format_manager.h +++ b/aegilib/include/aegilib/format_manager.h @@ -41,18 +41,18 @@ namespace Aegilib { // Format manager class class FormatManager { private: - static std::vector formats; + static std::vector formats; FormatManager() {} public: - static void AddFormat(const Format *format); + static void AddFormat(const FormatPtr format); static void InitializeFormats(); static void ClearFormats(); static int GetFormatCount(); - static const Format* GetFormatByIndex(const int index); - static const Format* GetFormatFromFilename(const String &filename,bool read); - static const Format* GetFormatFromName(const String &name); + static const FormatPtr GetFormatByIndex(const int index); + static const FormatPtr GetFormatFromFilename(const String &filename,bool read); + static const FormatPtr GetFormatFromName(const String &name); }; }; diff --git a/aegilib/include/aegilib/model.h b/aegilib/include/aegilib/model.h index 6ec69a1bc..c28a178f6 100644 --- a/aegilib/include/aegilib/model.h +++ b/aegilib/include/aegilib/model.h @@ -43,6 +43,7 @@ namespace Aegilib { // Prototypes class View; + typedef shared_ptr ViewPtr; class Notification; class Format; @@ -50,11 +51,12 @@ namespace Aegilib { // Stores the subtitle data class Model { friend class Manipulator; - typedef std::list ViewList; + typedef std::list ViewList; typedef std::list ActionStack; + typedef shared_ptr FormatPtr; private: - std::list sections; + std::list sections; ActionStack undoStack; ActionStack redoStack; ViewList listeners; @@ -66,14 +68,14 @@ namespace Aegilib { public: const Format& GetFormat() const; - void AddListener(View *listener); + void AddListener(ViewPtr listener); - void Load(wxInputStream &input,const Format *format=NULL,const String encoding=L""); - void Save(wxOutputStream &output,const Format *format=NULL,const String encoding=L"UTF-8"); + void Load(wxInputStream &input,const FormatPtr format=FormatPtr(),const String encoding=L""); + void Save(wxOutputStream &output,const FormatPtr format=FormatPtr(),const String encoding=L"UTF-8"); void LoadFile(const String filename,const String encoding=L""); void SaveFile(const String filename,const String encoding=L"UTF-8"); - Section* GetSection(String name) const; + SectionPtr GetSection(String name) const; void AddSection(String name); bool CanUndo(const String owner=L"") const; diff --git a/aegilib/include/aegilib/section.h b/aegilib/include/aegilib/section.h index 60adaf006..de952667b 100644 --- a/aegilib/include/aegilib/section.h +++ b/aegilib/include/aegilib/section.h @@ -36,6 +36,7 @@ #pragma once #include "aegistring.h" #include "section_entry.h" +#include "tr1.h" #include #include @@ -43,14 +44,15 @@ namespace Aegilib { // Section class class Section { + friend class shared_ptr
; private: - std::list entries; + std::list entries; std::map properties; String name; public: Section(String name); - ~Section(); + ~Section() {} const String& GetName() const { return name; } String SetName(const String& newName) { name = newName; } @@ -62,7 +64,8 @@ namespace Aegilib { size_t PropertyCount() const; String GetPropertyName(size_t index) const; - void AddEntry(SectionEntry *entry); + void AddEntry(SectionEntryPtr entry); }; + typedef shared_ptr
SectionPtr; }; diff --git a/aegilib/include/aegilib/section_entry.h b/aegilib/include/aegilib/section_entry.h index a071d3884..ec6a54921 100644 --- a/aegilib/include/aegilib/section_entry.h +++ b/aegilib/include/aegilib/section_entry.h @@ -35,6 +35,7 @@ #pragma once #include "aegistring.h" +#include "tr1.h" namespace Aegilib { @@ -49,25 +50,31 @@ namespace Aegilib { // Prototypes class SectionEntryPlain; + typedef shared_ptr SectionEntryPlainPtr; class SectionEntryDialogue; + typedef shared_ptr SectionEntryDialoguePtr; class SectionEntryStyle; + typedef shared_ptr SectionEntryStylePtr; class SectionEntryFile; + typedef shared_ptr SectionEntryFilePtr; class SectionEntryRaw; + typedef shared_ptr SectionEntryRawPtr; + class SectionEntry; + typedef shared_ptr SectionEntryPtr; // Section entry class class SectionEntry { protected: + virtual ~SectionEntry() {} const String& EmptyString() const; public: - virtual ~SectionEntry() {} - virtual SectionEntryType GetType() const =0; - virtual SectionEntryPlain *GetAsPlain() { return NULL; } - virtual SectionEntryDialogue *GetAsDialogue() { return NULL; } - virtual SectionEntryStyle *GetAsStyle() { return NULL; } - virtual SectionEntryFile *GetAsFile() { return NULL; } - virtual SectionEntryRaw *GetAsRaw() { return NULL; } + static const SectionEntryPlainPtr GetAsPlain(const SectionEntryPtr &ptr); + static const SectionEntryDialoguePtr GetAsDialogue(const SectionEntryPtr &ptr); + static const SectionEntryStylePtr GetAsStyle(const SectionEntryPtr &ptr); + static const SectionEntryFilePtr GetAsFile(const SectionEntryPtr &ptr); + static const SectionEntryRawPtr GetAsRaw(const SectionEntryPtr &ptr); }; }; diff --git a/aegilib/include/aegilib/tokenizer.h b/aegilib/include/aegilib/tokenizer.h index 13f31b1bf..b082431d6 100644 --- a/aegilib/include/aegilib/tokenizer.h +++ b/aegilib/include/aegilib/tokenizer.h @@ -35,6 +35,7 @@ #pragma once #include "aegistring.h" +#include "tr1.h" // Prototypes class wxStringTokenizer; @@ -44,7 +45,7 @@ namespace Aegilib { // Tokenizer class class Tokenizer { private: - wxStringTokenizer *tkn; + shared_ptr tkn; public: Tokenizer(String string,String token); diff --git a/aegilib/include/aegilib/tr1.h b/aegilib/include/aegilib/tr1.h new file mode 100644 index 000000000..02ace9b21 --- /dev/null +++ b/aegilib/include/aegilib/tr1.h @@ -0,0 +1,57 @@ +// Copyright (c) 2008, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB/AEGILIB +// +// Website: http://www.aegisub.net +// Contact: mailto:amz@aegisub.net +// + +#pragma once + +////////////////////////////////////////// +// Include the Technical Report 1 headers +// This is necessary because some compilers put them on different places + +#include +#include + +namespace Aegilib { + using std::tr1::shared_ptr; + using std::tr1::weak_ptr; + using std::tr1::array; + using std::tr1::dynamic_pointer_cast; + using std::tr1::static_pointer_cast; + + // Null deleter for use with shared_ptr + class NullDeleter { + public: + void operator()(void const *) const { } + }; +}; diff --git a/aegilib/src/action.cpp b/aegilib/src/action.cpp index efde1fde1..29ae30b1f 100644 --- a/aegilib/src/action.cpp +++ b/aegilib/src/action.cpp @@ -46,7 +46,7 @@ Action::Action() ////////////////////////////// // Initialization constructor -Action::Action(ActionType _type,void* _data,int _par1) +Action::Action(ActionType _type,shared_ptr _data,int _par1) { type = _type; data = _data; diff --git a/aegilib/src/format_manager.cpp b/aegilib/src/format_manager.cpp index 84c9fb7d5..52f499cee 100644 --- a/aegilib/src/format_manager.cpp +++ b/aegilib/src/format_manager.cpp @@ -41,12 +41,12 @@ using namespace Aegilib; //////// // List -std::vector FormatManager::formats; +std::vector FormatManager::formats; //////////////// // Add a format -void FormatManager::AddFormat(const Format *format) +void FormatManager::AddFormat(const FormatPtr format) { formats.push_back(format); } @@ -56,7 +56,7 @@ void FormatManager::AddFormat(const Format *format) // Initialzie all built-in formats void FormatManager::InitializeFormats() { - formats.push_back(new FormatASS); + formats.push_back(FormatPtr(new FormatASS)); } @@ -78,20 +78,20 @@ int FormatManager::GetFormatCount() //////////// // By index -const Format* FormatManager::GetFormatByIndex(const int index) +const FormatPtr FormatManager::GetFormatByIndex(const int index) { try { return formats.at(index); } catch (...) { - return NULL; + return FormatPtr(); } } /////////////// // By filename -const Format* FormatManager::GetFormatFromFilename(const String &filename,bool read) +const FormatPtr FormatManager::GetFormatFromFilename(const String &filename,bool read) { size_t len = formats.size(); for (size_t i=0;iGetName()) return formats[i]; } - return NULL; + return FormatPtr(); } diff --git a/aegilib/src/formats/format_ass.cpp b/aegilib/src/formats/format_ass.cpp index 05bda504f..79c8bf60f 100644 --- a/aegilib/src/formats/format_ass.cpp +++ b/aegilib/src/formats/format_ass.cpp @@ -86,7 +86,7 @@ void FormatHandlerASS::Load(wxInputStream &file,const String encoding) int version = 1; wxString curGroup = L"-"; wxString prevGroup = L"-"; - Section *section = NULL; + SectionPtr section = SectionPtr(); // Read file while (reader.HasMoreLines()) { @@ -108,7 +108,7 @@ void FormatHandlerASS::Load(wxInputStream &file,const String encoding) if (cur[0] == L'[') continue; // Create and insert line - SectionEntry *entry = MakeEntry(cur,section,version); + SectionEntryPtr entry = MakeEntry(cur,section,version); if (entry) section->AddEntry(entry); } @@ -127,11 +127,11 @@ void FormatHandlerASS::Load(wxInputStream &file,const String encoding) /////////////// // Create line -SectionEntry *FormatHandlerASS::MakeEntry(const String &data,Section *section,int version) +SectionEntryPtr FormatHandlerASS::MakeEntry(const String &data,SectionPtr section,int version) { // Variables const String group = section->GetName(); - SectionEntry *final = NULL; + SectionEntryPtr final; // Attachments if (group == _T("Fonts") || group == _T("Graphics")) { @@ -142,12 +142,8 @@ SectionEntry *FormatHandlerASS::MakeEntry(const String &data,Section *section,in else if (group == _T("Events")) { // Dialogue lines if ((data.Left(9) == _T("Dialogue:") || data.Left(8) == _T("Comment:"))) { - DialogueASS *diag = new DialogueASS(data,version); + shared_ptr diag (new DialogueASS(data,version)); final = diag; - - // Debug - wxString out = diag->GetStartTime().GetString(2,1) + _T(",") + diag->GetEndTime().GetString(2,1) + _T(",") + diag->GetText(); - std::cout << out.mb_str(wxConvUTF8) << std::endl; } // Format lines @@ -155,7 +151,7 @@ SectionEntry *FormatHandlerASS::MakeEntry(const String &data,Section *section,in section->SetProperty(_T("Format"),data.Mid(7).Trim(true).Trim(false)); } - // Garbage + // Garbage/hard comments else { // TODO } @@ -164,12 +160,8 @@ SectionEntry *FormatHandlerASS::MakeEntry(const String &data,Section *section,in // Styles else if (group == _T("V4+ Styles")) { if (data.Left(6) == _T("Style:")) { - StyleASS *style = new StyleASS(data,version); + shared_ptr style (new StyleASS(data,version)); final = style; - - // Debug - wxString out = style->GetName() + _T(": ") + style->GetFontName() + _T(", ") + wxString::Format(_T("(%i,%i,%i)"),style->GetColour(0).GetRed(),style->GetColour(0).GetGreen(),style->GetColour(0).GetBlue()); - std::cout << out.mb_str(wxConvUTF8) << std::endl; } if (data.Left(7) == _T("Format:")) { section->SetProperty(_T("Format"),data.Mid(7).Trim(true).Trim(false)); @@ -179,17 +171,17 @@ SectionEntry *FormatHandlerASS::MakeEntry(const String &data,Section *section,in // Script info else if (group == _T("Script Info")) { // Discard comments - if (data.Left(1) == _T(";")) return NULL; + if (data.Left(1) == _T(";")) return SectionEntryPtr(); // Parse property size_t pos = data.Find(_T(':')); - if (pos == wxNOT_FOUND) return NULL; + if (pos == wxNOT_FOUND) return SectionEntryPtr(); wxString key = data.Left(pos).Trim(true).Trim(false); wxString value = data.Mid(pos+1).Trim(true).Trim(false); // Insert property section->SetProperty(key,value); - return NULL; + return SectionEntryPtr(); } // Return entry diff --git a/aegilib/src/formats/format_ass.h b/aegilib/src/formats/format_ass.h index 09e98e9fe..e229bb617 100644 --- a/aegilib/src/formats/format_ass.h +++ b/aegilib/src/formats/format_ass.h @@ -48,7 +48,7 @@ namespace Aegilib { // Advanced Substation Alpha format handler class FormatHandlerASS : public FormatHandler { private: - SectionEntry *MakeEntry(const String &data,Section *section,int version); + SectionEntryPtr MakeEntry(const String &data,SectionPtr section,int version); void ProcessGroup(String cur,String &curGroup,int &version); Model &model; @@ -65,7 +65,7 @@ namespace Aegilib { String GetName() const { return L"Advanced Substation Alpha"; } StringArray GetReadExtensions() const; StringArray GetWriteExtensions() const; - FormatHandler* GetHandler(Model &model) const { return new FormatHandlerASS(model); } + FormatHandlerPtr GetHandler(Model &model) const { return FormatHandlerPtr(new FormatHandlerASS(model)); } bool CanStoreText() const { return true; } bool CanUseTime() const { return true; } diff --git a/aegilib/src/model.cpp b/aegilib/src/model.cpp index f5a83885e..ef6fbe472 100644 --- a/aegilib/src/model.cpp +++ b/aegilib/src/model.cpp @@ -39,7 +39,7 @@ using namespace Aegilib; ///////////////////////////////////////////////////////// // Adds a listener to be notified whenever things change -void Model::AddListener(View *listener) +void Model::AddListener(ViewPtr listener) { wxASSERT(listener); listeners.push_back(listener); @@ -86,7 +86,7 @@ Manipulator Model::CreateAntiManipulator(const Manipulator &src) ////////////////// // Load subtitles -void Model::Load(wxInputStream &input,const Format *format,const String encoding) +void Model::Load(wxInputStream &input,const FormatPtr format,const String encoding) { // Autodetect format if (format == NULL) { @@ -97,20 +97,17 @@ void Model::Load(wxInputStream &input,const Format *format,const String encoding } // Get handler - FormatHandler *handler = format->GetHandler(*this); + FormatHandlerPtr handler = format->GetHandler(*this); if (!handler) throw Exception(Exception::No_Format_Handler); // Load handler->Load(input,encoding); - - // Clean up - delete handler; } ////////////////// // Save subtitles -void Model::Save(wxOutputStream &output,const Format *format,const String encoding) +void Model::Save(wxOutputStream &output,const FormatPtr format,const String encoding) { (void) output; (void) format; @@ -123,7 +120,7 @@ void Model::Save(wxOutputStream &output,const Format *format,const String encodi // Load a file void Model::LoadFile(const String filename,const String encoding) { - const Format *handler = FormatManager::GetFormatFromFilename(filename,true); + const FormatPtr handler = FormatManager::GetFormatFromFilename(filename,true); wxFileInputStream stream(filename); Load(stream,handler,encoding); } @@ -133,7 +130,7 @@ void Model::LoadFile(const String filename,const String encoding) // Save a file void Model::SaveFile(const String filename,const String encoding) { - const Format *handler = FormatManager::GetFormatFromFilename(filename,true); + const FormatPtr handler = FormatManager::GetFormatFromFilename(filename,true); wxFileOutputStream stream(filename); Save(stream,handler,encoding); } @@ -141,13 +138,13 @@ void Model::SaveFile(const String filename,const String encoding) ////////////////// // Gets a section -Section* Model::GetSection(String name) const +SectionPtr Model::GetSection(String name) const { - std::list::const_iterator cur; + std::list::const_iterator cur; for (cur=sections.begin();cur!=sections.end();cur++) { if ((*cur)->GetName() == name) return *cur; } - return NULL; + return SectionPtr(); } @@ -155,7 +152,7 @@ Section* Model::GetSection(String name) const // Inserts a new section void Model::AddSection(String name) { - Section *prev = GetSection(name); + SectionPtr prev = GetSection(name); if (prev) throw Exception(Exception::Section_Already_Exists); - sections.push_back(new Section(name)); + sections.push_back(SectionPtr(new Section(name))); } diff --git a/aegilib/src/prec.h b/aegilib/src/prec.h index d7665d826..900b1e271 100644 --- a/aegilib/src/prec.h +++ b/aegilib/src/prec.h @@ -5,6 +5,7 @@ #include #include #include +#include "tr1.h" // wxWidgets #ifdef _MSC_VER diff --git a/aegilib/src/section.cpp b/aegilib/src/section.cpp index 1e1655733..7eeff08b7 100644 --- a/aegilib/src/section.cpp +++ b/aegilib/src/section.cpp @@ -46,16 +46,9 @@ Section::Section(String _name) } -////////////// -// Destructor -Section::~Section() -{ -} - - /////////////////// // Append an entry -void Section::AddEntry(SectionEntry *entry) +void Section::AddEntry(SectionEntryPtr entry) { entries.push_back(entry); } diff --git a/aegilib/src/section_entry.cpp b/aegilib/src/section_entry.cpp index 23109a7b6..a2f142fa6 100644 --- a/aegilib/src/section_entry.cpp +++ b/aegilib/src/section_entry.cpp @@ -35,6 +35,8 @@ #include "section_entry.h" +#include "section_entry_dialogue.h" +#include "section_entry_style.h" using namespace Aegilib; @@ -45,3 +47,25 @@ const String& SectionEntry::EmptyString() const static const String str = _T(""); return str; } + + +const SectionEntryPlainPtr SectionEntry::GetAsPlain(const SectionEntryPtr &ptr) +{ + (void) ptr; return SectionEntryPlainPtr(); +} +const SectionEntryDialoguePtr SectionEntry::GetAsDialogue(const SectionEntryPtr &ptr) +{ + return dynamic_pointer_cast(ptr); +} +const SectionEntryStylePtr SectionEntry::GetAsStyle(const SectionEntryPtr &ptr) +{ + return dynamic_pointer_cast(ptr); +} +const SectionEntryFilePtr SectionEntry::GetAsFile(const SectionEntryPtr &ptr) +{ + (void) ptr; return SectionEntryFilePtr(); +} +const SectionEntryRawPtr SectionEntry::GetAsRaw(const SectionEntryPtr &ptr) +{ + (void) ptr; return SectionEntryRawPtr(); +} diff --git a/aegilib/src/text_file_reader.cpp b/aegilib/src/text_file_reader.cpp index ad5dee544..f843ef54a 100644 --- a/aegilib/src/text_file_reader.cpp +++ b/aegilib/src/text_file_reader.cpp @@ -53,7 +53,6 @@ TextFileReader::TextFileReader(wxInputStream &stream,Aegilib::String enc,bool _t : file(stream) { // Setup - customConv = false; trim = _trim; // Set encoding @@ -66,8 +65,6 @@ TextFileReader::TextFileReader(wxInputStream &stream,Aegilib::String enc,bool _t ////////////// // Destructor TextFileReader::~TextFileReader() { - // Clean up conversion - if (customConv) delete conv; } @@ -77,11 +74,9 @@ void TextFileReader::SetEncodingConfiguration() { // Set encoding configuration swap = false; Is16 = false; - customConv = false; - conv = NULL; + conv = shared_ptr(); if (encoding == _T("UTF-8")) { - conv = new wxMBConvUTF8; - customConv = true; + conv = shared_ptr (new wxMBConvUTF8); } else if (encoding == _T("UTF-16LE")) { Is16 = true; @@ -91,15 +86,13 @@ void TextFileReader::SetEncodingConfiguration() { swap = true; } else if (encoding == _T("UTF-7")) { - conv = new wxCSConv(encoding); - customConv = true; + conv = shared_ptr(new wxCSConv(encoding)); } else if (encoding == _T("Local")) { - conv = wxConvCurrent; + conv = shared_ptr (wxConvCurrent,NullDeleter()); } else { - conv = new wxCSConv(encoding); - customConv = true; + conv = shared_ptr (new wxCSConv(encoding)); } } diff --git a/aegilib/src/text_file_reader.h b/aegilib/src/text_file_reader.h index 9e9a1d7f9..41d669bb9 100644 --- a/aegilib/src/text_file_reader.h +++ b/aegilib/src/text_file_reader.h @@ -47,10 +47,9 @@ namespace Aegilib { private: wxString encoding; wxInputStream &file; - wxMBConv *conv; + shared_ptr conv; bool Is16; bool swap; - bool customConv; bool trim; void SetEncodingConfiguration(); diff --git a/aegilib/src/tokenizer.cpp b/aegilib/src/tokenizer.cpp index 37f848c97..075c3d1d5 100644 --- a/aegilib/src/tokenizer.cpp +++ b/aegilib/src/tokenizer.cpp @@ -42,11 +42,10 @@ using namespace Aegilib; // Constructor Tokenizer::Tokenizer(String string,String token) { - tkn = new wxStringTokenizer(string,token,wxTOKEN_RET_EMPTY_ALL); + tkn = shared_ptr (new wxStringTokenizer(string,token,wxTOKEN_RET_EMPTY_ALL)); } Tokenizer::~Tokenizer() { - delete tkn; } diff --git a/aegilib/src/view.cpp b/aegilib/src/view.cpp index 328d94215..fd478da70 100644 --- a/aegilib/src/view.cpp +++ b/aegilib/src/view.cpp @@ -38,5 +38,7 @@ using namespace Aegilib; void View::Register(Model &model) { - model.AddListener(this); + (void) model; + // TODO: change this + //model.AddListener(this); }