Changed Athenasub's API (WIP) and updated projects.

Originally committed to SVN as r2291.
This commit is contained in:
Rodrigo Braz Monteiro 2008-07-27 18:26:36 +00:00
parent 15369e7545
commit e019c333d9
20 changed files with 317 additions and 101 deletions

View File

@ -121,7 +121,7 @@
EnableFiberSafeOptimizations="false"
WholeProgramOptimization="true"
AdditionalIncludeDirectories="include/aegilib"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_WINDOWS"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_WINDOWS;ATHENA_DLL;ATHENA_EXPORTS"
RuntimeLibrary="2"
OpenMP="false"
UsePrecompiledHeader="2"
@ -180,6 +180,10 @@
<Filter
Name="Include"
>
<File
RelativePath=".\include\aegilib\api.h"
>
</File>
<File
RelativePath=".\include\aegilib\athenastring.h"
>

View File

@ -163,16 +163,28 @@
<Filter
Name="Include"
>
<File
RelativePath=".\include\aegilib\api.h"
>
</File>
<File
RelativePath=".\include\aegilib\athenastring.h"
>
</File>
<File
RelativePath=".\include\aegilib\athenasub.h"
>
</File>
<File
RelativePath=".\include\aegilib\athenatime.h"
>
</File>
<File
RelativePath=".\include\aegilib\fastbuffer.h"
>
</File>
<File
RelativePath=".\include\aegilib\gorgonstring.h"
>
</File>
<File
RelativePath=".\include\aegilib\gorgonsub.h"
RelativePath=".\include\aegilib\selection.h"
>
</File>
<File
@ -428,6 +440,26 @@
RelativePath=".\include\aegilib\section_entry_style.h"
>
</File>
<File
RelativePath=".\src\selection.cpp"
>
</File>
<File
RelativePath=".\src\stdint.h"
>
</File>
</Filter>
<Filter
Name="Lib"
>
<File
RelativePath=".\src\libathenasub.cpp"
>
</File>
<File
RelativePath=".\include\aegilib\libathenasub.h"
>
</File>
</Filter>
</Files>
<Globals>

View File

