Modified the subs lib to use TR1's shared_ptr.

Originally committed to SVN as r2034.
This commit is contained in:
Rodrigo Braz Monteiro 2008-03-13 03:42:27 +00:00
parent 3ab038d373
commit a3755cc6e4
23 changed files with 176 additions and 96 deletions

View File

@ -227,6 +227,10 @@
RelativePath=".\include\aegilib\tokenizer.h" RelativePath=".\include\aegilib\tokenizer.h"
> >
</File> </File>
<File
RelativePath=".\include\aegilib\tr1.h"
>
</File>
<File <File
RelativePath=".\include\aegilib\utils.h" RelativePath=".\include\aegilib\utils.h"
> >

View File

@ -47,15 +47,15 @@ namespace Aegilib {
class Action { class Action {
private: private:
ActionType type; ActionType type;
void* data; shared_ptr<void> data;
int par1; int par1;
public: public:
Action(); Action();
Action(ActionType type,void* data,int par1); Action(ActionType type,shared_ptr<void> data,int par1);
ActionType GetType() { return type; } ActionType GetType() { return type; }
void* GetData() { return data; } shared_ptr<void> GetData() { return data; }
int GetLineNumber() { return par1; } int GetLineNumber() { return par1; }
}; };
}; };

View File

@ -34,6 +34,7 @@
// //
#pragma once #pragma once
#include "tr1.h"
#include "exception.h" #include "exception.h"
#include "model.h" #include "model.h"
#include "view.h" #include "view.h"

View File

@ -35,6 +35,7 @@
#pragma once #pragma once
#include "aegistring.h" #include "aegistring.h"
#include "tr1.h"
namespace Aegilib { namespace Aegilib {
// Prototypes // Prototypes
@ -49,7 +50,7 @@ namespace Aegilib {
virtual String GetName() const = 0; virtual String GetName() const = 0;
virtual StringArray GetReadExtensions() const = 0; virtual StringArray GetReadExtensions() const = 0;
virtual StringArray GetWriteExtensions() const = 0; virtual StringArray GetWriteExtensions() const = 0;
virtual FormatHandler* GetHandler(Model &model) const = 0; virtual shared_ptr<FormatHandler> GetHandler(Model &model) const = 0;
virtual bool CanStoreText() const { return false; } virtual bool CanStoreText() const { return false; }
virtual bool CanStoreImages() 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 GetTimingPrecision() const { return 10; } // In milliseconds
virtual int GetMaxTime() const { return 36000000-10; } // In milliseconds, default 9h 59min 59.99s virtual int GetMaxTime() const { return 36000000-10; } // In milliseconds, default 9h 59min 59.99s
}; };
typedef shared_ptr<Format> FormatPtr;
}; };

View File

@ -35,15 +35,18 @@
#pragma once #pragma once
#include "aegistring.h" #include "aegistring.h"
#include "tr1.h"
namespace Aegilib { namespace Aegilib {
// Format handler interface // Format handler interface
class FormatHandler { class FormatHandler {
public: protected:
virtual ~FormatHandler() {} virtual ~FormatHandler() {}
public:
virtual void Load(wxInputStream &file,const String encoding) = 0; virtual void Load(wxInputStream &file,const String encoding) = 0;
}; };
typedef shared_ptr<FormatHandler> FormatHandlerPtr;
}; };

View File

@ -41,18 +41,18 @@ namespace Aegilib {
// Format manager class // Format manager class
class FormatManager { class FormatManager {
private: private:
static std::vector<const Format*> formats; static std::vector<const FormatPtr> formats;
FormatManager() {} FormatManager() {}
public: public:
static void AddFormat(const Format *format); static void AddFormat(const FormatPtr format);
static void InitializeFormats(); static void InitializeFormats();
static void ClearFormats(); static void ClearFormats();
static int GetFormatCount(); static int GetFormatCount();
static const Format* GetFormatByIndex(const int index); static const FormatPtr GetFormatByIndex(const int index);
static const Format* GetFormatFromFilename(const String &filename,bool read); static const FormatPtr GetFormatFromFilename(const String &filename,bool read);
static const Format* GetFormatFromName(const String &name); static const FormatPtr GetFormatFromName(const String &name);
}; };
}; };

