diff --git a/aegilib/aegilib_2008.vcproj b/aegilib/aegilib_2008.vcproj index 0a4e6b814..0aa3c6210 100644 --- a/aegilib/aegilib_2008.vcproj +++ b/aegilib/aegilib_2008.vcproj @@ -89,7 +89,7 @@ Name="Release|Win32" OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="4" + ConfigurationType="2" CharacterSet="1" WholeProgramOptimization="1" > @@ -139,12 +139,15 @@ Name="VCPreLinkEventTool" /> + @@ -154,6 +157,9 @@ + @@ -323,7 +329,7 @@ Name="Formats" > +#include typedef Athenasub::ILibAthenaSub* (__stdcall *CreateLibAthenasubPtr)(const char*); namespace Athenasub { inline LibAthenaSub Create(HMODULE module,const char* hostName) { - CreateLibAthenasubPtr CreateLib = (CreateLibAthenasubPtr)GetProcAddress(module,"CreateLibAthenaSub"); + CreateLibAthenasubPtr CreateLib = (CreateLibAthenasubPtr)GetProcAddress(module,"CreateLibAthenasub"); + printf("Pointer at %x.\n",CreateLib); return LibAthenaSub(CreateLib(hostName)); } } diff --git a/aegilib/include/athenasub/interfaces.h b/aegilib/include/athenasub/interfaces.h index d61ec8317..259d47eca 100644 --- a/aegilib/include/athenasub/interfaces.h +++ b/aegilib/include/athenasub/interfaces.h @@ -128,7 +128,7 @@ namespace Athenasub { virtual size_t GetSectionCount() const = 0; public: - virtual ~IModel(); + virtual ~IModel() {} virtual Controller CreateController()=0; virtual Format GetFormat() const=0; @@ -338,7 +338,7 @@ namespace Athenasub { virtual String GetName() const = 0; virtual StringArray GetReadExtensions() const = 0; virtual StringArray GetWriteExtensions() const = 0; - //virtual FormatHandler GetHandler(Model &model) const = 0; + virtual FormatHandler GetHandler(IModel &model) const = 0; virtual bool CanStoreText() const = 0; virtual bool CanStoreImages() const = 0; @@ -363,6 +363,9 @@ namespace Athenasub { class IFormatHandler { public: virtual ~IFormatHandler() {} + + virtual void Load(wxInputStream &file,const String encoding) = 0; + virtual void Save(wxOutputStream &file,const String encoding) = 0; }; @@ -372,10 +375,10 @@ namespace Athenasub { class IAction { public: virtual ~IAction() {} - virtual Action GetAntiAction(ConstModel model) const = 0; - virtual void Execute(Model model) = 0; + virtual Action GetAntiAction(const IModel& model) const = 0; + virtual void Execute(IModel& model) = 0; - Section GetSection(Model model,const String &name) const { return model->GetSection(name); } + Section GetSection(const IModel& model,const String &name) const { return model.GetSection(name); } }; @@ -387,7 +390,7 @@ namespace Athenasub { virtual String GetName() const = 0; virtual String GetOwner() const = 0; - virtual void AddAction(const Action action) = 0; + virtual void AddAction(Action action) = 0; virtual void Finish() = 0; virtual void InsertLine(Entry line,int position=-1,const String section=L"") = 0; @@ -422,7 +425,7 @@ namespace Athenasub { virtual void RemoveEntryByIndex(size_t index) = 0; virtual void RemoveEntry(Entry entry) = 0; virtual Entry GetEntry(size_t index) const = 0; - virtual Entry& GetEntryRef(size_t index) const = 0; + virtual Entry& GetEntryRef(size_t index) = 0; virtual size_t GetEntryCount() const = 0; }; @@ -448,8 +451,8 @@ namespace Athenasub { // Operators - Time operator+(const ITime& p1,int p2) { Time res = p1.Clone(); res->SetMS(res->GetMS()+p2); return res; } - Time operator-(const ITime& p1,int p2) { Time res = p1.Clone(); res->SetMS(res->GetMS()-p2); return res; } - bool operator==(const ITime& p1,const ITime& p2) { return p1.GetMS() == p2.GetMS(); } + inline Time operator+(const ITime& p1,int p2) { Time res = p1.Clone(); res->SetMS(res->GetMS()+p2); return res; } + inline Time operator-(const ITime& p1,int p2) { Time res = p1.Clone(); res->SetMS(res->GetMS()-p2); return res; } + inline bool operator==(const ITime& p1,const ITime& p2) { return p1.GetMS() == p2.GetMS(); } } diff --git a/aegilib/src/action.cpp b/aegilib/src/action.cpp index a6b70102a..133ffb97a 100644 --- a/aegilib/src/action.cpp +++ b/aegilib/src/action.cpp @@ -48,7 +48,7 @@ ActionInsert::ActionInsert(Entry data,int line,const String &sName) ///////////////////////////////// // Create anti-action for insert -Action ActionInsert::GetAntiAction(ConstModel model) const +Action ActionInsert::GetAntiAction(const IModel& model) const { (void) model; String sect = section; @@ -59,7 +59,7 @@ Action ActionInsert::GetAntiAction(ConstModel model) const ///////////////////// // Execute insertion -void ActionInsert::Execute(Model model) +void ActionInsert::Execute(IModel& model) { // Find the section to insert it on String sectionName = section; @@ -83,9 +83,9 @@ ActionRemove::ActionRemove(int line,const String &sName) ///////////////////////////////// // Create anti-action for remove -Action ActionRemove::GetAntiAction(ConstModel model) const +Action ActionRemove::GetAntiAction(const IModel& model) const { - SectionPtr sect = GetSection(model,section); + Section sect = GetSection(model,section); Entry entry = sect->GetEntry(lineNumber); return Action(new ActionInsert(entry,lineNumber,section)); } @@ -93,12 +93,12 @@ Action ActionRemove::GetAntiAction(ConstModel model) const /////////////////// // Execute removal -void ActionRemove::Execute(Model model) +void ActionRemove::Execute(IModel& model) { // Find the section to remote it from String sect = section; if (sect.IsEmpty()) THROW_ATHENA_EXCEPTION(Exception::TODO); // TODO - SectionPtr section = GetSection(model,sect); + Section section = GetSection(model,sect); // Remove the line section->RemoveEntryByIndex(lineNumber); @@ -118,7 +118,7 @@ ActionModify::ActionModify(shared_ptr _delta,int line,const String &sName) ///////////////////////////////// // Create anti-action for insert -Action ActionModify::GetAntiAction(ConstModel model) const +Action ActionModify::GetAntiAction(const IModel& model) const { // Get section and original line Section sect = GetSection(model,section); @@ -142,7 +142,7 @@ Action ActionModify::GetAntiAction(ConstModel model) const ///////////////////// // Execute insertion -void ActionModify::Execute(Model model) +void ActionModify::Execute(IModel& model) { // Find the section to modify String sectionName = section; @@ -163,10 +163,10 @@ void ActionModify::Execute(Model model) ActionModifyBatch::ActionModifyBatch(std::vector _entries, std::vector > _deltas, Selection _selection,const String &_section,bool _noTextFields) : entries(_entries), deltas(_deltas), selection(_selection), section(_section), noTextFields(_noTextFields) {} -Action ActionModifyBatch::GetAntiAction(ConstModel model) const +Action ActionModifyBatch::GetAntiAction(const IModel& model) const { // Get section - SectionPtr sect = GetSection(model,section); + Section sect = GetSection(model,section); size_t len = selection->GetCount(); std::vector _deltas(len); std::vector oldEntries(len); @@ -190,7 +190,7 @@ Action ActionModifyBatch::GetAntiAction(ConstModel model) const return Action(new ActionModifyBatch(oldEntries,_deltas,selection,section,noTextFields)); } -void ActionModifyBatch::Execute(Model model) +void ActionModifyBatch::Execute(IModel& model) { // Find the section to modify size_t len = selection->GetCount(); diff --git a/aegilib/src/action.h b/aegilib/src/action.h index c317fd8e2..7ae234b29 100644 --- a/aegilib/src/action.h +++ b/aegilib/src/action.h @@ -51,8 +51,8 @@ namespace Athenasub { ActionInsert(Entry entry,int line,const String §ion); ~ActionInsert() {} - Action GetAntiAction(ConstModel model) const; - void Execute(Model model); + Action GetAntiAction(const IModel& model) const; + void Execute(IModel& model); }; // Remove line @@ -65,8 +65,8 @@ namespace Athenasub { ActionRemove(int line,const String §ion); ~ActionRemove() {} - Action GetAntiAction(ConstModel model) const; - void Execute(Model model); + Action GetAntiAction(const IModel& model) const; + void Execute(IModel& model); }; // Modify line @@ -83,8 +83,8 @@ namespace Athenasub { ActionModify(shared_ptr delta,int line,const String §ion); ~ActionModify() {} - Action GetAntiAction(ConstModel model) const; - void Execute(Model model); + Action GetAntiAction(const IModel& model) const; + void Execute(IModel& model); }; // Modify several lines @@ -100,7 +100,7 @@ namespace Athenasub { ActionModifyBatch(std::vector entries,std::vector deltas,Selection selection,const String §ion,bool noTextFields); ~ActionModifyBatch() {} - Action GetAntiAction(ConstModel model) const; - void Execute(Model model); + Action GetAntiAction(const IModel& model) const; + void Execute(IModel& model); }; } diff --git a/aegilib/src/actionlist.h b/aegilib/src/actionlist.h index 4dc799e4f..54ed421d8 100644 --- a/aegilib/src/actionlist.h +++ b/aegilib/src/actionlist.h @@ -71,7 +71,7 @@ namespace Athenasub { virtual String GetName() const { return actionName; } virtual String GetOwner() const { return owner; } - virtual void AddAction(const Action action); + virtual void AddAction(Action action); virtual void Finish(); virtual void InsertLine(Entry line,int position=-1,const String section=L""); diff --git a/aegilib/src/controller.cpp b/aegilib/src/controller.cpp index c0fd8d9fc..9dd1ef186 100644 --- a/aegilib/src/controller.cpp +++ b/aegilib/src/controller.cpp @@ -37,6 +37,7 @@ #include "athenasub.h" #include "actionlist.h" #include "format_manager.h" +#include "selection.h" using namespace Athenasub; @@ -159,3 +160,10 @@ ConstEntry CController::GetEntry(size_t n,String section) const if (!sect) THROW_ATHENA_EXCEPTION(Exception::Invalid_Section); return sect->GetEntry(n); } + + +////////////////////// +// Create a selection +Selection CController::CreateSelection() { + return Selection(new CSelection()); +} diff --git a/aegilib/src/exception.cpp b/aegilib/src/exception.cpp index bf4372e31..4f73f0dcb 100644 --- a/aegilib/src/exception.cpp +++ b/aegilib/src/exception.cpp @@ -37,59 +37,3 @@ using namespace Athenasub; -//////////////// -// Constructors -Exception::Exception(ExceptionList _code) -: std::exception(GetMessageChar(_code)) -{ - code = _code; -} - -Exception::Exception(ExceptionList _code,const char *file,const long line) -: std::exception(GetMessageFile(_code,file,line)) -{ - code = _code; -} - - -////////////////////// -// Get message string -const char* Exception::GetMessageChar(int code) -{ - switch (code) { - case Unknown: return "Unknown."; - case No_Format_Handler: return "Could not find a suitable format handler."; - case Invalid_ActionList: return "Invalid manipulator."; - case Section_Already_Exists: return "The specified section already exists in this model."; - case Unknown_Format: return "The specified file format is unknown."; - case Parse_Error: return "Parse error."; - case Unsupported_Format_Feature: return "This feature is not supported by this format."; - case Invalid_Token: return "Invalid type for this token."; - case Out_Of_Range: return "Out of range."; - case Invalid_Section: return "Invalid section."; - case Internal_Error: return "Internal error."; - case TODO: return "TODO"; - } - return "Invalid code."; -} - - -/////////////////////////////////// -// Insert file and line on message -const char* Exception::GetMessageFile(int code,const char *file,long line) -{ - static std::string str = GetMessageChar(code); - str = str + " (" + file + ":"; - char buffer[16]; - _itoa_s(line,buffer,10); - str = str + buffer + ")"; - return str.c_str(); -} - - -//////////// -// Get code -int Exception::GetCode() -{ - return code; -} diff --git a/aegilib/src/format_handler.h b/aegilib/src/format_handler.h index f1741af3a..3f13807ee 100644 --- a/aegilib/src/format_handler.h +++ b/aegilib/src/format_handler.h @@ -43,20 +43,20 @@ namespace Athenasub { // Format handler interface class CFormatHandler : public IFormatHandler { private: - Model model; + IModel& model; protected: virtual ~CFormatHandler() {} - Model GetModel() const { return model; } + IModel& GetModel() const { return model; } - void AddSection(String name) { model->AddSection(name); } - Section GetSection(String name) const { return model->GetSection(name); } - Section GetSectionByIndex(size_t index) const { return model->GetSectionByIndex(index); } - size_t GetSectionCount() const { return model->GetSectionCount(); } + void AddSection(String name) { model.AddSection(name); } + Section GetSection(String name) const { return model.GetSection(name); } + Section GetSectionByIndex(size_t index) const { return model.GetSectionByIndex(index); } + size_t GetSectionCount() const { return model.GetSectionCount(); } public: - CFormatHandler(Model _model) : model(_model) {} + CFormatHandler(IModel& _model) : model(_model) {} virtual void Load(wxInputStream &file,const String encoding) = 0; virtual void Save(wxOutputStream &file,const String encoding) = 0; diff --git a/aegilib/src/format_manager.cpp b/aegilib/src/format_manager.cpp index 3a043d920..26b75dfa3 100644 --- a/aegilib/src/format_manager.cpp +++ b/aegilib/src/format_manager.cpp @@ -41,24 +41,24 @@ using namespace Athenasub; //////// // List -std::vector FormatManager::formats; +std::vector FormatManager::formats; //////////////// // Add a format -void FormatManager::AddFormat(const FormatPtr format) +void FormatManager::AddFormat(const Format format) { formats.push_back(format); } /////////////////////////////////// -// Initialzie all built-in formats +// Initialize all built-in formats void FormatManager::InitializeFormats() { - formats.push_back(FormatPtr(new FormatASS)); - formats.push_back(FormatPtr(new FormatSSA)); - formats.push_back(FormatPtr(new FormatASS2)); + formats.push_back(Format(new FormatASS())); + formats.push_back(Format(new FormatSSA())); + formats.push_back(Format(new FormatASS2())); } @@ -80,20 +80,20 @@ int FormatManager::GetFormatCount() //////////// // By index -const FormatPtr FormatManager::GetFormatByIndex(const int index) +const Format FormatManager::GetFormatByIndex(const int index) { try { return formats.at(index); } catch (...) { - return FormatPtr(); + return Format(); } } /////////////// // By filename -const FormatPtr FormatManager::GetFormatFromFilename(const String &filename,bool read) +const Format FormatManager::GetFormatFromFilename(const String &filename,bool read) { size_t len = formats.size(); for (size_t i=0;iGetName()) return formats[i]; } - return FormatPtr(); + return Format(); } diff --git a/aegilib/src/formats/format_ass.cpp b/aegilib/src/formats/format_ass.cpp index 992c24352..1dec0a742 100644 --- a/aegilib/src/formats/format_ass.cpp +++ b/aegilib/src/formats/format_ass.cpp @@ -113,7 +113,7 @@ void FormatHandlerASS::Load(wxInputStream &file,const String encoding) int version = 1; wxString curGroup = L"-"; wxString prevGroup = L"-"; - SectionPtr section = SectionPtr(); + Section section = Section(); // Read file while (reader.HasMoreLines()) { @@ -136,7 +136,7 @@ void FormatHandlerASS::Load(wxInputStream &file,const String encoding) if (cur[0] == L'[') continue; // Create and insert line - EntryPtr entry = MakeEntry(cur,section,version); + Entry entry = MakeEntry(cur,section,version); if (entry) section->AddEntry(entry); } @@ -171,7 +171,7 @@ void FormatHandlerASS::Save(wxOutputStream &file,const String encoding) size_t len = sections.size(); for (size_t i=0;iGetName(); - EntryPtr final; + Entry final; // Attachments if (group == _T("Fonts") || group == _T("Graphics")) { @@ -229,17 +229,17 @@ EntryPtr FormatHandlerASS::MakeEntry(const String &data,SectionPtr section,int v // Script info else if (group == _T("Script Info")) { // Discard comments - if (data.Left(1) == _T(";")) return EntryPtr(); + if (data.Left(1) == _T(";")) return Entry(); // Parse property size_t pos = data.Find(_T(':')); - if (pos == wxNOT_FOUND) return EntryPtr(); + if (pos == wxNOT_FOUND) return Entry(); 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 EntryPtr(); + return Entry(); } // Unknown group, just leave it intact @@ -331,7 +331,7 @@ void FormatHandlerASS::ProcessGroup(String cur,String &curGroup,int &version) { /////////////////////////////// // Write a section to the file -void FormatHandlerASS::WriteSection(TextFileWriter &writer,SectionPtr section) +void FormatHandlerASS::WriteSection(TextFileWriter &writer,Section section) { // Write name wxString name = section->GetName(); @@ -359,7 +359,7 @@ void FormatHandlerASS::WriteSection(TextFileWriter &writer,SectionPtr section) // Write contents size_t entries = section->GetEntryCount(); for (size_t i=0;iGetEntry(i); + ConstEntry entry = section->GetEntry(i); shared_ptr serial = dynamic_pointer_cast(entry); writer.WriteLineToFile(serial->ToText(formatVersion)); } @@ -374,7 +374,7 @@ void FormatHandlerASS::MakeValid() if (formatVersion != 1) THROW_ATHENA_EXCEPTION(Exception::TODO); // Check for [Script Info] - SectionPtr section = GetSection(L"Script Info"); + Section section = GetSection(L"Script Info"); if (!section) AddSection(L"Script Info"); section = GetSection(L"Script Info"); if (!section) THROW_ATHENA_EXCEPTION(Exception::Internal_Error); diff --git a/aegilib/src/formats/format_ass.h b/aegilib/src/formats/format_ass.h index 3c0961efe..21762e6c9 100644 --- a/aegilib/src/formats/format_ass.h +++ b/aegilib/src/formats/format_ass.h @@ -53,9 +53,9 @@ namespace Athenasub { private: int formatVersion; - Entry MakeEntry(const String &data,SectionPtr section,int version); + Entry MakeEntry(const String &data,Section section,int version); void ProcessGroup(String cur,String &curGroup,int &version); - void WriteSection(TextFileWriter &writer,SectionPtr section); + void WriteSection(TextFileWriter &writer,Section section); void MakeValid(); public: @@ -67,16 +67,23 @@ namespace Athenasub { }; // Advanced Substation Alpha format base class - class FormatASSFamily : public Format { + class FormatASSFamily : public IFormat { public: virtual ~FormatASSFamily() {} bool CanStoreText() const { return true; } + bool CanStoreImages() const { return false; } + bool CanUseFrames() const { return false; } bool CanUseTime() const { return true; } bool HasStyles() const { return true; } bool HasMargins() const { return true; } bool HasActors() const { return true; } + virtual bool HasUserField() const { return false; } + virtual String GetUserFieldName() const { return _T(""); } + + virtual int GetTimingPrecision() const { return 10; } + virtual int GetMaxTime() const { return 35999990; } Dialogue CreateDialogue() const { return Dialogue(new DialogueASS()); } Style CreateStyle() const { return Style(new StyleASS()); } @@ -85,7 +92,7 @@ namespace Athenasub { // Substation Alpha class FormatSSA : public FormatASSFamily { public: - FormatHandler GetHandler(CModel &model) const { return FormatHandler(new FormatHandlerASS(model,0)); } + FormatHandler GetHandler(IModel &model) const { return FormatHandler(new FormatHandlerASS((CModel&)model,0)); } String GetName() const { return L"Substation Alpha"; } StringArray GetReadExtensions() const; StringArray GetWriteExtensions() const; @@ -94,7 +101,7 @@ namespace Athenasub { // Advanced Substation Alpha class FormatASS : public FormatASSFamily { public: - FormatHandler GetHandler(CModel &model) const { return FormatHandler(new FormatHandlerASS(model,1)); } + FormatHandler GetHandler(IModel &model) const { return FormatHandler(new FormatHandlerASS((CModel&)model,1)); } String GetName() const { return L"Advanced Substation Alpha"; } StringArray GetReadExtensions() const; StringArray GetWriteExtensions() const; @@ -103,7 +110,7 @@ namespace Athenasub { // Advanced Substation Alpha 2 class FormatASS2 : public FormatASSFamily { public: - FormatHandler GetHandler(CModel &model) const { return FormatHandler(new FormatHandlerASS(model,2)); } + FormatHandler GetHandler(IModel &model) const { return FormatHandler(new FormatHandlerASS((CModel&)model,2)); } String GetName() const { return L"Advanced Substation Alpha 2"; } StringArray GetReadExtensions() const; StringArray GetWriteExtensions() const; diff --git a/aegilib/src/formats/format_ass_plain.h b/aegilib/src/formats/format_ass_plain.h index b59621ef5..e7f06b640 100644 --- a/aegilib/src/formats/format_ass_plain.h +++ b/aegilib/src/formats/format_ass_plain.h @@ -40,7 +40,7 @@ namespace Athenasub { // Raw line - class PlainASS : public PlainText, public SerializeText { + class PlainASS : public CPlainText, public SerializeText { private: String data; String ToText(int param) const { (void)param; return data; } @@ -51,7 +51,7 @@ namespace Athenasub { // Basic features String GetDefaultGroup() const { return L"Events"; } - EntryPtr Clone() const { return EntryPtr(new PlainASS(*this)); } + Entry Clone() const { return Entry(new PlainASS(*this)); } String GetText() const { return data; } void SetText(const String &_data) { data = _data; } diff --git a/aegilib/src/libathenasub.cpp b/aegilib/src/libathenasub.cpp index 0a365e189..01811f0ad 100644 --- a/aegilib/src/libathenasub.cpp +++ b/aegilib/src/libathenasub.cpp @@ -52,5 +52,7 @@ CLibAthenaSub::CLibAthenaSub(const char* hostName) { Model CLibAthenaSub::CreateModel() { - return Model(new CModel()); + shared_ptr model(new CModel()); + model->SetWeakPtr(model); + return model; } diff --git a/aegilib/src/model.cpp b/aegilib/src/model.cpp index b284479dc..a954c92a2 100644 --- a/aegilib/src/model.cpp +++ b/aegilib/src/model.cpp @@ -35,6 +35,7 @@ #include "Athenasub.h" #include "model.h" +#include "controller.h" using namespace Athenasub; @@ -62,10 +63,10 @@ void CModel::DispatchNotifications(Notification notification) const void CModel::ProcessActionList(ActionList _actionList,int type) { // Copy the list - ActionList actions = ActionList(new CActionList(_actionList)); + shared_ptr actions = shared_ptr(new CActionList(*static_pointer_cast(_actionList))); // Setup undo - ActionList undo = ActionList(new CActionList(actions->model,actions->actionName,actions->owner,actions->undoAble)); + shared_ptr undo = shared_ptr(new CActionList(actions->model,actions->actionName,actions->owner,actions->undoAble)); ActionStack *stack; if (type == 1) stack = &redoStack; else stack = &undoStack; @@ -93,7 +94,7 @@ void CModel::ProcessActionList(ActionList _actionList,int type) ////////////////// // Load subtitles -void CModel::Load(wxInputStream &input,const FormatPtr _format,const String encoding) +void CModel::Load(wxInputStream &input,const Format _format,const String encoding) { // Autodetect format if (!_format) { @@ -104,7 +105,7 @@ void CModel::Load(wxInputStream &input,const FormatPtr _format,const String enco } // Get handler - FormatHandlerPtr handler = _format->GetHandler(*this); + FormatHandler handler = _format->GetHandler(*this); if (!handler) THROW_ATHENA_EXCEPTION(Exception::No_Format_Handler); // Clear the model first @@ -120,7 +121,7 @@ void CModel::Load(wxInputStream &input,const FormatPtr _format,const String enco ////////////////// // Save subtitles -void CModel::Save(wxOutputStream &output,const FormatPtr _format,const String encoding) +void CModel::Save(wxOutputStream &output,const Format _format,const String encoding) { // Use another format if (_format && _format != format) { @@ -129,7 +130,7 @@ void CModel::Save(wxOutputStream &output,const FormatPtr _format,const String en } // Get handler - FormatHandlerPtr handler = format->GetHandler(*this); + FormatHandler handler = format->GetHandler(*this); if (!handler) THROW_ATHENA_EXCEPTION(Exception::No_Format_Handler); // Load @@ -141,15 +142,15 @@ void CModel::Save(wxOutputStream &output,const FormatPtr _format,const String en // Inserts a new section void CModel::AddSection(String name) { - SectionPtr prev = GetSection(name); + Section prev = GetSection(name); if (prev) THROW_ATHENA_EXCEPTION(Exception::Section_Already_Exists); - sections.push_back(SectionPtr(new CSection(name))); + sections.push_back(Section(new CSection(name))); } ////////////////// // Gets a section -SectionPtr CModel::GetSection(String name) const +Section CModel::GetSection(String name) const { size_t len = sections.size(); for (size_t i=0;i sections; + weak_ptr weakThis; + + std::vector
sections; ActionStack undoStack; ActionStack redoStack; ViewList listeners; @@ -86,6 +88,8 @@ namespace Athenasub { Controller CreateController(); Format GetFormat() const { return format; } void AddListener(View listener); + + void SetWeakPtr(weak_ptr ptr) { weakThis = ptr; } }; typedef shared_ptr ModelPtr; diff --git a/aegilib/src/section.cpp b/aegilib/src/section.cpp index 6ec782023..cf239d98e 100644 --- a/aegilib/src/section.cpp +++ b/aegilib/src/section.cpp @@ -97,6 +97,14 @@ Entry CSection::GetEntry(size_t i) const } +////////////////////////////////////// +// Retrieves entry reference by index +Entry& CSection::GetEntryRef(size_t i) +{ + return entries[i]; +} + + ///////////////////////// // Get number of entries size_t CSection::GetEntryCount() const diff --git a/aegilib/src/section.h b/aegilib/src/section.h index b4882869b..9f1078837 100644 --- a/aegilib/src/section.h +++ b/aegilib/src/section.h @@ -73,7 +73,7 @@ namespace Athenasub { void RemoveEntryByIndex(size_t index); void RemoveEntry(Entry entry); Entry GetEntry(size_t index) const; - Entry& GetEntryRef(size_t index) const; + Entry& GetEntryRef(size_t index); size_t GetEntryCount() const; }; typedef shared_ptr SectionPtr; diff --git a/aegilib/src/selection.h b/aegilib/src/selection.h index b8b663973..30bf79b0e 100644 --- a/aegilib/src/selection.h +++ b/aegilib/src/selection.h @@ -41,6 +41,8 @@ namespace Athenasub { // Selection class class CSelection : public ISelection { + friend class CController; + private: std::vector ranges; size_t count; diff --git a/aegilib/test/src/main.cpp b/aegilib/test/src/main.cpp index 59d2a6cc3..188203e61 100644 --- a/aegilib/test/src/main.cpp +++ b/aegilib/test/src/main.cpp @@ -50,15 +50,21 @@ int main() try { // Set up the lib + cout << "Loading library... "; HMODULE module = LoadLibrary(_T("athenasub.dll")); if (!module) { cout << "Failed to load library, aborting.\n"; + system("pause"); return 1; } + cout << "Done.\nCreating library..."; LibAthenaSub lib = Athenasub::Create(module,"Aegilib test program"); + cout << "Done.\n"; // Subtitles model + cout << "Creating model... "; Model subs = lib->CreateModel(); + cout << "Creating controller...\n"; Controller control = subs->CreateController(); wxStopWatch timer; diff --git a/aegilib/test/test_2008.vcproj b/aegilib/test/test_2008.vcproj index 0c0d2fe8c..4d836164d 100644 --- a/aegilib/test/test_2008.vcproj +++ b/aegilib/test/test_2008.vcproj @@ -139,6 +139,7 @@ />