@ -104,7 +104,7 @@ namespace Athenasub {
void Execute(Model &model);
};
// Modify several line
// Modify several lines
class ActionModifyBatch : public Action {
private:
std::vector<shared_ptr<Entry> > entries;

View File

@ -39,6 +39,7 @@
#include "athenastring.h"
#include "section_entry.h"
#include "selection.h"
#include "api.h"
namespace Athenasub {

View File

@ -0,0 +1,46 @@
// 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
//
#ifdef ATHENA_DLL
#ifdef ATHENA_EXPORTS
#define ATHENA_API __declspec(dllexport)
#else
#define ATHENA_API __declspec(dllimport)
#endif
#else
#define ATHENA_API
#endif
#pragma warning(disable: 4251)

View File

@ -41,6 +41,7 @@
#include "tr1.h"
#include "exception.h"
#include "libathenasub.h"
#include "model.h"
#include "view.h"
#include "controller.h"

View File

@ -1,76 +1,79 @@
// 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
//
#pragma once
#include "athenastring.h"
#include "tr1.h"
#include "format.h"
namespace Athenasub {
// Prototypes
class Model;
class ActionList;
typedef shared_ptr<ActionList> ActionListPtr;
// Controller class
class Controller {
private:
Model &model;
public:
Controller (Model &model);
ActionListPtr CreateActionList(const String title,const String owner=L"",bool undoAble=true);
void LoadFile(const String filename,const String encoding=L"");
void SaveFile(const String filename,const String encoding=L"UTF-8");
bool CanUndo(const String owner=L"") const;
bool CanRedo(const String owner=L"") const;
void Undo(const String owner=L"");
void Redo(const String owner=L"");
DialoguePtr CreateDialogue() const;
StylePtr CreateStyle() const;
DialogueConstPtr GetDialogue(size_t n) const;
DialogueConstPtr GetStyle(size_t n) const;
StyleConstPtr GetStyle(String name) const;
EntryConstPtr GetEntry(size_t n,String section) const;
const FormatPtr GetFormat() const;
};
}
// 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
//
#pragma once
#include "athenastring.h"
#include "tr1.h"
#include "format.h"
#include "api.h"
namespace Athenasub {
// Prototypes
class Model;
class ActionList;
typedef shared_ptr<ActionList> ActionListPtr;
// Controller class
class Controller {
private:
Model &model;
public:
Controller (Model &model);
ActionListPtr CreateActionList(const String title,const String owner=L"",bool undoAble=true);
void LoadFile(const String filename,const String encoding=L"");
void SaveFile(const String filename,const String encoding=L"UTF-8");
bool CanUndo(const String owner=L"") const;
bool CanRedo(const String owner=L"") const;
void Undo(const String owner=L"");
void Redo(const String owner=L"");
DialoguePtr CreateDialogue() const;
StylePtr CreateStyle() const;
DialogueConstPtr GetDialogue(size_t n) const;
DialogueConstPtr GetStyle(size_t n) const;
StyleConstPtr GetStyle(String name) const;
EntryConstPtr GetEntry(size_t n,String section) const;
const FormatPtr GetFormat() const;
};
typedef shared_ptr<Controller> ControllerPtr;
}

View File

@ -35,6 +35,7 @@
#pragma once
#include "format.h"
#include "api.h"
namespace Athenasub {

View File

@ -0,0 +1,54 @@
// 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
//
#pragma once
#include "tr1.h"
namespace Athenasub {
class Model;
typedef shared_ptr<Model> ModelPtr;
class LibAthenaSub {
public:
LibAthenaSub(const char* hostName);
ModelPtr CreateModel();
};
}
extern "C" Athenasub::LibAthenaSub* CreateLibAthenasub(const char* hostName);

View File

@ -39,6 +39,7 @@
#include <wx/wfstream.h>
#include "actionlist.h"
#include "section.h"
#include "api.h"
namespace Athenasub {
@ -59,6 +60,7 @@ namespace Athenasub {
typedef std::list<ViewPtr> ViewList;
typedef std::list<ActionListPtr> ActionStack;
typedef shared_ptr<Format> FormatPtr;
typedef shared_ptr<Controller> ControllerPtr;
private:
std::vector<SectionPtr> sections;
@ -90,8 +92,12 @@ namespace Athenasub {
void Save(wxOutputStream &output,const FormatPtr format=FormatPtr(),const String encoding=L"UTF-8");
public:
ControllerPtr CreateController();
const FormatPtr GetFormat() const { return format; }
void AddListener(ViewPtr listener);
};
typedef shared_ptr<Model> ModelPtr;
}

View File

@ -37,6 +37,7 @@
#include "athenastring.h"
#include "section_entry.h"
#include "tr1.h"
#include "api.h"
#include <list>
#include <map>

View File

@ -37,6 +37,7 @@
#include "athenastring.h"
#include "tr1.h"
#include "deltacoder.h"
#include "api.h"
namespace Athenasub {

View File

@ -35,6 +35,7 @@
#pragma once
#include <vector>
#include "api.h"
namespace Athenasub {

View File

@ -39,8 +39,8 @@
// Include the Technical Report 1 headers
// This is necessary because some compilers put them on different places
#include <tr1/memory>
#include <tr1/array>
#include <memory>
#include <array>
namespace Athenasub {
using std::tr1::shared_ptr;

View File

@ -36,6 +36,7 @@
#pragma once
#include "athenastring.h"
#include "api.h"
////////////////////
// Helper functions

View File

@ -35,6 +35,7 @@
#pragma once
#include "athenastring.h"
#include "api.h"
#include <list>
namespace Athenasub {

View File

@ -0,0 +1,54 @@
// 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 "athenasub.h"
using namespace Athenasub;
extern "C" LibAthenaSub* CreateLibAthenasub(const char* hostName) {
return new LibAthenaSub(hostName);
}
LibAthenaSub::LibAthenaSub(const char* hostName) {
(void) hostName;
Athenasub::SetHostApplicationName(String(hostName,wxConvUTF8));
FormatManager::InitializeFormats();
}
ModelPtr LibAthenaSub::CreateModel() {
return ModelPtr(new Model());
}

View File

@ -243,3 +243,11 @@ String Model::GetRedoMessage(const String owner) const
if (CanRedo()) return redoStack.back()->GetName();
return L"";
}
//////////////////////////////////////
// Create a controller for this model
ControllerPtr Athenasub::Model::CreateController()
{
return ControllerPtr(new Controller(*this));
}

View File

@ -33,6 +33,7 @@
// Contact: mailto:amz@aegisub.net
//
#define ATHENA_DLL
#include <aegilib/athenasub.h>
#include <wx/wfstream.h>
#include <iostream>
@ -49,26 +50,26 @@ int main()
try {
// Set up the lib
FormatManager::InitializeFormats();
Athenasub::SetHostApplicationName(L"Aegilib test program");
//FormatManager::InitializeFormats();
//Athenasub::SetHostApplicationName(L"Aegilib test program");
LibAthenaSub* lib = CreateLibAthenasub("Aegisub test program");
// Subtitles model
Model subs;
Controller control(subs);
ModelPtr subs = lib->CreateModel();
ControllerPtr control = subs->CreateController();
wxStopWatch timer;
// Load subtitles
cout << "Loading file... ";
timer.Start();
control.LoadFile(L"subs_in.ass",L"UTF-8");
control->LoadFile(L"subs_in.ass",L"UTF-8");
timer.Pause();
cout << "Done in " << timer.Time() << " ms.\n";
//system("pause");
// Save subtitles
cout << "Saving file... ";
timer.Start();
control.SaveFile(L"subs_out.ass",L"UTF-8");
control->SaveFile(L"subs_out.ass",L"UTF-8");
timer.Pause();
cout << "Done in " << timer.Time() << " ms.\n";
@ -81,7 +82,7 @@ int main()
cout << "Executing action " << n << " times... ";
timer.Start();
for (size_t i=0;i<n;i++) {
ActionListPtr actions = control.CreateActionList(L"Test");
ActionListPtr actions = control->CreateActionList(L"Test");
Selection selection;
selection.AddRange(Range(0,5000));
selection.AddRange(Range(4500,5500));
@ -101,7 +102,7 @@ int main()
// Rollback
cout << "Undoing " << n << " times... ";
for (size_t i=0;i<n-1;i++) {
control.Undo();
control->Undo();
}
cout << "Done.\n";
@ -109,20 +110,20 @@ int main()
cout << "Undoing and redoing " << n*10 << " times... ";
timer.Start();
for (size_t i=0;i<n*10;i++) {
control.Undo();
control.Redo();
control->Undo();
control->Redo();
}
timer.Pause();
cout << "Done in " << timer.Time() << " ms.\n";
// Get style test
StyleConstPtr style = control.GetStyle(L"japro1_star");
StyleConstPtr style = control->GetStyle(L"japro1_star");
cout << "Style " << style->GetName().mb_str() << " font is " << style->GetFontName().mb_str() << " " << style->GetFontSize() << ".\n";
// Save a few more
control.SaveFile(L"subs_out2.ass",L"UTF-8");
control.Undo();
control.SaveFile(L"subs_out3.ass",L"UTF-8");
control->SaveFile(L"subs_out2.ass",L"UTF-8");
control->Undo();
control->SaveFile(L"subs_out3.ass",L"UTF-8");
}
catch (std::exception &e) {

View File

@ -124,7 +124,7 @@
OpenMP="false"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="true"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
DisableSpecificWarnings="4996"
/>