diff --git a/aegilib/aegilib.vcproj b/aegilib/aegilib.vcproj index 0cbee39ce..ae3582d2c 100644 --- a/aegilib/aegilib.vcproj +++ b/aegilib/aegilib.vcproj @@ -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 @@ + + diff --git a/aegilib/aegilib_2008.vcproj b/aegilib/aegilib_2008.vcproj index 58e43fd0e..073471bd4 100644 --- a/aegilib/aegilib_2008.vcproj +++ b/aegilib/aegilib_2008.vcproj @@ -163,16 +163,28 @@ + + + + + + + + - - + + + + + + + + + + diff --git a/aegilib/include/aegilib/action.h b/aegilib/include/aegilib/action.h index 7fb6a07b9..3adb10c00 100644 --- a/aegilib/include/aegilib/action.h +++ b/aegilib/include/aegilib/action.h @@ -104,7 +104,7 @@ namespace Athenasub { void Execute(Model &model); }; - // Modify several line + // Modify several lines class ActionModifyBatch : public Action { private: std::vector > entries; diff --git a/aegilib/include/aegilib/actionlist.h b/aegilib/include/aegilib/actionlist.h index 2c32351a7..bbe6b0a2a 100644 --- a/aegilib/include/aegilib/actionlist.h +++ b/aegilib/include/aegilib/actionlist.h @@ -39,6 +39,7 @@ #include "athenastring.h" #include "section_entry.h" #include "selection.h" +#include "api.h" namespace Athenasub { diff --git a/aegilib/include/aegilib/api.h b/aegilib/include/aegilib/api.h new file mode 100644 index 000000000..d195e57c1 --- /dev/null +++ b/aegilib/include/aegilib/api.h @@ -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) diff --git a/aegilib/include/aegilib/athenasub.h b/aegilib/include/aegilib/athenasub.h index f9b44e8ee..9d0c37413 100644 --- a/aegilib/include/aegilib/athenasub.h +++ b/aegilib/include/aegilib/athenasub.h @@ -41,6 +41,7 @@ #include "tr1.h" #include "exception.h" +#include "libathenasub.h" #include "model.h" #include "view.h" #include "controller.h" diff --git a/aegilib/include/aegilib/controller.h b/aegilib/include/aegilib/controller.h index ca07d30b8..3e6eb4e86 100644 --- a/aegilib/include/aegilib/controller.h +++ b/aegilib/include/aegilib/controller.h @@ -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 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 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 ControllerPtr; + +} diff --git a/aegilib/include/aegilib/format_manager.h b/aegilib/include/aegilib/format_manager.h index ce59382a3..15b4fbc4f 100644 --- a/aegilib/include/aegilib/format_manager.h +++ b/aegilib/include/aegilib/format_manager.h @@ -35,6 +35,7 @@ #pragma once #include "format.h" +#include "api.h" namespace Athenasub { diff --git a/aegilib/include/aegilib/libathenasub.h b/aegilib/include/aegilib/libathenasub.h new file mode 100644 index 000000000..ce2f3c552 --- /dev/null +++ b/aegilib/include/aegilib/libathenasub.h @@ -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 ModelPtr; + + class LibAthenaSub { + public: + LibAthenaSub(const char* hostName); + + ModelPtr CreateModel(); + }; + +} + +extern "C" Athenasub::LibAthenaSub* CreateLibAthenasub(const char* hostName); diff --git a/aegilib/include/aegilib/model.h b/aegilib/include/aegilib/model.h index 6061c62f5..44b3c87d8 100644 --- a/aegilib/include/aegilib/model.h +++ b/aegilib/include/aegilib/model.h @@ -39,6 +39,7 @@ #include #include "actionlist.h" #include "section.h" +#include "api.h" namespace Athenasub { @@ -59,6 +60,7 @@ namespace Athenasub { typedef std::list ViewList; typedef std::list ActionStack; typedef shared_ptr FormatPtr; + typedef shared_ptr ControllerPtr; private: std::vector 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 ModelPtr; + } diff --git a/aegilib/include/aegilib/section.h b/aegilib/include/aegilib/section.h index 33da6b397..cd6453876 100644 --- a/aegilib/include/aegilib/section.h +++ b/aegilib/include/aegilib/section.h @@ -37,6 +37,7 @@ #include "athenastring.h" #include "section_entry.h" #include "tr1.h" +#include "api.h" #include #include diff --git a/aegilib/include/aegilib/section_entry.h b/aegilib/include/aegilib/section_entry.h index 087c805b8..ad81c4c47 100644 --- a/aegilib/include/aegilib/section_entry.h +++ b/aegilib/include/aegilib/section_entry.h @@ -37,6 +37,7 @@ #include "athenastring.h" #include "tr1.h" #include "deltacoder.h" +#include "api.h" namespace Athenasub { diff --git a/aegilib/include/aegilib/selection.h b/aegilib/include/aegilib/selection.h index aa5f938f9..c9fd7bfb3 100644 --- a/aegilib/include/aegilib/selection.h +++ b/aegilib/include/aegilib/selection.h @@ -35,6 +35,7 @@ #pragma once #include +#include "api.h" namespace Athenasub { diff --git a/aegilib/include/aegilib/tr1.h b/aegilib/include/aegilib/tr1.h index d72facbe7..74829b550 100644 --- a/aegilib/include/aegilib/tr1.h +++ b/aegilib/include/aegilib/tr1.h @@ -39,8 +39,8 @@ // Include the Technical Report 1 headers // This is necessary because some compilers put them on different places -#include -#include +#include +#include namespace Athenasub { using std::tr1::shared_ptr; diff --git a/aegilib/include/aegilib/version.h b/aegilib/include/aegilib/version.h index 5fd975010..0cf38f4bc 100644 --- a/aegilib/include/aegilib/version.h +++ b/aegilib/include/aegilib/version.h @@ -36,6 +36,7 @@ #pragma once #include "athenastring.h" +#include "api.h" //////////////////// // Helper functions diff --git a/aegilib/include/aegilib/view.h b/aegilib/include/aegilib/view.h index f37092141..45656a88a 100644 --- a/aegilib/include/aegilib/view.h +++ b/aegilib/include/aegilib/view.h @@ -35,6 +35,7 @@ #pragma once #include "athenastring.h" +#include "api.h" #include namespace Athenasub { diff --git a/aegilib/src/libathenasub.cpp b/aegilib/src/libathenasub.cpp new file mode 100644 index 000000000..1c924616f --- /dev/null +++ b/aegilib/src/libathenasub.cpp @@ -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()); +} diff --git a/aegilib/src/model.cpp b/aegilib/src/model.cpp index f454802ec..8864b6555 100644 --- a/aegilib/src/model.cpp +++ b/aegilib/src/model.cpp @@ -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)); +} diff --git a/aegilib/test/src/main.cpp b/aegilib/test/src/main.cpp index d32c6cca3..5e1c67345 100644 --- a/aegilib/test/src/main.cpp +++ b/aegilib/test/src/main.cpp @@ -33,6 +33,7 @@ // Contact: mailto:amz@aegisub.net // +#define ATHENA_DLL #include #include #include @@ -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;iCreateActionList(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;iUndo(); } cout << "Done.\n"; @@ -109,20 +110,20 @@ int main() cout << "Undoing and redoing " << n*10 << " times... "; timer.Start(); for (size_t i=0;iUndo(); + 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) { diff --git a/aegilib/test/test_2008.vcproj b/aegilib/test/test_2008.vcproj index a09f106ea..10ac41e00 100644 --- a/aegilib/test/test_2008.vcproj +++ b/aegilib/test/test_2008.vcproj @@ -124,7 +124,7 @@ OpenMP="false" UsePrecompiledHeader="0" WarningLevel="4" - Detect64BitPortabilityProblems="true" + Detect64BitPortabilityProblems="false" DebugInformationFormat="3" DisableSpecificWarnings="4996" />