Some interface clean up.
Originally committed to SVN as r2477.
This commit is contained in:
parent
f279bc2a14
commit
c7f8ba6ca8
11 changed files with 101 additions and 41 deletions
|
@ -319,6 +319,10 @@
|
||||||
<Filter
|
<Filter
|
||||||
Name="Formats"
|
Name="Formats"
|
||||||
>
|
>
|
||||||
|
<File
|
||||||
|
RelativePath=".\src\format_handler.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\src\format_handler.h"
|
RelativePath=".\src\format_handler.h"
|
||||||
>
|
>
|
||||||
|
|
|
@ -66,6 +66,7 @@ namespace Athenasub {
|
||||||
class IDeltaCoder;
|
class IDeltaCoder;
|
||||||
class CController;
|
class CController;
|
||||||
class CAction;
|
class CAction;
|
||||||
|
class IAction;
|
||||||
|
|
||||||
|
|
||||||
// Smart pointers
|
// Smart pointers
|
||||||
|
@ -83,6 +84,7 @@ namespace Athenasub {
|
||||||
typedef shared_ptr<INotification> Notification;
|
typedef shared_ptr<INotification> Notification;
|
||||||
typedef shared_ptr<ISection> Section;
|
typedef shared_ptr<ISection> Section;
|
||||||
typedef shared_ptr<IDeltaCoder> DeltaCoder;
|
typedef shared_ptr<IDeltaCoder> DeltaCoder;
|
||||||
|
typedef shared_ptr<IAction> Action;
|
||||||
|
|
||||||
|
|
||||||
// Const smart pointers
|
// Const smart pointers
|
||||||
|
@ -100,27 +102,6 @@ namespace Athenasub {
|
||||||
|
|
||||||
// Model
|
// Model
|
||||||
class IModel {
|
class IModel {
|
||||||
friend class CFormatHandler;
|
|
||||||
friend class CActionList;
|
|
||||||
friend class CController;
|
|
||||||
friend class CAction;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void ProcessActionList(CActionList &actionList,int type=0) = 0;
|
|
||||||
|
|
||||||
virtual void Undo(const String owner="") = 0;
|
|
||||||
virtual void Redo(const String owner="") = 0;
|
|
||||||
virtual void ActivateStack(ActionStack stack,bool isUndo,const String &owner) = 0;
|
|
||||||
|
|
||||||
virtual void DispatchNotifications(Notification notification) const = 0;
|
|
||||||
|
|
||||||
virtual void Clear() = 0;
|
|
||||||
virtual void Load(Reader &input,Format format=Format()) = 0;
|
|
||||||
|
|
||||||
virtual Section AddSection(String name) = 0;
|
|
||||||
virtual Section GetMutableSection(String name) = 0;
|
|
||||||
virtual Section GetMutableSectionByIndex(size_t index) = 0;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~IModel() {}
|
virtual ~IModel() {}
|
||||||
|
|
||||||
|
@ -335,8 +316,6 @@ namespace Athenasub {
|
||||||
|
|
||||||
|
|
||||||
// Action interface
|
// Action interface
|
||||||
class IAction;
|
|
||||||
typedef shared_ptr<IAction> Action;
|
|
||||||
class IAction {
|
class IAction {
|
||||||
public:
|
public:
|
||||||
virtual ~IAction() {}
|
virtual ~IAction() {}
|
||||||
|
@ -415,7 +394,6 @@ namespace Athenasub {
|
||||||
class ILibAthenaSub {
|
class ILibAthenaSub {
|
||||||
public:
|
public:
|
||||||
virtual ~ILibAthenaSub() {}
|
virtual ~ILibAthenaSub() {}
|
||||||
|
|
||||||
virtual Model CreateModel()=0;
|
virtual Model CreateModel()=0;
|
||||||
};
|
};
|
||||||
typedef shared_ptr<ILibAthenaSub> LibAthenaSub;
|
typedef shared_ptr<ILibAthenaSub> LibAthenaSub;
|
||||||
|
|
|
@ -48,6 +48,16 @@ CAction::CAction(Model _model)
|
||||||
if (!model) THROW_ATHENA_EXCEPTION(Exception::Internal_Error);
|
if (!model) THROW_ATHENA_EXCEPTION(Exception::Internal_Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Model CAction::GetModel() const
|
||||||
|
{
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
Section CAction::GetSection(String name) const
|
||||||
|
{
|
||||||
|
return static_pointer_cast<CModel>(model)->GetMutableSection(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////// Insert line /////////////////////////////
|
///////////////////////////// Insert line /////////////////////////////
|
||||||
|
|
||||||
|
|
|
@ -43,13 +43,13 @@ namespace Athenasub {
|
||||||
// Action base class
|
// Action base class
|
||||||
class CAction : public IAction {
|
class CAction : public IAction {
|
||||||
private:
|
private:
|
||||||
mutable Model model;
|
Model model;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CAction(Model model);
|
CAction(Model model);
|
||||||
|
|
||||||
Model GetModel() const { return model; }
|
Model GetModel() const;
|
||||||
Section GetSection(String name) const { return model->GetMutableSection(name); }
|
Section GetSection(String name) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Insert line
|
// Insert line
|
||||||
|
|
|
@ -41,7 +41,7 @@ using namespace Athenasub;
|
||||||
///////////////
|
///////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
CActionList::CActionList(weak_ptr<IModel> _model,String _actionName,const String _owner,bool _undoAble)
|
CActionList::CActionList(weak_ptr<IModel> _model,String _actionName,const String _owner,bool _undoAble)
|
||||||
: model(_model), owner(_owner), undoAble(_undoAble)
|
: model(dynamic_pointer_cast<CModel>(Model(_model))), owner(_owner), undoAble(_undoAble)
|
||||||
{
|
{
|
||||||
valid = false;
|
valid = false;
|
||||||
Start(_actionName);
|
Start(_actionName);
|
||||||
|
@ -96,7 +96,7 @@ void CActionList::Start(const String name)
|
||||||
void CActionList::Finish()
|
void CActionList::Finish()
|
||||||
{
|
{
|
||||||
if (valid) {
|
if (valid) {
|
||||||
Model(model)->ProcessActionList(*this);
|
shared_ptr<CModel>(model)->ProcessActionList(*this);
|
||||||
actions.clear();
|
actions.clear();
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ void CActionList::RemoveLine(int position,const String section)
|
||||||
// Insert a "modify line" action
|
// Insert a "modify line" action
|
||||||
Entry CActionList::ModifyLine(int position,const String section)
|
Entry CActionList::ModifyLine(int position,const String section)
|
||||||
{
|
{
|
||||||
Section sect = Model(model)->GetMutableSection(section);
|
Section sect = shared_ptr<CModel>(model)->GetMutableSection(section);
|
||||||
Entry entry = sect->GetEntry(position)->Clone();
|
Entry entry = sect->GetEntry(position)->Clone();
|
||||||
Action action = Action (new ActionModify(model.lock(),entry,position,section,false));
|
Action action = Action (new ActionModify(model.lock(),entry,position,section,false));
|
||||||
AddAction(action);
|
AddAction(action);
|
||||||
|
@ -138,7 +138,7 @@ Entry CActionList::ModifyLine(int position,const String section)
|
||||||
std::vector<Entry> CActionList::ModifyLines(Selection selection,const String section)
|
std::vector<Entry> CActionList::ModifyLines(Selection selection,const String section)
|
||||||
{
|
{
|
||||||
// Get section
|
// Get section
|
||||||
Section sect = Model(model)->GetMutableSection(section);
|
Section sect = shared_ptr<CModel>(model)->GetMutableSection(section);
|
||||||
|
|
||||||
// Generate entries
|
// Generate entries
|
||||||
std::vector<Entry> entries(selection->GetCount());
|
std::vector<Entry> entries(selection->GetCount());
|
||||||
|
|
|
@ -56,7 +56,7 @@ namespace Athenasub {
|
||||||
private:
|
private:
|
||||||
String actionName;
|
String actionName;
|
||||||
String owner;
|
String owner;
|
||||||
weak_ptr<IModel> model;
|
weak_ptr<CModel> model;
|
||||||
std::list<Action> actions;
|
std::list<Action> actions;
|
||||||
bool valid;
|
bool valid;
|
||||||
bool undoAble;
|
bool undoAble;
|
||||||
|
|
|
@ -46,7 +46,7 @@ using namespace Athenasub;
|
||||||
///////////////
|
///////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
CController::CController(Model _model)
|
CController::CController(Model _model)
|
||||||
: model(_model)
|
: model(dynamic_pointer_cast<CModel>(_model))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace Athenasub {
|
||||||
friend class CModel;
|
friend class CModel;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Model model;
|
shared_ptr<CModel> model;
|
||||||
CController (Model model);
|
CController (Model model);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
68
athenasub/src/format_handler.cpp
Normal file
68
athenasub/src/format_handler.cpp
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
// 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/ATHENASUB
|
||||||
|
//
|
||||||
|
// Website: http://www.aegisub.net
|
||||||
|
// Contact: mailto:amz@aegisub.net
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "format_handler.h"
|
||||||
|
#include "model.h"
|
||||||
|
using namespace Athenasub;
|
||||||
|
|
||||||
|
|
||||||
|
Section CFormatHandler::AddSection(IModel &model,String name) const
|
||||||
|
{
|
||||||
|
return (dynamic_cast<CModel*>(&model))->AddSection(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConstSection CFormatHandler::GetSection(const IModel &model,String name) const
|
||||||
|
{
|
||||||
|
return model.GetSection(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConstSection CFormatHandler::GetSectionByIndex(const IModel &model,size_t index) const
|
||||||
|
{
|
||||||
|
return model.GetSectionByIndex(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
Section CFormatHandler::GetSection(IModel &model,String name) const
|
||||||
|
{
|
||||||
|
return (dynamic_cast<CModel*>(&model))->GetMutableSection(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
Section CFormatHandler::GetSectionByIndex(IModel &model,size_t index) const
|
||||||
|
{
|
||||||
|
return (dynamic_cast<CModel*>(&model))->GetMutableSectionByIndex(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t CFormatHandler::GetSectionCount(const IModel &model) const {
|
||||||
|
return model.GetSectionCount();
|
||||||
|
}
|
|
@ -45,12 +45,12 @@ namespace Athenasub {
|
||||||
protected:
|
protected:
|
||||||
virtual ~CFormatHandler() {}
|
virtual ~CFormatHandler() {}
|
||||||
|
|
||||||
Section AddSection(IModel &model,String name) const { return model.AddSection(name); }
|
Section AddSection(IModel &model,String name) const;
|
||||||
ConstSection GetSection(const IModel &model,String name) const { return model.GetSection(name); }
|
ConstSection GetSection(const IModel &model,String name) const;
|
||||||
ConstSection GetSectionByIndex(const IModel &model,size_t index) const { return model.GetSectionByIndex(index); }
|
ConstSection GetSectionByIndex(const IModel &model,size_t index) const;
|
||||||
Section GetSection(IModel &model,String name) const { return model.GetMutableSection(name); }
|
Section GetSection(IModel &model,String name) const;
|
||||||
Section GetSectionByIndex(IModel &model,size_t index) const { return model.GetMutableSectionByIndex(index); }
|
Section GetSectionByIndex(IModel &model,size_t index) const;
|
||||||
size_t GetSectionCount(const IModel &model) const { return model.GetSectionCount(); }
|
size_t GetSectionCount(const IModel &model) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//CFormatHandler(IModel& _model) : model(_model) {}
|
//CFormatHandler(IModel& _model) : model(_model) {}
|
||||||
|
|
|
@ -48,7 +48,7 @@ Athenasub::TextReaderCache::TextReaderCache(shared_ptr<TextReader> src)
|
||||||
String TextReaderCache::ReadLineFromFile()
|
String TextReaderCache::ReadLineFromFile()
|
||||||
{
|
{
|
||||||
if (bufferPos == buffer.size()) {
|
if (bufferPos == buffer.size()) {
|
||||||
LoadMore(1000000);
|
LoadMore(1);
|
||||||
}
|
}
|
||||||
if (bufferPos == buffer.size()) {
|
if (bufferPos == buffer.size()) {
|
||||||
return "";
|
return "";
|
||||||
|
|
Loading…
Reference in a new issue