View File

@ -43,6 +43,7 @@ namespace Aegilib {
// Prototypes // Prototypes
class View; class View;
typedef shared_ptr<View> ViewPtr;
class Notification; class Notification;
class Format; class Format;
@ -50,11 +51,12 @@ namespace Aegilib {
// Stores the subtitle data // Stores the subtitle data
class Model { class Model {
friend class Manipulator; friend class Manipulator;
typedef std::list<View*> ViewList; typedef std::list<ViewPtr> ViewList;
typedef std::list<const Manipulator> ActionStack; typedef std::list<const Manipulator> ActionStack;
typedef shared_ptr<Format> FormatPtr;
private: private:
std::list<Section*> sections; std::list<SectionPtr> sections;
ActionStack undoStack; ActionStack undoStack;
ActionStack redoStack; ActionStack redoStack;
ViewList listeners; ViewList listeners;
@ -66,14 +68,14 @@ namespace Aegilib {
public: public:
const Format& GetFormat() const; 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 Load(wxInputStream &input,const FormatPtr format=FormatPtr(),const String encoding=L"");
void Save(wxOutputStream &output,const Format *format=NULL,const String encoding=L"UTF-8"); void Save(wxOutputStream &output,const FormatPtr format=FormatPtr(),const String encoding=L"UTF-8");
void LoadFile(const String filename,const String encoding=L""); void LoadFile(const String filename,const String encoding=L"");
void SaveFile(const String filename,const String encoding=L"UTF-8"); 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); void AddSection(String name);
bool CanUndo(const String owner=L"") const; bool CanUndo(const String owner=L"") const;

View File

@ -36,6 +36,7 @@
#pragma once #pragma once
#include "aegistring.h" #include "aegistring.h"
#include "section_entry.h" #include "section_entry.h"
#include "tr1.h"
#include <list> #include <list>
#include <map> #include <map>
@ -43,14 +44,15 @@ namespace Aegilib {
// Section class // Section class
class Section { class Section {
friend class shared_ptr<Section>;
private: private:
std::list<SectionEntry*> entries; std::list<SectionEntryPtr> entries;
std::map<String,String> properties; std::map<String,String> properties;
String name; String name;
public: public:
Section(String name); Section(String name);
~Section(); ~Section() {}
const String& GetName() const { return name; } const String& GetName() const { return name; }
String SetName(const String& newName) { name = newName; } String SetName(const String& newName) { name = newName; }
@ -62,7 +64,8 @@ namespace Aegilib {
size_t PropertyCount() const; size_t PropertyCount() const;
String GetPropertyName(size_t index) const; String GetPropertyName(size_t index) const;
void AddEntry(SectionEntry *entry); void AddEntry(SectionEntryPtr entry);
}; };
typedef shared_ptr<Section> SectionPtr;
}; };

View File

@ -35,6 +35,7 @@
#pragma once #pragma once
#include "aegistring.h" #include "aegistring.h"
#include "tr1.h"
namespace Aegilib { namespace Aegilib {
@ -49,25 +50,31 @@ namespace Aegilib {
// Prototypes // Prototypes
class SectionEntryPlain; class SectionEntryPlain;
typedef shared_ptr<SectionEntryPlain> SectionEntryPlainPtr;
class SectionEntryDialogue; class SectionEntryDialogue;
typedef shared_ptr<SectionEntryDialogue> SectionEntryDialoguePtr;
class SectionEntryStyle; class SectionEntryStyle;
typedef shared_ptr<SectionEntryStyle> SectionEntryStylePtr;
class SectionEntryFile; class SectionEntryFile;
typedef shared_ptr<SectionEntryFile> SectionEntryFilePtr;
class SectionEntryRaw; class SectionEntryRaw;
typedef shared_ptr<SectionEntryRaw> SectionEntryRawPtr;
class SectionEntry;
typedef shared_ptr<SectionEntry> SectionEntryPtr;
// Section entry class // Section entry class
class SectionEntry { class SectionEntry {
protected: protected:
virtual ~SectionEntry() {}
const String& EmptyString() const; const String& EmptyString() const;
public: public:
virtual ~SectionEntry() {}
virtual SectionEntryType GetType() const =0; virtual SectionEntryType GetType() const =0;
virtual SectionEntryPlain *GetAsPlain() { return NULL; } static const SectionEntryPlainPtr GetAsPlain(const SectionEntryPtr &ptr);
virtual SectionEntryDialogue *GetAsDialogue() { return NULL; } static const SectionEntryDialoguePtr GetAsDialogue(const SectionEntryPtr &ptr);
virtual SectionEntryStyle *GetAsStyle() { return NULL; } static const SectionEntryStylePtr GetAsStyle(const SectionEntryPtr &ptr);
virtual SectionEntryFile *GetAsFile() { return NULL; } static const SectionEntryFilePtr GetAsFile(const SectionEntryPtr &ptr);
virtual SectionEntryRaw *GetAsRaw() { return NULL; } static const SectionEntryRawPtr GetAsRaw(const SectionEntryPtr &ptr);
}; };
}; };

View File

@ -35,6 +35,7 @@
#pragma once #pragma once
#include "aegistring.h" #include "aegistring.h"
#include "tr1.h"
// Prototypes // Prototypes
class wxStringTokenizer; class wxStringTokenizer;
@ -44,7 +45,7 @@ namespace Aegilib {
// Tokenizer class // Tokenizer class
class Tokenizer { class Tokenizer {
private: private:
wxStringTokenizer *tkn; shared_ptr<wxStringTokenizer> tkn;
public: public:
Tokenizer(String string,String token); Tokenizer(String string,String token);

View File

@ -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 <tr1/memory>
#include <tr1/array>
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 { }
};
};

View File

@ -46,7 +46,7 @@ Action::Action()
////////////////////////////// //////////////////////////////
// Initialization constructor // Initialization constructor
Action::Action(ActionType _type,void* _data,int _par1) Action::Action(ActionType _type,shared_ptr<void> _data,int _par1)
{ {
type = _type; type = _type;
data = _data; data = _data;

View File

@ -41,12 +41,12 @@ using namespace Aegilib;
//////// ////////
// List // List
std::vector<const Format*> FormatManager::formats; std::vector<const FormatPtr> FormatManager::formats;
//////////////// ////////////////
// Add a format // Add a format
void FormatManager::AddFormat(const Format *format) void FormatManager::AddFormat(const FormatPtr format)
{ {
formats.push_back(format); formats.push_back(format);
} }
@ -56,7 +56,7 @@ void FormatManager::AddFormat(const Format *format)
// Initialzie all built-in formats // Initialzie all built-in formats
void FormatManager::InitializeFormats() void FormatManager::InitializeFormats()
{ {
formats.push_back(new FormatASS); formats.push_back(FormatPtr(new FormatASS));
} }
@ -78,20 +78,20 @@ int FormatManager::GetFormatCount()
//////////// ////////////
// By index // By index
const Format* FormatManager::GetFormatByIndex(const int index) const FormatPtr FormatManager::GetFormatByIndex(const int index)
{ {
try { try {
return formats.at(index); return formats.at(index);
} }
catch (...) { catch (...) {
return NULL; return FormatPtr();
} }
} }
/////////////// ///////////////
// By filename // 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(); size_t len = formats.size();
for (size_t i=0;i<len;i++) { for (size_t i=0;i<len;i++) {
@ -103,18 +103,18 @@ const Format* FormatManager::GetFormatFromFilename(const String &filename,bool r
if (filename.EndsWith(exts[j])) return formats[i]; if (filename.EndsWith(exts[j])) return formats[i];
} }
} }
return NULL; return FormatPtr();
} }
////////////////// //////////////////
// By format name // By format name
const Format* FormatManager::GetFormatFromName(const String &name) const FormatPtr FormatManager::GetFormatFromName(const String &name)
{ {
size_t len = formats.size(); size_t len = formats.size();
for (size_t i=0;i<len;i++) { for (size_t i=0;i<len;i++) {
if (name == formats[i]->GetName()) return formats[i]; if (name == formats[i]->GetName()) return formats[i];
} }
return NULL; return FormatPtr();
} }

View File

@ -86,7 +86,7 @@ void FormatHandlerASS::Load(wxInputStream &file,const String encoding)
int version = 1; int version = 1;
wxString curGroup = L"-"; wxString curGroup = L"-";
wxString prevGroup = L"-"; wxString prevGroup = L"-";
Section *section = NULL; SectionPtr section = SectionPtr();
// Read file // Read file
while (reader.HasMoreLines()) { while (reader.HasMoreLines()) {
@ -108,7 +108,7 @@ void FormatHandlerASS::Load(wxInputStream &file,const String encoding)
if (cur[0] == L'[') continue; if (cur[0] == L'[') continue;
// Create and insert line // Create and insert line
SectionEntry *entry = MakeEntry(cur,section,version); SectionEntryPtr entry = MakeEntry(cur,section,version);
if (entry) section->AddEntry(entry); if (entry) section->AddEntry(entry);
} }
@ -127,11 +127,11 @@ void FormatHandlerASS::Load(wxInputStream &file,const String encoding)
/////////////// ///////////////
// Create line // Create line
SectionEntry *FormatHandlerASS::MakeEntry(const String &data,Section *section,int version) SectionEntryPtr FormatHandlerASS::MakeEntry(const String &data,SectionPtr section,int version)
{ {
// Variables // Variables
const String group = section->GetName(); const String group = section->GetName();
SectionEntry *final = NULL; SectionEntryPtr final;
// Attachments // Attachments
if (group == _T("Fonts") || group == _T("Graphics")) { 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")) { else if (group == _T("Events")) {
// Dialogue lines // Dialogue lines
if ((data.Left(9) == _T("Dialogue:") || data.Left(8) == _T("Comment:"))) { if ((data.Left(9) == _T("Dialogue:") || data.Left(8) == _T("Comment:"))) {
DialogueASS *diag = new DialogueASS(data,version); shared_ptr<DialogueASS> diag (new DialogueASS(data,version));
final = diag; 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 // 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)); section->SetProperty(_T("Format"),data.Mid(7).Trim(true).Trim(false));
} }
// Garbage // Garbage/hard comments
else { else {
// TODO // TODO
} }
@ -164,12 +160,8 @@ SectionEntry *FormatHandlerASS::MakeEntry(const String &data,Section *section,in
// Styles // Styles
else if (group == _T("V4+ Styles")) { else if (group == _T("V4+ Styles")) {
if (data.Left(6) == _T("Style:")) { if (data.Left(6) == _T("Style:")) {
StyleASS *style = new StyleASS(data,version); shared_ptr<StyleASS> style (new StyleASS(data,version));
final = style; 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:")) { if (data.Left(7) == _T("Format:")) {
section->SetProperty(_T("Format"),data.Mid(7).Trim(true).Trim(false)); 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 // Script info
else if (group == _T("Script Info")) { else if (group == _T("Script Info")) {
// Discard comments // Discard comments
if (data.Left(1) == _T(";")) return NULL; if (data.Left(1) == _T(";")) return SectionEntryPtr();
// Parse property // Parse property
size_t pos = data.Find(_T(':')); 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 key = data.Left(pos).Trim(true).Trim(false);
wxString value = data.Mid(pos+1).Trim(true).Trim(false); wxString value = data.Mid(pos+1).Trim(true).Trim(false);
// Insert property // Insert property
section->SetProperty(key,value); section->SetProperty(key,value);
return NULL; return SectionEntryPtr();
} }
// Return entry // Return entry

View File

@ -48,7 +48,7 @@ namespace Aegilib {
// Advanced Substation Alpha format handler // Advanced Substation Alpha format handler
class FormatHandlerASS : public FormatHandler { class FormatHandlerASS : public FormatHandler {
private: 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); void ProcessGroup(String cur,String &curGroup,int &version);
Model &model; Model &model;
@ -65,7 +65,7 @@ namespace Aegilib {
String GetName() const { return L"Advanced Substation Alpha"; } String GetName() const { return L"Advanced Substation Alpha"; }
StringArray GetReadExtensions() const; StringArray GetReadExtensions() const;
StringArray GetWriteExtensions() 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 CanStoreText() const { return true; }
bool CanUseTime() const { return true; } bool CanUseTime() const { return true; }

View File

@ -39,7 +39,7 @@ using namespace Aegilib;
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
// Adds a listener to be notified whenever things change // Adds a listener to be notified whenever things change
void Model::AddListener(View *listener) void Model::AddListener(ViewPtr listener)
{ {
wxASSERT(listener); wxASSERT(listener);
listeners.push_back(listener); listeners.push_back(listener);
@ -86,7 +86,7 @@ Manipulator Model::CreateAntiManipulator(const Manipulator &src)
////////////////// //////////////////
// Load subtitles // 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 // Autodetect format
if (format == NULL) { if (format == NULL) {
@ -97,20 +97,17 @@ void Model::Load(wxInputStream &input,const Format *format,const String encoding
} }
// Get handler // Get handler
FormatHandler *handler = format->GetHandler(*this); FormatHandlerPtr handler = format->GetHandler(*this);
if (!handler) throw Exception(Exception::No_Format_Handler); if (!handler) throw Exception(Exception::No_Format_Handler);
// Load // Load
handler->Load(input,encoding); handler->Load(input,encoding);
// Clean up
delete handler;
} }
////////////////// //////////////////
// Save subtitles // 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) output;
(void) format; (void) format;
@ -123,7 +120,7 @@ void Model::Save(wxOutputStream &output,const Format *format,const String encodi
// Load a file // Load a file
void Model::LoadFile(const String filename,const String encoding) 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); wxFileInputStream stream(filename);
Load(stream,handler,encoding); Load(stream,handler,encoding);
} }
@ -133,7 +130,7 @@ void Model::LoadFile(const String filename,const String encoding)
// Save a file // Save a file
void Model::SaveFile(const String filename,const String encoding) 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); wxFileOutputStream stream(filename);
Save(stream,handler,encoding); Save(stream,handler,encoding);
} }
@ -141,13 +138,13 @@ void Model::SaveFile(const String filename,const String encoding)
////////////////// //////////////////
// Gets a section // Gets a section
Section* Model::GetSection(String name) const SectionPtr Model::GetSection(String name) const
{ {
std::list<Section*>::const_iterator cur; std::list<SectionPtr>::const_iterator cur;
for (cur=sections.begin();cur!=sections.end();cur++) { for (cur=sections.begin();cur!=sections.end();cur++) {
if ((*cur)->GetName() == name) return *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 // Inserts a new section
void Model::AddSection(String name) void Model::AddSection(String name)
{ {
Section *prev = GetSection(name); SectionPtr prev = GetSection(name);
if (prev) throw Exception(Exception::Section_Already_Exists); if (prev) throw Exception(Exception::Section_Already_Exists);
sections.push_back(new Section(name)); sections.push_back(SectionPtr(new Section(name)));
} }

View File

@ -5,6 +5,7 @@
#include <vector> #include <vector>
#include <list> #include <list>
#include <map> #include <map>
#include "tr1.h"
// wxWidgets // wxWidgets
#ifdef _MSC_VER #ifdef _MSC_VER

View File

@ -46,16 +46,9 @@ Section::Section(String _name)
} }
//////////////
// Destructor
Section::~Section()
{
}
/////////////////// ///////////////////
// Append an entry // Append an entry
void Section::AddEntry(SectionEntry *entry) void Section::AddEntry(SectionEntryPtr entry)
{ {
entries.push_back(entry); entries.push_back(entry);
} }

View File

@ -35,6 +35,8 @@
#include "section_entry.h" #include "section_entry.h"
#include "section_entry_dialogue.h"
#include "section_entry_style.h"
using namespace Aegilib; using namespace Aegilib;
@ -45,3 +47,25 @@ const String& SectionEntry::EmptyString() const
static const String str = _T(""); static const String str = _T("");
return str; return str;
} }
const SectionEntryPlainPtr SectionEntry::GetAsPlain(const SectionEntryPtr &ptr)
{
(void) ptr; return SectionEntryPlainPtr();
}
const SectionEntryDialoguePtr SectionEntry::GetAsDialogue(const SectionEntryPtr &ptr)
{
return dynamic_pointer_cast<SectionEntryDialogue>(ptr);
}
const SectionEntryStylePtr SectionEntry::GetAsStyle(const SectionEntryPtr &ptr)
{
return dynamic_pointer_cast<SectionEntryStyle>(ptr);
}
const SectionEntryFilePtr SectionEntry::GetAsFile(const SectionEntryPtr &ptr)
{
(void) ptr; return SectionEntryFilePtr();
}
const SectionEntryRawPtr SectionEntry::GetAsRaw(const SectionEntryPtr &ptr)
{
(void) ptr; return SectionEntryRawPtr();
}

View File

@ -53,7 +53,6 @@ TextFileReader::TextFileReader(wxInputStream &stream,Aegilib::String enc,bool _t
: file(stream) : file(stream)
{ {
// Setup // Setup
customConv = false;
trim = _trim; trim = _trim;
// Set encoding // Set encoding
@ -66,8 +65,6 @@ TextFileReader::TextFileReader(wxInputStream &stream,Aegilib::String enc,bool _t
////////////// //////////////
// Destructor // Destructor
TextFileReader::~TextFileReader() { TextFileReader::~TextFileReader() {
// Clean up conversion
if (customConv) delete conv;
} }
@ -77,11 +74,9 @@ void TextFileReader::SetEncodingConfiguration() {
// Set encoding configuration // Set encoding configuration
swap = false; swap = false;
Is16 = false; Is16 = false;
customConv = false; conv = shared_ptr<wxMBConv>();
conv = NULL;
if (encoding == _T("UTF-8")) { if (encoding == _T("UTF-8")) {
conv = new wxMBConvUTF8; conv = shared_ptr<wxMBConv> (new wxMBConvUTF8);
customConv = true;
} }
else if (encoding == _T("UTF-16LE")) { else if (encoding == _T("UTF-16LE")) {
Is16 = true; Is16 = true;
@ -91,15 +86,13 @@ void TextFileReader::SetEncodingConfiguration() {
swap = true; swap = true;
} }
else if (encoding == _T("UTF-7")) { else if (encoding == _T("UTF-7")) {
conv = new wxCSConv(encoding); conv = shared_ptr<wxMBConv>(new wxCSConv(encoding));
customConv = true;
} }
else if (encoding == _T("Local")) { else if (encoding == _T("Local")) {
conv = wxConvCurrent; conv = shared_ptr<wxMBConv> (wxConvCurrent,NullDeleter());
} }
else { else {
conv = new wxCSConv(encoding); conv = shared_ptr<wxMBConv> (new wxCSConv(encoding));
customConv = true;
} }
} }

View File

@ -47,10 +47,9 @@ namespace Aegilib {
private: private:
wxString encoding; wxString encoding;
wxInputStream &file; wxInputStream &file;
wxMBConv *conv; shared_ptr<wxMBConv> conv;
bool Is16; bool Is16;
bool swap; bool swap;
bool customConv;
bool trim; bool trim;
void SetEncodingConfiguration(); void SetEncodingConfiguration();

View File

@ -42,11 +42,10 @@ using namespace Aegilib;
// Constructor // Constructor
Tokenizer::Tokenizer(String string,String token) Tokenizer::Tokenizer(String string,String token)
{ {
tkn = new wxStringTokenizer(string,token,wxTOKEN_RET_EMPTY_ALL); tkn = shared_ptr<wxStringTokenizer> (new wxStringTokenizer(string,token,wxTOKEN_RET_EMPTY_ALL));
} }
Tokenizer::~Tokenizer() Tokenizer::~Tokenizer()
{ {
delete tkn;
} }

View File

@ -38,5 +38,7 @@ using namespace Aegilib;
void View::Register(Model &model) void View::Register(Model &model)
{ {
model.AddListener(this); (void) model;
// TODO: change this
//model.AddListener(this);
} }