Some interface clean up.

Originally committed to SVN as r2477.
This commit is contained in:
Rodrigo Braz Monteiro 2008-11-22 19:52:38 +00:00
parent f279bc2a14
commit c7f8ba6ca8
11 changed files with 101 additions and 41 deletions

View File

@ -319,6 +319,10 @@
<Filter
Name="Formats"
>
<File
RelativePath=".\src\format_handler.cpp"
>
</File>
<File
RelativePath=".\src\format_handler.h"
>

View File

@ -66,6 +66,7 @@ namespace Athenasub {
class IDeltaCoder;
class CController;
class CAction;
class IAction;
// Smart pointers
@ -83,6 +84,7 @@ namespace Athenasub {
typedef shared_ptr<INotification> Notification;
typedef shared_ptr<ISection> Section;
typedef shared_ptr<IDeltaCoder> DeltaCoder;
typedef shared_ptr<IAction> Action;
// Const smart pointers
@ -100,27 +102,6 @@ namespace Athenasub {
// Model
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:
virtual ~IModel() {}
@ -335,8 +316,6 @@ namespace Athenasub {
// Action interface
class IAction;
typedef shared_ptr<IAction> Action;
class IAction {
public:
virtual ~IAction() {}
@ -415,7 +394,6 @@ namespace Athenasub {
class ILibAthenaSub {
public:
virtual ~ILibAthenaSub() {}
virtual Model CreateModel()=0;
};
typedef shared_ptr<ILibAthenaSub> LibAthenaSub;

View File

@ -48,6 +48,16 @@ CAction::CAction(Model _model)
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 /////////////////////////////

View File

@ -43,13 +43,13 @@ namespace Athenasub {
// Action base class
class CAction : public IAction {
private:
mutable Model model;
Model model;
protected:
CAction(Model model);
Model GetModel() const { return model; }
Section GetSection(String name) const { return model->GetMutableSection(name); }
Model GetModel() const;
Section GetSection(String name) const;
};
// Insert line

View File

@ -41,7 +41,7 @@ using namespace Athenasub;
///////////////
// Constructor
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;
Start(_actionName);
@ -96,7 +96,7 @@ void CActionList::Start(const String name)
void CActionList::Finish()
{
if (valid) {
Model(model)->ProcessActionList(*this);
shared_ptr<CModel>(model)->ProcessActionList(*this);
actions.clear();
valid = false;
}
@ -125,7 +125,7 @@ void CActionList::RemoveLine(int position,const String section)
// Insert a "modify line" action
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();
Action action = Action (new ActionModify(model.lock(),entry,position,section,false));
AddAction(action);
@ -138,7 +138,7 @@ Entry CActionList::ModifyLine(int position,const String section)
std::vector<Entry> CActionList::ModifyLines(Selection selection,const String section)
{
// Get section
Section sect = Model(model)->GetMutableSection(section);
Section sect = shared_ptr<CModel>(model)->GetMutableSection(section);
// Generate entries
std::vector<Entry> entries(selection->GetCount());

View File

@ -56,7 +56,7 @@ namespace Athenasub {
private:
String actionName;
String owner;
weak_ptr<IModel> model;
weak_ptr<CModel> model;
std::list<Action> actions;
bool valid;
bool undoAble;

View File

@ -46,7 +46,7 @@ using namespace Athenasub;
///////////////
// Constructor
CController::CController(Model _model)
: model(_model)
: model(dynamic_pointer_cast<CModel>(_model))
{
}

View File

@ -43,7 +43,7 @@ namespace Athenasub {
friend class CModel;
private:
Model model;
shared_ptr<CModel> model;
CController (Model model);
public:

View 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();
}

View File

@ -45,12 +45,12 @@ namespace Athenasub {
protected:
virtual ~CFormatHandler() {}
Section AddSection(IModel &model,String name) const { return model.AddSection(name); }
ConstSection GetSection(const IModel &model,String name) const { return model.GetSection(name); }
ConstSection GetSectionByIndex(const IModel &model,size_t index) const { return model.GetSectionByIndex(index); }
Section GetSection(IModel &model,String name) const { return model.GetMutableSection(name); }
Section GetSectionByIndex(IModel &model,size_t index) const { return model.GetMutableSectionByIndex(index); }
size_t GetSectionCount(const IModel &model) const { return model.GetSectionCount(); }
Section AddSection(IModel &model,String name) const;
ConstSection GetSection(const IModel &model,String name) const;
ConstSection GetSectionByIndex(const IModel &model,size_t index) const;
Section GetSection(IModel &model,String name) const;
Section GetSectionByIndex(IModel &model,size_t index) const;
size_t GetSectionCount(const IModel &model) const;
public:
//CFormatHandler(IModel& _model) : model(_model) {}

View File

@ -48,7 +48,7 @@ Athenasub::TextReaderCache::TextReaderCache(shared_ptr<TextReader> src)
String TextReaderCache::ReadLineFromFile()
{
if (bufferPos == buffer.size()) {
LoadMore(1000000);
LoadMore(1);
}
if (bufferPos == buffer.size()) {
return "";