Completely broke Athenasub (WIP)
Originally committed to SVN as r2293.
This commit is contained in:
parent
29ed35de5c
commit
f0f1f7fb72
53 changed files with 1006 additions and 835 deletions
1
aegilib/ClassDiagram1.cd
Normal file
1
aegilib/ClassDiagram1.cd
Normal file
|
@ -0,0 +1 @@
|
|||
|
|
@ -115,7 +115,7 @@
|
|||
EnableIntrinsicFunctions="true"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="false"
|
||||
AdditionalIncludeDirectories="include/aegilib"
|
||||
AdditionalIncludeDirectories="include/athenasub;src"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_WINDOWS"
|
||||
RuntimeLibrary="2"
|
||||
EnableEnhancedInstructionSet="0"
|
||||
|
@ -166,35 +166,23 @@
|
|||
Name="Include"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\api.h"
|
||||
RelativePath=".\include\athenasub\api.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\athenastring.h"
|
||||
RelativePath=".\include\athenasub\athenasub.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\athenasub.h"
|
||||
RelativePath=".\include\athenasub\athenawin.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\athenatime.h"
|
||||
RelativePath=".\include\athenasub\interfaces.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\fastbuffer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\range.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\selection.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\tr1.h"
|
||||
RelativePath=".\include\athenasub\tr1.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
|
@ -206,7 +194,7 @@
|
|||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\controller.h"
|
||||
RelativePath=".\src\controller.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
|
@ -214,29 +202,13 @@
|
|||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\model.h"
|
||||
RelativePath=".\src\model.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\notification.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\view.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PrecompiledHeaderThrough="prec.h"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\view.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Misc"
|
||||
|
@ -249,10 +221,6 @@
|
|||
RelativePath=".\include\aegilib\colour.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\deltacoder.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\exception.cpp"
|
||||
>
|
||||
|
@ -261,6 +229,10 @@
|
|||
RelativePath=".\include\aegilib\exception.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\fastbuffer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\gorgontime.h"
|
||||
>
|
||||
|
@ -290,6 +262,14 @@
|
|||
RelativePath=".\src\prec.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\range.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\selection.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\serialize.h"
|
||||
>
|
||||
|
@ -327,7 +307,7 @@
|
|||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\utils.h"
|
||||
RelativePath=".\src\utils.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
|
@ -342,10 +322,6 @@
|
|||
<Filter
|
||||
Name="Formats"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\format.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\format_handler.h"
|
||||
>
|
||||
|
@ -415,7 +391,7 @@
|
|||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\actionlist.h"
|
||||
RelativePath=".\src\actionlist.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
|
@ -426,10 +402,6 @@
|
|||
RelativePath=".\src\section.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\section.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\section_entry.cpp"
|
||||
>
|
||||
|
@ -463,7 +435,7 @@
|
|||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\libathenasub.h"
|
||||
RelativePath=".\src\libathenasub.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
// 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;
|
||||
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
// 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 "section_entry.h"
|
||||
|
||||
namespace Athenasub {
|
||||
// Prototypes
|
||||
class FormatHandler;
|
||||
class Model;
|
||||
|
||||
// Format interface
|
||||
class Format {
|
||||
public:
|
||||
virtual ~Format() {}
|
||||
|
||||
virtual String GetName() const = 0;
|
||||
virtual StringArray GetReadExtensions() const = 0;
|
||||
virtual StringArray GetWriteExtensions() const = 0;
|
||||
virtual shared_ptr<FormatHandler> GetHandler(Model &model) const = 0;
|
||||
|
||||
virtual bool CanStoreText() const { return false; }
|
||||
virtual bool CanStoreImages() const { return false; }
|
||||
virtual bool CanUseTime() const { return false; }
|
||||
virtual bool CanUseFrames() const { return false; }
|
||||
|
||||
virtual bool HasStyles() const { return false; }
|
||||
virtual bool HasMargins() const { return false; }
|
||||
virtual bool HasActors() const { return false; }
|
||||
virtual bool HasUserField() const { return false; }
|
||||
virtual String GetUserFieldName() const { return L""; }
|
||||
|
||||
virtual int GetTimingPrecision() const { return 10; } // In milliseconds
|
||||
virtual int GetMaxTime() const { return 36000000-10; } // In milliseconds, default 9h 59min 59.99s
|
||||
|
||||
virtual DialoguePtr CreateDialogue() const = 0;
|
||||
virtual StylePtr CreateStyle() const = 0;
|
||||
};
|
||||
typedef shared_ptr<Format> FormatPtr;
|
||||
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
// 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 "deltacoder.h"
|
||||
#include "api.h"
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
// Types
|
||||
enum SectionEntryType {
|
||||
SECTION_ENTRY_PLAIN,
|
||||
SECTION_ENTRY_DIALOGUE,
|
||||
SECTION_ENTRY_STYLE,
|
||||
SECTION_ENTRY_FILE,
|
||||
SECTION_ENTRY_RAW
|
||||
};
|
||||
|
||||
// Prototypes
|
||||
class Entry;
|
||||
class PlainText;
|
||||
class Dialogue;
|
||||
class Style;
|
||||
class Attachment;
|
||||
class RawEntry;
|
||||
typedef shared_ptr<Entry> EntryPtr;
|
||||
typedef shared_ptr<PlainText> PlainTextPtr;
|
||||
typedef shared_ptr<Dialogue> DialoguePtr;
|
||||
typedef shared_ptr<Style> StylePtr;
|
||||
typedef shared_ptr<Attachment> AttachmentPtr;
|
||||
typedef shared_ptr<RawEntry> RawEntryPtr;
|
||||
typedef shared_ptr<const Entry> EntryConstPtr;
|
||||
typedef shared_ptr<const PlainText> PlainTextConstPtr;
|
||||
typedef shared_ptr<const Dialogue> DialogueConstPtr;
|
||||
typedef shared_ptr<const Style> StyleConstPtr;
|
||||
typedef shared_ptr<const Attachment> AttachmentConstPtr;
|
||||
typedef shared_ptr<const RawEntry> RawEntryConstPtr;
|
||||
|
||||
// Section entry class
|
||||
class Entry {
|
||||
protected:
|
||||
virtual ~Entry() {}
|
||||
const String& EmptyString() const;
|
||||
|
||||
public:
|
||||
virtual SectionEntryType GetType() const =0;
|
||||
virtual String GetDefaultGroup() const =0;
|
||||
virtual EntryPtr Clone() const =0;
|
||||
|
||||
virtual DeltaCoderPtr GetDeltaCoder() const { return DeltaCoderPtr(); }
|
||||
virtual bool IsIndexable() const { return false; }
|
||||
virtual String GetIndexName() const { return L""; }
|
||||
|
||||
static const PlainTextPtr GetAsPlain(const EntryPtr &ptr);
|
||||
static const DialoguePtr GetAsDialogue(const EntryPtr &ptr);
|
||||
static const DialogueConstPtr GetAsDialogue(const EntryConstPtr &ptr);
|
||||
static const StylePtr GetAsStyle(const EntryPtr &ptr);
|
||||
static const AttachmentPtr GetAsFile(const EntryPtr &ptr);
|
||||
static const RawEntryPtr GetAsRaw(const EntryPtr &ptr);
|
||||
};
|
||||
|
||||
// Section plain-text entry
|
||||
class PlainText : public Entry {
|
||||
public:
|
||||
SectionEntryType GetType() const { return SECTION_ENTRY_PLAIN; }
|
||||
virtual ~PlainText() {}
|
||||
virtual String GetText() const =0;
|
||||
virtual void SetText(const String &_data) =0;
|
||||
};
|
||||
|
||||
}
|
|
@ -35,26 +35,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifndef UNICODE
|
||||
#error "This library requires unicode support."
|
||||
#endif
|
||||
|
||||
#include "api.h"
|
||||
#include "tr1.h"
|
||||
#include "exception.h"
|
||||
#include "libathenasub.h"
|
||||
#include "model.h"
|
||||
#include "view.h"
|
||||
#include "controller.h"
|
||||
#include "notification.h"
|
||||
#include "athenastring.h"
|
||||
#include "format.h"
|
||||
#include "format_handler.h"
|
||||
#include "format_manager.h"
|
||||
#include "actionlist.h"
|
||||
#include "section.h"
|
||||
#include "section_entry_dialogue.h"
|
||||
#include "section_entry_style.h"
|
||||
#include "athenatime.h"
|
||||
#include "colour.h"
|
||||
#include "utils.h"
|
||||
#include "version.h"
|
||||
#include "interfaces.h"
|
||||
#include "range.h"
|
||||
|
||||
|
||||
extern "C" Athenasub::ILibAthenaSub* CreateLibAthenasub(const char* hostName);
|
|
@ -34,21 +34,15 @@
|
|||
//
|
||||
|
||||
#pragma once
|
||||
#include "tr1.h"
|
||||
|
||||
#include "athenasub.h"
|
||||
#include <windows.h>
|
||||
|
||||
typedef Athenasub::ILibAthenaSub* (__stdcall *CreateLibAthenasubPtr)(const char*);
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
// Void pointer prototyle
|
||||
typedef shared_ptr<void> VoidPtr;
|
||||
|
||||
// Deltacoder interface
|
||||
class DeltaCoder {
|
||||
public:
|
||||
virtual ~DeltaCoder() {}
|
||||
virtual VoidPtr EncodeDelta(VoidPtr from,VoidPtr to,bool withTextFields=true) const = 0;
|
||||
virtual VoidPtr EncodeReverseDelta(VoidPtr delta,VoidPtr object) const = 0;
|
||||
virtual void ApplyDelta(VoidPtr delta,VoidPtr object) const = 0;
|
||||
};
|
||||
typedef shared_ptr<DeltaCoder> DeltaCoderPtr;
|
||||
|
||||
inline LibAthenaSub Create(HMODULE module,const char* hostName) {
|
||||
CreateLibAthenasubPtr CreateLib = (CreateLibAthenasubPtr)GetProcAddress(module,"CreateLibAthenaSub");
|
||||
return LibAthenaSub(CreateLib(hostName));
|
||||
}
|
||||
}
|
111
aegilib/include/athenasub/exception.h
Normal file
111
aegilib/include/athenasub/exception.h
Normal file
|
@ -0,0 +1,111 @@
|
|||
// 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 <string>
|
||||
#include <exception>
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
// Exception class
|
||||
class Exception : public std::exception {
|
||||
public:
|
||||
enum ExceptionList {
|
||||
Unknown,
|
||||
No_Format_Handler,
|
||||
Invalid_ActionList,
|
||||
Section_Already_Exists,
|
||||
Unknown_Format,
|
||||
Parse_Error,
|
||||
Unsupported_Format_Feature,
|
||||
Invalid_Token,
|
||||
Out_Of_Range,
|
||||
Invalid_Section,
|
||||
Internal_Error,
|
||||
TODO
|
||||
};
|
||||
|
||||
Exception(ExceptionList _code) : std::exception(GetMessageChar(_code)) { code = _code; }
|
||||
Exception(ExceptionList _code,const char* file,const long line) : std::exception(GetMessageFile(_code,file,line)) { code = _code; }
|
||||
|
||||
//String GetMessageString() const { return String(what(),wxConvLocal); }
|
||||
int GetCode() { return code; }
|
||||
|
||||
private:
|
||||
static const char* 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.";
|
||||
}
|
||||
|
||||
|
||||
static const char* 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();
|
||||
}
|
||||
|
||||
|
||||
ExceptionList code;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#ifndef THROW_ATHENA_EXCEPTION
|
||||
#ifdef _MSC_VER
|
||||
#define THROW_ATHENA_EXCEPTION(code) throw Athenasub::Exception(code,__FILE__,__LINE__)
|
||||
#else
|
||||
#define THROW_ATHENA_EXCEPTION(code) throw Athenasub::Exception(code)
|
||||
#endif
|
||||
#endif
|
455
aegilib/include/athenasub/interfaces.h
Normal file
455
aegilib/include/athenasub/interfaces.h
Normal file
|
@ -0,0 +1,455 @@
|
|||
// 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"
|
||||
#include <wx/string.h>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
// Strings
|
||||
typedef wxString String;
|
||||
typedef std::vector<String> StringArray;
|
||||
|
||||
|
||||
// Prototypes
|
||||
class Range;
|
||||
class ISelection;
|
||||
class IController;
|
||||
class IView;
|
||||
class IFormatHandler;
|
||||
class ITime;
|
||||
class IColour;
|
||||
class IEntry;
|
||||
class IDialogue;
|
||||
class IStyle;
|
||||
class IFormat;
|
||||
class IModel;
|
||||
class IActionList;
|
||||
class INotification;
|
||||
class ISection;
|
||||
class IDeltaCoder;
|
||||
class CController;
|
||||
|
||||
|
||||
// Smart pointers
|
||||
typedef shared_ptr<void> VoidPtr;
|
||||
typedef shared_ptr<ISelection> Selection;
|
||||
typedef shared_ptr<IController> Controller;
|
||||
typedef shared_ptr<IView> View;
|
||||
typedef shared_ptr<IFormatHandler> FormatHandler;
|
||||
typedef shared_ptr<ITime> Time;
|
||||
typedef shared_ptr<IColour> Colour;
|
||||
typedef shared_ptr<IEntry> Entry;
|
||||
typedef shared_ptr<IDialogue> Dialogue;
|
||||
typedef shared_ptr<IStyle> Style;
|
||||
typedef shared_ptr<IFormat> Format;
|
||||
typedef shared_ptr<IModel> Model;
|
||||
typedef shared_ptr<IActionList> ActionList;
|
||||
typedef shared_ptr<INotification> Notification;
|
||||
typedef shared_ptr<ISection> Section;
|
||||
typedef shared_ptr<IDeltaCoder> DeltaCoder;
|
||||
|
||||
|
||||
// Const smart pointers
|
||||
typedef shared_ptr<const IEntry> ConstEntry;
|
||||
typedef shared_ptr<const IDialogue> ConstDialogue;
|
||||
typedef shared_ptr<const IStyle> ConstStyle;
|
||||
typedef shared_ptr<const IModel> ConstModel;
|
||||
|
||||
|
||||
// Lists
|
||||
typedef std::list<View> ViewList;
|
||||
typedef std::list<ActionList> ActionStack;
|
||||
|
||||
|
||||
// Model
|
||||
class IModel {
|
||||
friend class CFormatHandler;
|
||||
friend class CActionList;
|
||||
friend class CController;
|
||||
friend class IAction;
|
||||
|
||||
protected:
|
||||
virtual void ProcessActionList(ActionList actionList,int type=0) = 0;
|
||||
|
||||
virtual String GetUndoMessage(const String owner=L"") const = 0;
|
||||
virtual String GetRedoMessage(const String owner=L"") const = 0;
|
||||
virtual bool CanUndo(const String owner=L"") const = 0;
|
||||
virtual bool CanRedo(const String owner=L"") const = 0;
|
||||
virtual void Undo(const String owner=L"") = 0;
|
||||
virtual void Redo(const String owner=L"") = 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(wxInputStream &input,Format format=Format(),const String encoding=L"") = 0;
|
||||
virtual void Save(wxOutputStream &output,Format format=Format(),const String encoding=L"UTF-8") = 0;
|
||||
|
||||
virtual void AddSection(String name) = 0;
|
||||
virtual Section GetSection(String name) const = 0;
|
||||
virtual Section GetSectionByIndex(size_t index) const = 0;
|
||||
virtual size_t GetSectionCount() const = 0;
|
||||
|
||||
public:
|
||||
virtual ~IModel();
|
||||
|
||||
virtual Controller CreateController()=0;
|
||||
virtual Format GetFormat() const=0;
|
||||
virtual void AddListener(View listener)=0;
|
||||
};
|
||||
|
||||
|
||||
// View
|
||||
class IView {
|
||||
public:
|
||||
virtual ~IView() {}
|
||||
};
|
||||
|
||||
|
||||
// Controller
|
||||
class IController {
|
||||
public:
|
||||
virtual ~IController() {}
|
||||
|
||||
virtual ActionList CreateActionList(const String title,const String owner=L"",bool undoAble=true) = 0;
|
||||
virtual Selection CreateSelection() = 0;
|
||||
|
||||
virtual void LoadFile(const String filename,const String encoding=L"") = 0;
|
||||
virtual void SaveFile(const String filename,const String encoding=L"UTF-8") = 0;
|
||||
|
||||
virtual bool CanUndo(const String owner=L"") const = 0;
|
||||
virtual bool CanRedo(const String owner=L"") const = 0;
|
||||
virtual void Undo(const String owner=L"") = 0;
|
||||
virtual void Redo(const String owner=L"") = 0;
|
||||
|
||||
virtual Dialogue CreateDialogue() const = 0;
|
||||
virtual Style CreateStyle() const = 0;
|
||||
|
||||
virtual ConstDialogue GetDialogue(size_t n) const = 0;
|
||||
virtual ConstStyle GetStyle(size_t n) const = 0;
|
||||
virtual ConstStyle GetStyle(String name) const = 0;
|
||||
virtual ConstEntry GetEntry(size_t n,String section) const = 0;
|
||||
|
||||
virtual const Format GetFormat() const = 0;
|
||||
};
|
||||
|
||||
|
||||
// Selection
|
||||
class ISelection {
|
||||
public:
|
||||
virtual ~ISelection() {}
|
||||
|
||||
virtual void AddLine(size_t line) = 0;
|
||||
virtual void RemoveLine(size_t line) = 0;
|
||||
|
||||
virtual void AddRange(const Range &range) = 0;
|
||||
virtual void RemoveRange(const Range &range) = 0;
|
||||
|
||||
virtual void AddSelection(const Selection ¶m) = 0;
|
||||
virtual void RemoveSelection(const Selection ¶m) = 0;
|
||||
|
||||
virtual void NormalizeRanges() = 0;
|
||||
|
||||
virtual size_t GetCount() const = 0;
|
||||
virtual size_t GetRanges() const = 0;
|
||||
virtual size_t GetLine(size_t n) const = 0;
|
||||
virtual size_t GetLineInRange(size_t n,size_t range) const = 0;
|
||||
virtual size_t GetLinesInRange(size_t range) const = 0;
|
||||
virtual bool IsContiguous() const = 0;
|
||||
};
|
||||
|
||||
|
||||
// Time
|
||||
class ITime {
|
||||
public:
|
||||
virtual ~ITime() {}
|
||||
|
||||
virtual void SetMS(int milliseconds) = 0;
|
||||
virtual int GetMS() const = 0;
|
||||
|
||||
virtual String GetString(int ms_precision,int h_precision) const = 0;
|
||||
virtual void ParseString(const String &data) = 0;
|
||||
|
||||
virtual Time Clone() const = 0;
|
||||
};
|
||||
|
||||
|
||||
// Color
|
||||
class IColour {
|
||||
public:
|
||||
virtual ~IColour() {}
|
||||
|
||||
virtual void SetRed(int red) = 0;
|
||||
virtual void SetGreen(int green) = 0;
|
||||
virtual void SetBlue(int blue) = 0;
|
||||
virtual void SetAlpha(int alpha) = 0;
|
||||
|
||||
virtual int GetRed() const = 0;
|
||||
virtual int GetGreen() const = 0;
|
||||
virtual int GetBlue() const = 0;
|
||||
virtual int GetAlpha() const = 0;
|
||||
|
||||
virtual void Parse(String str,bool reverse) = 0;
|
||||
virtual String GetVBHex(bool withAlpha=false,bool withHeader=true,bool withFooter=true) const = 0;
|
||||
};
|
||||
|
||||
|
||||
// Types
|
||||
enum SectionEntryType {
|
||||
SECTION_ENTRY_PLAIN,
|
||||
SECTION_ENTRY_DIALOGUE,
|
||||
SECTION_ENTRY_STYLE,
|
||||
SECTION_ENTRY_FILE,
|
||||
SECTION_ENTRY_RAW
|
||||
};
|
||||
|
||||
|
||||
// Entry
|
||||
class IEntry {
|
||||
public:
|
||||
virtual ~IEntry() {}
|
||||
|
||||
virtual DeltaCoder GetDeltaCoder() const { return DeltaCoder(); }
|
||||
|
||||
virtual bool IsIndexable() const { return false; }
|
||||
virtual String GetIndexName() const { return L""; }
|
||||
virtual String GetDefaultGroup() const = 0;
|
||||
|
||||
virtual Entry Clone() const = 0;
|
||||
|
||||
/*
|
||||
static PlainTextPtr GetAsPlain(EntryPtr ptr);
|
||||
static DialoguePtr GetAsDialogue(EntryPtr ptr);
|
||||
static DialogueConstPtr GetAsDialogue(EntryConstPtr ptr);
|
||||
static StylePtr GetAsStyle(EntryPtr ptr);
|
||||
static AttachmentPtr GetAsFile(EntryPtr ptr);
|
||||
static RawEntryPtr GetAsRaw(EntryPtr ptr);
|
||||
*/
|
||||
};
|
||||
|
||||
|
||||
// Dialogue
|
||||
class IDialogue : public IEntry {
|
||||
public:
|
||||
// Destructor
|
||||
virtual ~IDialogue() {}
|
||||
|
||||
// Type
|
||||
SectionEntryType GetType() const { return SECTION_ENTRY_DIALOGUE; }
|
||||
Dialogue GetAsDialogue() { return Dialogue(this); }
|
||||
|
||||
// Capabilities
|
||||
virtual bool HasText() const { return false; }
|
||||
virtual bool HasImage() const { return false; }
|
||||
virtual bool HasTime() const { return false; }
|
||||
virtual bool HasFrame() const { return false; }
|
||||
virtual bool HasStyle() const { return false; }
|
||||
virtual bool HasActor() const { return false; }
|
||||
virtual bool HasMargins() const { return false; }
|
||||
|
||||
// Read accessors
|
||||
virtual const String& GetText() const = 0;
|
||||
virtual const ITime& GetStartTime() const = 0;
|
||||
virtual const ITime& GetEndTime() const = 0;
|
||||
virtual int GetStartFrame() const = 0;
|
||||
virtual int GetEndFrame() const = 0;
|
||||
virtual bool IsComment() const = 0;
|
||||
virtual int GetLayer() const = 0;
|
||||
virtual int GetMargin(int n) const = 0;
|
||||
virtual const String& GetStyle() const = 0;
|
||||
virtual const String& GetActor() const = 0;
|
||||
virtual const String& GetUserField() const = 0;
|
||||
|
||||
// Write accessors
|
||||
virtual void SetText(const String& text) = 0;
|
||||
virtual void SetStartTime(Time start) = 0;
|
||||
virtual void SetEndTime(Time end) = 0;
|
||||
virtual void SetStartFrame(int start) = 0;
|
||||
virtual void SetEndFrame(int end) = 0;
|
||||
virtual void SetComment(bool isComment) = 0;
|
||||
virtual void SetLayer(int layer) = 0;
|
||||
virtual void SetMargin(int margin,int value) = 0;
|
||||
virtual void SetStyle(const String& style) = 0;
|
||||
virtual void SetActor(const String& actor) = 0;
|
||||
virtual void SetUserField(const String& userField) = 0;
|
||||
};
|
||||
|
||||
|
||||
// Style
|
||||
class IStyle : public IEntry {
|
||||
public:
|
||||
virtual ~IStyle() {}
|
||||
|
||||
// Type
|
||||
SectionEntryType GetType() const { return SECTION_ENTRY_STYLE; }
|
||||
Style GetAsStyle() { return Style(this); }
|
||||
|
||||
// Read accessors
|
||||
virtual String GetName() const = 0;
|
||||
virtual String GetFontName() const = 0;
|
||||
virtual float GetFontSize() const = 0;
|
||||
virtual const IColour& GetColour(int n) const = 0;
|
||||
virtual int GetMargin(int n) const = 0;
|
||||
};
|
||||
|
||||
|
||||
// Format
|
||||
class IFormat {
|
||||
public:
|
||||
virtual ~IFormat() {}
|
||||
|
||||
virtual String GetName() const = 0;
|
||||
virtual StringArray GetReadExtensions() const = 0;
|
||||
virtual StringArray GetWriteExtensions() const = 0;
|
||||
//virtual FormatHandler GetHandler(Model &model) const = 0;
|
||||
|
||||
virtual bool CanStoreText() const = 0;
|
||||
virtual bool CanStoreImages() const = 0;
|
||||
virtual bool CanUseTime() const = 0;
|
||||
virtual bool CanUseFrames() const = 0;
|
||||
|
||||
virtual bool HasStyles() const = 0;
|
||||
virtual bool HasMargins() const = 0;
|
||||
virtual bool HasActors() const = 0;
|
||||
virtual bool HasUserField() const = 0;
|
||||
virtual String GetUserFieldName() const = 0;
|
||||
|
||||
virtual int GetTimingPrecision() const = 0; // In milliseconds
|
||||
virtual int GetMaxTime() const = 0; // In milliseconds
|
||||
|
||||
virtual Dialogue CreateDialogue() const = 0;
|
||||
virtual Style CreateStyle() const = 0;
|
||||
};
|
||||
|
||||
|
||||
// Format handler
|
||||
class IFormatHandler {
|
||||
public:
|
||||
virtual ~IFormatHandler() {}
|
||||
};
|
||||
|
||||
|
||||
// Action interface
|
||||
class IAction;
|
||||
typedef shared_ptr<IAction> Action;
|
||||
class IAction {
|
||||
public:
|
||||
virtual ~IAction() {}
|
||||
virtual Action GetAntiAction(ConstModel model) const = 0;
|
||||
virtual void Execute(Model model) = 0;
|
||||
|
||||
Section GetSection(Model model,const String &name) const { return model->GetSection(name); }
|
||||
};
|
||||
|
||||
|
||||
// Action list
|
||||
class IActionList {
|
||||
public:
|
||||
virtual ~IActionList() {}
|
||||
|
||||
virtual String GetName() const = 0;
|
||||
virtual String GetOwner() const = 0;
|
||||
|
||||
virtual void AddAction(const Action action) = 0;
|
||||
virtual void Finish() = 0;
|
||||
|
||||
virtual void InsertLine(Entry line,int position=-1,const String section=L"") = 0;
|
||||
virtual void RemoveLine(int position,const String section) = 0;
|
||||
virtual Entry ModifyLine(int position,const String section) = 0;
|
||||
virtual std::vector<Entry> ModifyLines(Selection selection,const String section) = 0;
|
||||
};
|
||||
|
||||
|
||||
// Section
|
||||
class ISection {
|
||||
public:
|
||||
virtual ~ISection() {}
|
||||
|
||||
// Section name
|
||||
virtual void SetName(const String& newName) = 0;
|
||||
virtual const String& GetName() const = 0;
|
||||
|
||||
// Script properties
|
||||
virtual void SetProperty(const String &key,const String &value) = 0;
|
||||
virtual void UnsetProperty(const String &key) = 0;
|
||||
virtual String GetProperty(const String &key) const = 0;
|
||||
virtual bool HasProperty(const String &key) const = 0;
|
||||
virtual size_t GetPropertyCount() const = 0;
|
||||
virtual String GetPropertyName(size_t index) const = 0;
|
||||
|
||||
// Indexed
|
||||
virtual Entry GetFromIndex(String key) const = 0;
|
||||
|
||||
// Entries
|
||||
virtual void AddEntry(Entry entry,int pos=-1) = 0;
|
||||
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 size_t GetEntryCount() const = 0;
|
||||
};
|
||||
|
||||
|
||||
// Delta coder
|
||||
class IDeltaCoder {
|
||||
public:
|
||||
virtual ~IDeltaCoder() {}
|
||||
virtual VoidPtr EncodeDelta(VoidPtr from,VoidPtr to,bool withTextFields=true) const = 0;
|
||||
virtual VoidPtr EncodeReverseDelta(VoidPtr delta,VoidPtr object) const = 0;
|
||||
virtual void ApplyDelta(VoidPtr delta,VoidPtr object) const = 0;
|
||||
};
|
||||
|
||||
|
||||
// Library
|
||||
class ILibAthenaSub {
|
||||
public:
|
||||
virtual ~ILibAthenaSub() {}
|
||||
|
||||
virtual Model CreateModel()=0;
|
||||
};
|
||||
typedef shared_ptr<ILibAthenaSub> LibAthenaSub;
|
||||
|
||||
|
||||
// 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(); }
|
||||
|
||||
}
|
|
@ -34,7 +34,8 @@
|
|||
//
|
||||
|
||||
#pragma once
|
||||
#include "exception.h"
|
||||
//#include "exception.h"
|
||||
#include "interfaces.h"
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
|
@ -49,7 +50,9 @@ namespace Athenasub {
|
|||
|
||||
size_t GetLine(size_t n) const {
|
||||
if (start+n < end) return start+n;
|
||||
else THROW_ATHENA_EXCEPTION(Exception::Out_Of_Range);
|
||||
//else THROW_ATHENA_EXCEPTION(Exception::Out_Of_Range);
|
||||
// TODO: fixme
|
||||
throw 0;
|
||||
}
|
||||
size_t GetSize() const { return end-start; }
|
||||
size_t GetStart() const { return start; }
|
|
@ -33,45 +33,38 @@
|
|||
// Contact: mailto:amz@aegisub.net
|
||||
//
|
||||
|
||||
#include "athenasub.h"
|
||||
#include "action.h"
|
||||
#include "model.h"
|
||||
using namespace Athenasub;
|
||||
|
||||
|
||||
////////////////////////////////
|
||||
// Get a section from the model
|
||||
SectionPtr Action::GetSection(const Model &model,const String &name) const
|
||||
{
|
||||
return model.GetSection(name);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////// Insert line /////////////////////////////
|
||||
|
||||
///////////////
|
||||
// Constructor
|
||||
ActionInsert::ActionInsert(shared_ptr<Entry> data,int line,const String &sName)
|
||||
ActionInsert::ActionInsert(Entry data,int line,const String &sName)
|
||||
: entry(data), lineNumber(line), section(sName) {}
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Create anti-action for insert
|
||||
ActionPtr ActionInsert::GetAntiAction(const Model &model) const
|
||||
Action ActionInsert::GetAntiAction(ConstModel model) const
|
||||
{
|
||||
(void) model;
|
||||
String sect = section;
|
||||
if (section.IsEmpty()) sect = entry->GetDefaultGroup();
|
||||
return ActionPtr(new ActionRemove(lineNumber,sect));
|
||||
return Action(new ActionRemove(lineNumber,sect));
|
||||
}
|
||||
|
||||
|
||||
/////////////////////
|
||||
// Execute insertion
|
||||
void ActionInsert::Execute(Model &model)
|
||||
void ActionInsert::Execute(Model model)
|
||||
{
|
||||
// Find the section to insert it on
|
||||
String sectionName = section;
|
||||
if (sectionName.IsEmpty()) sectionName = entry->GetDefaultGroup();
|
||||
SectionPtr sect = GetSection(model,sectionName);
|
||||
Section sect = GetSection(model,sectionName);
|
||||
|
||||
// Insert the line
|
||||
sect->AddEntry(entry,lineNumber);
|
||||
|
@ -90,17 +83,17 @@ ActionRemove::ActionRemove(int line,const String &sName)
|
|||
|
||||
/////////////////////////////////
|
||||
// Create anti-action for remove
|
||||
ActionPtr ActionRemove::GetAntiAction(const Model &model) const
|
||||
Action ActionRemove::GetAntiAction(ConstModel model) const
|
||||
{
|
||||
SectionPtr sect = GetSection(model,section);
|
||||
EntryPtr entry = sect->GetEntry(lineNumber);
|
||||
return ActionPtr(new ActionInsert(entry,lineNumber,section));
|
||||
Entry entry = sect->GetEntry(lineNumber);
|
||||
return Action(new ActionInsert(entry,lineNumber,section));
|
||||
}
|
||||
|
||||
|
||||
///////////////////
|
||||
// Execute removal
|
||||
void ActionRemove::Execute(Model &model)
|
||||
void ActionRemove::Execute(Model model)
|
||||
{
|
||||
// Find the section to remote it from
|
||||
String sect = section;
|
||||
|
@ -116,7 +109,7 @@ void ActionRemove::Execute(Model &model)
|
|||
|
||||
////////////////
|
||||
// Constructors
|
||||
ActionModify::ActionModify(shared_ptr<Entry> data,int line,const String &sName,bool _noTextFields)
|
||||
ActionModify::ActionModify(Entry data,int line,const String &sName,bool _noTextFields)
|
||||
: entry(data), lineNumber(line), section(sName), noTextFields(_noTextFields) {}
|
||||
|
||||
ActionModify::ActionModify(shared_ptr<void> _delta,int line,const String &sName)
|
||||
|
@ -125,40 +118,40 @@ ActionModify::ActionModify(shared_ptr<void> _delta,int line,const String &sName)
|
|||
|
||||
/////////////////////////////////
|
||||
// Create anti-action for insert
|
||||
ActionPtr ActionModify::GetAntiAction(const Model &model) const
|
||||
Action ActionModify::GetAntiAction(ConstModel model) const
|
||||
{
|
||||
// Get section and original line
|
||||
SectionPtr sect = GetSection(model,section);
|
||||
EntryPtr oldEntry = sect->GetEntry(lineNumber);
|
||||
Section sect = GetSection(model,section);
|
||||
Entry oldEntry = sect->GetEntry(lineNumber);
|
||||
|
||||
// Try to get a delta
|
||||
DeltaCoderPtr deltaCoder = oldEntry->GetDeltaCoder();
|
||||
DeltaCoder deltaCoder = oldEntry->GetDeltaCoder();
|
||||
if (deltaCoder) {
|
||||
VoidPtr _delta;
|
||||
if (entry) _delta = deltaCoder->EncodeDelta(entry,oldEntry,!noTextFields);
|
||||
else _delta = deltaCoder->EncodeReverseDelta(delta,oldEntry);
|
||||
return ActionPtr(new ActionModify(_delta,lineNumber,section));
|
||||
return Action(new ActionModify(_delta,lineNumber,section));
|
||||
}
|
||||
|
||||
// Store the whole original line
|
||||
else {
|
||||
return ActionPtr(new ActionModify(oldEntry,lineNumber,section,noTextFields));
|
||||
return Action(new ActionModify(oldEntry,lineNumber,section,noTextFields));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////
|
||||
// Execute insertion
|
||||
void ActionModify::Execute(Model &model)
|
||||
void ActionModify::Execute(Model model)
|
||||
{
|
||||
// Find the section to modify
|
||||
String sectionName = section;
|
||||
if (sectionName.IsEmpty()) sectionName = entry->GetDefaultGroup();
|
||||
SectionPtr sect = GetSection(model,sectionName);
|
||||
Section sect = GetSection(model,sectionName);
|
||||
|
||||
// Modify the line
|
||||
if (delta) {
|
||||
EntryPtr &ref = sect->GetEntryRef(lineNumber);
|
||||
Entry ref = sect->GetEntry(lineNumber);
|
||||
ref->GetDeltaCoder()->ApplyDelta(delta,ref);
|
||||
}
|
||||
else sect->GetEntryRef(lineNumber) = entry;
|
||||
|
@ -167,24 +160,24 @@ void ActionModify::Execute(Model &model)
|
|||
|
||||
////////////////////////// Batch Modify line //////////////////////////
|
||||
|
||||
ActionModifyBatch::ActionModifyBatch(std::vector<shared_ptr<Entry> > _entries, std::vector<shared_ptr<void> > _deltas, Selection _selection,const String &_section,bool _noTextFields)
|
||||
ActionModifyBatch::ActionModifyBatch(std::vector<Entry> _entries, std::vector<shared_ptr<void> > _deltas, Selection _selection,const String &_section,bool _noTextFields)
|
||||
: entries(_entries), deltas(_deltas), selection(_selection), section(_section), noTextFields(_noTextFields) {}
|
||||
|
||||
ActionPtr ActionModifyBatch::GetAntiAction(const Model &model) const
|
||||
Action ActionModifyBatch::GetAntiAction(ConstModel model) const
|
||||
{
|
||||
// Get section
|
||||
SectionPtr sect = GetSection(model,section);
|
||||
size_t len = selection.GetCount();
|
||||
size_t len = selection->GetCount();
|
||||
std::vector<VoidPtr> _deltas(len);
|
||||
std::vector<EntryPtr> oldEntries(len);
|
||||
std::vector<Entry> oldEntries(len);
|
||||
|
||||
// For each line...
|
||||
for (size_t i=0;i<len;i++) {
|
||||
// Get old entry
|
||||
EntryPtr oldEntry = sect->GetEntry(selection.GetLine(i));
|
||||
Entry oldEntry = sect->GetEntry(selection->GetLine(i));
|
||||
|
||||
// Try to get a delta
|
||||
DeltaCoderPtr deltaCoder = oldEntry->GetDeltaCoder();
|
||||
DeltaCoder deltaCoder = oldEntry->GetDeltaCoder();
|
||||
if (deltaCoder) {
|
||||
if (i < deltas.size() && deltas[i]) _deltas[i] = deltaCoder->EncodeReverseDelta(deltas[i],oldEntry);
|
||||
_deltas[i] = deltaCoder->EncodeDelta(entries[i],oldEntry,!noTextFields);
|
||||
|
@ -194,23 +187,23 @@ ActionPtr ActionModifyBatch::GetAntiAction(const Model &model) const
|
|||
else oldEntries[i] = oldEntry;
|
||||
}
|
||||
|
||||
return ActionPtr(new ActionModifyBatch(oldEntries,_deltas,selection,section,noTextFields));
|
||||
return Action(new ActionModifyBatch(oldEntries,_deltas,selection,section,noTextFields));
|
||||
}
|
||||
|
||||
void ActionModifyBatch::Execute(Model &model)
|
||||
void ActionModifyBatch::Execute(Model model)
|
||||
{
|
||||
// Find the section to modify
|
||||
size_t len = selection.GetCount();
|
||||
size_t len = selection->GetCount();
|
||||
String sectionName = section;
|
||||
if (sectionName.IsEmpty()) sectionName = entries[0]->GetDefaultGroup();
|
||||
SectionPtr sect = GetSection(model,sectionName);
|
||||
Section sect = GetSection(model,sectionName);
|
||||
|
||||
// For each line...
|
||||
for (size_t i=0;i<len;i++) {
|
||||
if (i < deltas.size() && deltas[i]) {
|
||||
EntryPtr &ref = sect->GetEntryRef(selection.GetLine(i));
|
||||
Entry &ref = sect->GetEntryRef(selection->GetLine(i));
|
||||
ref->GetDeltaCoder()->ApplyDelta(deltas[i],ref);
|
||||
}
|
||||
else sect->GetEntryRef(selection.GetLine(i)) = entries[i];
|
||||
else sect->GetEntryRef(selection->GetLine(i)) = entries[i];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,44 +36,27 @@
|
|||
#pragma once
|
||||
#include "athenastring.h"
|
||||
#include "selection.h"
|
||||
#include "interfaces.h"
|
||||
|
||||
namespace Athenasub {
|
||||
// Prototypes
|
||||
class Model;
|
||||
class Entry;
|
||||
class Action;
|
||||
class Section;
|
||||
typedef shared_ptr<Action> ActionPtr;
|
||||
typedef shared_ptr<Section> SectionPtr;
|
||||
|
||||
// Action interface
|
||||
class Action {
|
||||
protected:
|
||||
SectionPtr GetSection(const Model &model,const String &name) const;
|
||||
|
||||
public:
|
||||
virtual ~Action() {}
|
||||
virtual ActionPtr GetAntiAction(const Model &model) const =0;
|
||||
virtual void Execute(Model &model) =0;
|
||||
};
|
||||
|
||||
// Insert line
|
||||
class ActionInsert : public Action {
|
||||
class ActionInsert : public IAction {
|
||||
private:
|
||||
shared_ptr<Entry> entry;
|
||||
Entry entry;
|
||||
const String section;
|
||||
int lineNumber;
|
||||
|
||||
public:
|
||||
ActionInsert(shared_ptr<Entry> entry,int line,const String §ion);
|
||||
ActionInsert(Entry entry,int line,const String §ion);
|
||||
~ActionInsert() {}
|
||||
|
||||
ActionPtr GetAntiAction(const Model &model) const;
|
||||
void Execute(Model &model);
|
||||
Action GetAntiAction(ConstModel model) const;
|
||||
void Execute(Model model);
|
||||
};
|
||||
|
||||
// Remove line
|
||||
class ActionRemove : public Action {
|
||||
class ActionRemove : public IAction {
|
||||
private:
|
||||
const String section;
|
||||
int lineNumber;
|
||||
|
@ -82,42 +65,42 @@ namespace Athenasub {
|
|||
ActionRemove(int line,const String §ion);
|
||||
~ActionRemove() {}
|
||||
|
||||
ActionPtr GetAntiAction(const Model &model) const;
|
||||
void Execute(Model &model);
|
||||
Action GetAntiAction(ConstModel model) const;
|
||||
void Execute(Model model);
|
||||
};
|
||||
|
||||
// Modify line
|
||||
class ActionModify : public Action {
|
||||
class ActionModify : public IAction {
|
||||
private:
|
||||
shared_ptr<Entry> entry;
|
||||
shared_ptr<void> delta;
|
||||
Entry entry;
|
||||
VoidPtr delta;
|
||||
const String section;
|
||||
int lineNumber;
|
||||
bool noTextFields;
|
||||
|
||||
public:
|
||||
ActionModify(shared_ptr<Entry> entry,int line,const String §ion,bool noTextFields);
|
||||
ActionModify(Entry entry,int line,const String §ion,bool noTextFields);
|
||||
ActionModify(shared_ptr<void> delta,int line,const String §ion);
|
||||
~ActionModify() {}
|
||||
|
||||
ActionPtr GetAntiAction(const Model &model) const;
|
||||
void Execute(Model &model);
|
||||
Action GetAntiAction(ConstModel model) const;
|
||||
void Execute(Model model);
|
||||
};
|
||||
|
||||
// Modify several lines
|
||||
class ActionModifyBatch : public Action {
|
||||
class ActionModifyBatch : public IAction {
|
||||
private:
|
||||
std::vector<shared_ptr<Entry> > entries;
|
||||
std::vector<shared_ptr<void> > deltas;
|
||||
std::vector<Entry> entries;
|
||||
std::vector<VoidPtr> deltas;
|
||||
Selection selection;
|
||||
const String section;
|
||||
bool noTextFields;
|
||||
|
||||
public:
|
||||
ActionModifyBatch(std::vector<shared_ptr<Entry> > entries,std::vector<shared_ptr<void> > deltas,Selection selection,const String §ion,bool noTextFields);
|
||||
ActionModifyBatch(std::vector<Entry> entries,std::vector<VoidPtr> deltas,Selection selection,const String §ion,bool noTextFields);
|
||||
~ActionModifyBatch() {}
|
||||
|
||||
ActionPtr GetAntiAction(const Model &model) const;
|
||||
void Execute(Model &model);
|
||||
Action GetAntiAction(ConstModel model) const;
|
||||
void Execute(Model model);
|
||||
};
|
||||
}
|
|
@ -33,13 +33,14 @@
|
|||
// Contact: mailto:amz@aegisub.net
|
||||
//
|
||||
|
||||
#include "Athenasub.h"
|
||||
#include "actionlist.h"
|
||||
#include "model.h"
|
||||
using namespace Athenasub;
|
||||
|
||||
|
||||
///////////////
|
||||
// Constructor
|
||||
ActionList::ActionList(Model &_model,String _actionName,const String _owner,bool _undoAble)
|
||||
CActionList::CActionList(Model _model,String _actionName,const String _owner,bool _undoAble)
|
||||
: model(_model), owner(_owner), undoAble(_undoAble)
|
||||
{
|
||||
valid = false;
|
||||
|
@ -49,14 +50,14 @@ ActionList::ActionList(Model &_model,String _actionName,const String _owner,bool
|
|||
|
||||
//////////////
|
||||
// Destructor
|
||||
ActionList::~ActionList()
|
||||
CActionList::~CActionList()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////
|
||||
// Add an action to the queue
|
||||
void ActionList::AddAction(const ActionPtr action)
|
||||
void CActionList::AddAction(const Action action)
|
||||
{
|
||||
if (!valid) THROW_ATHENA_EXCEPTION(Exception::Invalid_ActionList);
|
||||
actions.push_back(action);
|
||||
|
@ -69,7 +70,7 @@ void ActionList::AddAction(const ActionPtr action)
|
|||
|
||||
///////////////////////////////////////////
|
||||
// Add an action to the start of the queue
|
||||
void ActionList::AddActionStart(const ActionPtr action)
|
||||
void CActionList::AddActionStart(const Action action)
|
||||
{
|
||||
if (!valid) THROW_ATHENA_EXCEPTION(Exception::Invalid_ActionList);
|
||||
actions.push_front(action);
|
||||
|
@ -82,7 +83,7 @@ void ActionList::AddActionStart(const ActionPtr action)
|
|||
|
||||
/////////////////////////////
|
||||
// Starts performing actions
|
||||
void ActionList::Start(const String name)
|
||||
void CActionList::Start(const String name)
|
||||
{
|
||||
if (valid) Finish();
|
||||
actionName = name;
|
||||
|
@ -92,10 +93,10 @@ void ActionList::Start(const String name)
|
|||
|
||||
////////////////////////
|
||||
// Ends the action list
|
||||
void ActionList::Finish()
|
||||
void CActionList::Finish()
|
||||
{
|
||||
if (valid) {
|
||||
model.ProcessActionList(*this);
|
||||
model->ProcessActionList(ActionList(this));
|
||||
actions.clear();
|
||||
valid = false;
|
||||
}
|
||||
|
@ -104,29 +105,29 @@ void ActionList::Finish()
|
|||
|
||||
//////////////////////////////////
|
||||
// Create an "insert line" action
|
||||
void ActionList::InsertLine(EntryPtr line,int position,const String section)
|
||||
void CActionList::InsertLine(Entry line,int position,const String section)
|
||||
{
|
||||
ActionPtr action = ActionPtr (new ActionInsert(line,position,section));
|
||||
Action action = Action (new ActionInsert(line,position,section));
|
||||
AddAction(action);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Create a "remove line" action
|
||||
void ActionList::RemoveLine(int position,const String section)
|
||||
void CActionList::RemoveLine(int position,const String section)
|
||||
{
|
||||
ActionPtr action = ActionPtr (new ActionRemove(position,section));
|
||||
Action action = Action (new ActionRemove(position,section));
|
||||
AddAction(action);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Insert a "modify line" action
|
||||
EntryPtr ActionList::ModifyLine(int position,const String section)
|
||||
Entry CActionList::ModifyLine(int position,const String section)
|
||||
{
|
||||
SectionPtr sect = model.GetSection(section);
|
||||
EntryPtr entry = sect->GetEntry(position)->Clone();
|
||||
ActionPtr action = ActionPtr (new ActionModify(entry,position,section,false));
|
||||
Section sect = model->GetSection(section);
|
||||
Entry entry = sect->GetEntry(position)->Clone();
|
||||
Action action = Action (new ActionModify(entry,position,section,false));
|
||||
AddAction(action);
|
||||
return entry;
|
||||
}
|
||||
|
@ -134,24 +135,24 @@ EntryPtr ActionList::ModifyLine(int position,const String section)
|
|||
|
||||
////////////////////////////////////////
|
||||
// Insert a "modify lines" batch action
|
||||
std::vector<EntryPtr> ActionList::ModifyLines(Selection selection,const String section)
|
||||
std::vector<Entry> CActionList::ModifyLines(Selection selection,const String section)
|
||||
{
|
||||
// Get section
|
||||
SectionPtr sect = model.GetSection(section);
|
||||
Section sect = model->GetSection(section);
|
||||
|
||||
// Generate entries
|
||||
std::vector<EntryPtr> entries(selection.GetCount());
|
||||
size_t len = selection.GetRanges();
|
||||
std::vector<Entry> entries(selection->GetCount());
|
||||
size_t len = selection->GetRanges();
|
||||
size_t n = 0;
|
||||
for (size_t i=0;i<len;i++) {
|
||||
size_t rLen = selection.GetLinesInRange(i);
|
||||
size_t rLen = selection->GetLinesInRange(i);
|
||||
for (size_t j=0;j<rLen;j++) {
|
||||
entries[n++] = sect->GetEntry(selection.GetLineInRange(j,i))->Clone();
|
||||
entries[n++] = sect->GetEntry(selection->GetLineInRange(j,i))->Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Generate the action
|
||||
ActionPtr action = ActionPtr (new ActionModifyBatch(entries,std::vector<VoidPtr>(),selection,section,false));
|
||||
Action action = Action (new ActionModifyBatch(entries,std::vector<VoidPtr>(),selection,section,false));
|
||||
AddAction(action);
|
||||
return entries;
|
||||
}
|
||||
|
|
|
@ -40,43 +40,44 @@
|
|||
#include "section_entry.h"
|
||||
#include "selection.h"
|
||||
#include "api.h"
|
||||
#include "model.h"
|
||||
#include "interfaces.h"
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
// Prototypes
|
||||
class Controller;
|
||||
class CController;
|
||||
|
||||
// ActionList class
|
||||
class ActionList {
|
||||
friend class Model;
|
||||
friend class Controller;
|
||||
class CActionList : public IActionList {
|
||||
friend class CModel;
|
||||
friend class CController;
|
||||
|
||||
private:
|
||||
String actionName;
|
||||
String owner;
|
||||
Model &model;
|
||||
std::list<ActionPtr> actions;
|
||||
Model model;
|
||||
std::list<Action> actions;
|
||||
bool valid;
|
||||
bool undoAble;
|
||||
|
||||
ActionList(Model &model,const String actionName,const String owner,bool undoAble);
|
||||
CActionList(Model model,const String actionName,const String owner,bool undoAble);
|
||||
void Start(const String actionName);
|
||||
void AddActionStart(const ActionPtr action);
|
||||
void AddActionStart(const Action action);
|
||||
|
||||
public:
|
||||
~ActionList();
|
||||
virtual ~CActionList();
|
||||
|
||||
String GetName() const { return actionName; }
|
||||
String GetOwner() const { return owner; }
|
||||
virtual String GetName() const { return actionName; }
|
||||
virtual String GetOwner() const { return owner; }
|
||||
|
||||
void AddAction(const ActionPtr action);
|
||||
void Finish();
|
||||
virtual void AddAction(const Action action);
|
||||
virtual void Finish();
|
||||
|
||||
void InsertLine(EntryPtr line,int position=-1,const String section=L"");
|
||||
void RemoveLine(int position,const String section);
|
||||
EntryPtr ModifyLine(int position,const String section);
|
||||
std::vector<EntryPtr> ModifyLines(Selection selection,const String section);
|
||||
virtual void InsertLine(Entry line,int position=-1,const String section=L"");
|
||||
virtual void RemoveLine(int position,const String section);
|
||||
virtual Entry ModifyLine(int position,const String section);
|
||||
virtual std::vector<Entry> ModifyLines(Selection selection,const String section);
|
||||
};
|
||||
typedef shared_ptr<ActionList> ActionListPtr;
|
||||
|
||||
}
|
|
@ -34,34 +34,27 @@
|
|||
//
|
||||
|
||||
#pragma once
|
||||
#include "athenastring.h"
|
||||
#include "athenasub.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
// Time class
|
||||
class Time {
|
||||
class CTime : public ITime {
|
||||
private:
|
||||
int ms;
|
||||
|
||||
public:
|
||||
Time() { ms = 0; }
|
||||
Time(int _ms) { ms = _ms; }
|
||||
CTime() { ms = 0; }
|
||||
CTime(int _ms) { ms = _ms; }
|
||||
|
||||
void SetMS(int milliseconds) { ms = milliseconds; }
|
||||
int GetMS() const { return ms; }
|
||||
|
||||
String GetString(int ms_precision,int h_precision) const;
|
||||
void Parse(const String &data);
|
||||
void ParseString(const String &data);
|
||||
|
||||
Time operator + (const int &par) const { return Max<int>(0,ms+par); }
|
||||
Time operator - (const int &par) const { return Max<int>(0,ms-par); }
|
||||
bool operator == (const Time &par) const { return ms == par.ms; }
|
||||
bool operator != (const Time &par) const { return ms != par.ms; }
|
||||
bool operator < (const Time &par) const { return ms < par.ms; }
|
||||
bool operator > (const Time &par) const { return ms > par.ms; }
|
||||
bool operator <= (const Time &par) const { return ms <= par.ms; }
|
||||
bool operator >= (const Time &par) const { return ms >= par.ms; }
|
||||
Time Clone() const { return Time(new CTime(*this)); }
|
||||
};
|
||||
|
||||
}
|
|
@ -35,23 +35,25 @@
|
|||
|
||||
|
||||
#include "Athenasub.h"
|
||||
#include "colour.h"
|
||||
#include "utils.h"
|
||||
using namespace Athenasub;
|
||||
|
||||
|
||||
////////////////
|
||||
// Constructors
|
||||
Colour::Colour ()
|
||||
CColour::CColour ()
|
||||
{
|
||||
r = g = b = a = 0;
|
||||
}
|
||||
Colour::Colour (unsigned char red,unsigned char green,unsigned char blue,unsigned char alpha)
|
||||
CColour::CColour (unsigned char red,unsigned char green,unsigned char blue,unsigned char alpha)
|
||||
{
|
||||
r = red;
|
||||
g = green;
|
||||
b = blue;
|
||||
a = alpha;
|
||||
}
|
||||
Colour::Colour (int red,int green,int blue,int alpha)
|
||||
CColour::CColour (int red,int green,int blue,int alpha)
|
||||
{
|
||||
SetRed(red);
|
||||
SetGreen(green);
|
||||
|
@ -62,15 +64,15 @@ Colour::Colour (int red,int green,int blue,int alpha)
|
|||
|
||||
////////////////////////
|
||||
// Set colour component
|
||||
void Colour::SetRed(int red) { r = (unsigned char) Mid(0,red,255); }
|
||||
void Colour::SetGreen(int green) { g = (unsigned char) Mid(0,green,255); }
|
||||
void Colour::SetBlue(int blue) { b = (unsigned char) Mid(0,blue,255); }
|
||||
void Colour::SetAlpha(int alpha) { a = (unsigned char) Mid(0,alpha,255); }
|
||||
void CColour::SetRed(int red) { r = (unsigned char) Mid(0,red,255); }
|
||||
void CColour::SetGreen(int green) { g = (unsigned char) Mid(0,green,255); }
|
||||
void CColour::SetBlue(int blue) { b = (unsigned char) Mid(0,blue,255); }
|
||||
void CColour::SetAlpha(int alpha) { a = (unsigned char) Mid(0,alpha,255); }
|
||||
|
||||
|
||||
//////////////
|
||||
// Parse text
|
||||
void Colour::Parse(String value,bool reverse)
|
||||
void CColour::Parse(String value,bool reverse)
|
||||
{
|
||||
// Prepare
|
||||
unsigned char c;
|
||||
|
@ -110,7 +112,7 @@ void Colour::Parse(String value,bool reverse)
|
|||
|
||||
/////////////////////////////
|
||||
// Generate Visual Basic hex
|
||||
String Colour::GetVBHex(bool withAlpha,bool withHeader,bool withFooter) const
|
||||
String CColour::GetVBHex(bool withAlpha,bool withHeader,bool withFooter) const
|
||||
{
|
||||
wxString work;
|
||||
if (withHeader) work += _T("&H");
|
||||
|
|
|
@ -34,19 +34,19 @@
|
|||
//
|
||||
|
||||
#pragma once
|
||||
#include "athenastring.h"
|
||||
#include "athenasub.h"
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
// Colour class
|
||||
class Colour {
|
||||
class CColour : public IColour {
|
||||
private:
|
||||
unsigned char r, g, b, a;
|
||||
|
||||
public:
|
||||
Colour ();
|
||||
Colour (unsigned char red,unsigned char green,unsigned char blue,unsigned char alpha=0);
|
||||
Colour (int red,int green,int blue,int alpha=0);
|
||||
CColour ();
|
||||
CColour (unsigned char red,unsigned char green,unsigned char blue,unsigned char alpha=0);
|
||||
CColour (int red,int green,int blue,int alpha=0);
|
||||
|
||||
void SetRed(unsigned char red) { r = red; }
|
||||
void SetGreen(unsigned char green) { g = green; }
|
||||
|
@ -57,10 +57,10 @@ namespace Athenasub {
|
|||
void SetBlue(int blue);
|
||||
void SetAlpha(int alpha);
|
||||
|
||||
unsigned char GetRed() const { return r; }
|
||||
unsigned char GetGreen() const { return g; }
|
||||
unsigned char GetBlue() const { return b; }
|
||||
unsigned char GetAlpha() const { return a; }
|
||||
int GetRed() const { return r; }
|
||||
int GetGreen() const { return g; }
|
||||
int GetBlue() const { return b; }
|
||||
int GetAlpha() const { return a; }
|
||||
|
||||
void Parse(String str,bool reverse);
|
||||
String GetVBHex(bool withAlpha=false,bool withHeader=true,bool withFooter=true) const;
|
|
@ -34,13 +34,15 @@
|
|||
//
|
||||
|
||||
#include "controller.h"
|
||||
#include "Athenasub.h"
|
||||
#include "athenasub.h"
|
||||
#include "actionlist.h"
|
||||
#include "format_manager.h"
|
||||
using namespace Athenasub;
|
||||
|
||||
|
||||
///////////////
|
||||
// Constructor
|
||||
Controller::Controller(Model &_model)
|
||||
CController::CController(Model _model)
|
||||
: model(_model)
|
||||
{
|
||||
}
|
||||
|
@ -48,47 +50,47 @@ Controller::Controller(Model &_model)
|
|||
|
||||
/////////////////////////
|
||||
// Create an action list
|
||||
ActionListPtr Controller::CreateActionList(const String title,const String owner,bool undoAble)
|
||||
ActionList CController::CreateActionList(const String title,const String owner,bool undoAble)
|
||||
{
|
||||
return ActionListPtr (new ActionList(model,title,owner,undoAble));
|
||||
return ActionList (new CActionList(model,title,owner,undoAble));
|
||||
}
|
||||
|
||||
|
||||
///////////////
|
||||
// Load a file
|
||||
void Controller::LoadFile(const String filename,const String encoding)
|
||||
void CController::LoadFile(const String filename,const String encoding)
|
||||
{
|
||||
const FormatPtr handler = FormatManager::GetFormatFromFilename(filename,true);
|
||||
const Format handler = FormatManager::GetFormatFromFilename(filename,true);
|
||||
wxFFileInputStream stream(filename);
|
||||
model.Load(stream,handler,encoding);
|
||||
model->Load(stream,handler,encoding);
|
||||
}
|
||||
|
||||
|
||||
///////////////
|
||||
// Save a file
|
||||
void Controller::SaveFile(const String filename,const String encoding)
|
||||
void CController::SaveFile(const String filename,const String encoding)
|
||||
{
|
||||
const FormatPtr handler = FormatManager::GetFormatFromFilename(filename,true);
|
||||
const Format handler = FormatManager::GetFormatFromFilename(filename,true);
|
||||
wxFFileOutputStream stream(filename);
|
||||
model.Save(stream,handler,encoding);
|
||||
model->Save(stream,handler,encoding);
|
||||
}
|
||||
|
||||
|
||||
//////////////
|
||||
// Get format
|
||||
const FormatPtr Controller::GetFormat() const
|
||||
const Format CController::GetFormat() const
|
||||
{
|
||||
return model.GetFormat();
|
||||
return model->GetFormat();
|
||||
}
|
||||
|
||||
|
||||
//////////////////
|
||||
// Create entries
|
||||
DialoguePtr Controller::CreateDialogue() const
|
||||
Dialogue CController::CreateDialogue() const
|
||||
{
|
||||
return GetFormat()->CreateDialogue();
|
||||
}
|
||||
StylePtr Controller::CreateStyle() const
|
||||
Style CController::CreateStyle() const
|
||||
{
|
||||
return GetFormat()->CreateStyle();
|
||||
}
|
||||
|
@ -96,27 +98,27 @@ StylePtr Controller::CreateStyle() const
|
|||
|
||||
////////
|
||||
// Undo
|
||||
bool Controller::CanUndo(const String owner) const
|
||||
bool CController::CanUndo(const String owner) const
|
||||
{
|
||||
return model.CanUndo(owner);
|
||||
return model->CanUndo(owner);
|
||||
}
|
||||
bool Controller::CanRedo(const String owner) const
|
||||
bool CController::CanRedo(const String owner) const
|
||||
{
|
||||
return model.CanRedo(owner);
|
||||
return model->CanRedo(owner);
|
||||
}
|
||||
void Controller::Undo(const String owner)
|
||||
void CController::Undo(const String owner)
|
||||
{
|
||||
model.Undo(owner);
|
||||
model->Undo(owner);
|
||||
}
|
||||
void Controller::Redo(const String owner)
|
||||
void CController::Redo(const String owner)
|
||||
{
|
||||
model.Redo(owner);
|
||||
model->Redo(owner);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////
|
||||
// Get the nth dialogue
|
||||
DialogueConstPtr Controller::GetDialogue(size_t n) const
|
||||
ConstDialogue CController::GetDialogue(size_t n) const
|
||||
{
|
||||
// TODO
|
||||
(void) n;
|
||||
|
@ -126,7 +128,7 @@ DialogueConstPtr Controller::GetDialogue(size_t n) const
|
|||
|
||||
/////////////////////
|
||||
// Get the nth style
|
||||
DialogueConstPtr Controller::GetStyle(size_t n) const
|
||||
ConstStyle CController::GetStyle(size_t n) const
|
||||
{
|
||||
// TODO
|
||||
(void) n;
|
||||
|
@ -136,24 +138,24 @@ DialogueConstPtr Controller::GetStyle(size_t n) const
|
|||
|
||||
///////////////////////
|
||||
// Get a style by name
|
||||
StyleConstPtr Controller::GetStyle(String name) const
|
||||
ConstStyle CController::GetStyle(String name) const
|
||||
{
|
||||
// Get section
|
||||
StylePtr dummy = CreateStyle();
|
||||
Style dummy = CreateStyle();
|
||||
String section = dummy->GetDefaultGroup();
|
||||
SectionPtr sect = model.GetSection(section);
|
||||
Section sect = model->GetSection(section);
|
||||
if (!sect) THROW_ATHENA_EXCEPTION(Exception::Invalid_Section);
|
||||
|
||||
// Return from index
|
||||
return dynamic_pointer_cast<const Style> (sect->GetFromIndex(name));
|
||||
return dynamic_pointer_cast<const IStyle> (sect->GetFromIndex(name));
|
||||
}
|
||||
|
||||
|
||||
////////////////
|
||||
// Get an entry
|
||||
EntryConstPtr Controller::GetEntry(size_t n,String section) const
|
||||
ConstEntry CController::GetEntry(size_t n,String section) const
|
||||
{
|
||||
SectionPtr sect = model.GetSection(section);
|
||||
Section sect = model->GetSection(section);
|
||||
if (!sect) THROW_ATHENA_EXCEPTION(Exception::Invalid_Section);
|
||||
return sect->GetEntry(n);
|
||||
}
|
||||
|
|
|
@ -34,46 +34,39 @@
|
|||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "athenastring.h"
|
||||
#include <exception>
|
||||
#include "athenasub.h"
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
// Exception class
|
||||
class Exception : public std::exception {
|
||||
public:
|
||||
enum ExceptionList {
|
||||
Unknown,
|
||||
No_Format_Handler,
|
||||
Invalid_ActionList,
|
||||
Section_Already_Exists,
|
||||
Unknown_Format,
|
||||
Parse_Error,
|
||||
Unsupported_Format_Feature,
|
||||
Invalid_Token,
|
||||
Out_Of_Range,
|
||||
Invalid_Section,
|
||||
Internal_Error,
|
||||
TODO
|
||||
};
|
||||
|
||||
Exception(ExceptionList code);
|
||||
Exception(ExceptionList code,const char* file,const long line);
|
||||
|
||||
String GetMessageString() const { return wxString(what(),wxConvLocal); }
|
||||
int GetCode();
|
||||
|
||||
// Controller class
|
||||
class CController : public IController {
|
||||
friend class CModel;
|
||||
|
||||
private:
|
||||
static const char* GetMessageChar(int code);
|
||||
static const char* GetMessageFile(int code,const char *file,long line);
|
||||
ExceptionList code;
|
||||
Model model;
|
||||
CController (Model model);
|
||||
|
||||
public:
|
||||
virtual ActionList CreateActionList(const String title,const String owner=L"",bool undoAble=true);
|
||||
virtual Selection CreateSelection();
|
||||
|
||||
virtual void LoadFile(const String filename,const String encoding=L"");
|
||||
virtual void SaveFile(const String filename,const String encoding=L"UTF-8");
|
||||
|
||||
virtual bool CanUndo(const String owner=L"") const;
|
||||
virtual bool CanRedo(const String owner=L"") const;
|
||||
virtual void Undo(const String owner=L"");
|
||||
virtual void Redo(const String owner=L"");
|
||||
|
||||
virtual Dialogue CreateDialogue() const;
|
||||
virtual Style CreateStyle() const;
|
||||
|
||||
virtual ConstDialogue GetDialogue(size_t n) const;
|
||||
virtual ConstStyle GetStyle(size_t n) const;
|
||||
virtual ConstStyle GetStyle(String name) const;
|
||||
virtual ConstEntry GetEntry(size_t n,String section) const;
|
||||
|
||||
virtual const Format GetFormat() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define THROW_ATHENA_EXCEPTION(code) throw Athenasub::Exception(code,__FILE__,__LINE__)
|
||||
#else
|
||||
#define THROW_ATHENA_EXCEPTION(code) throw Athenasub::Exception(code)
|
||||
#endif
|
|
@ -34,33 +34,32 @@
|
|||
//
|
||||
|
||||
#pragma once
|
||||
#include "athenastring.h"
|
||||
#include "athenasub.h"
|
||||
#include "model.h"
|
||||
#include "tr1.h"
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
// Format handler interface
|
||||
class FormatHandler {
|
||||
class CFormatHandler : public IFormatHandler {
|
||||
private:
|
||||
Model &model;
|
||||
Model model;
|
||||
|
||||
protected:
|
||||
virtual ~FormatHandler() {}
|
||||
virtual ~CFormatHandler() {}
|
||||
|
||||
Model &GetModel() const { return model; }
|
||||
Model GetModel() const { return model; }
|
||||
|
||||
void AddSection(String name) { model.AddSection(name); }
|
||||
SectionPtr GetSection(String name) const { return model.GetSection(name); }
|
||||
SectionPtr 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:
|
||||
FormatHandler(Model &_model) : model(_model) {}
|
||||
CFormatHandler(Model _model) : model(_model) {}
|
||||
|
||||
virtual void Load(wxInputStream &file,const String encoding) = 0;
|
||||
virtual void Save(wxOutputStream &file,const String encoding) = 0;
|
||||
};
|
||||
typedef shared_ptr<FormatHandler> FormatHandlerPtr;
|
||||
|
||||
}
|
|
@ -34,26 +34,25 @@
|
|||
//
|
||||
|
||||
#pragma once
|
||||
#include "format.h"
|
||||
#include "api.h"
|
||||
#include "athenasub.h"
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
// Format manager class
|
||||
class FormatManager {
|
||||
private:
|
||||
static std::vector<const FormatPtr> formats;
|
||||
static std::vector<Format> formats;
|
||||
FormatManager() {}
|
||||
|
||||
public:
|
||||
static void AddFormat(const FormatPtr format);
|
||||
static void AddFormat(Format format);
|
||||
static void InitializeFormats();
|
||||
static void ClearFormats();
|
||||
|
||||
static int GetFormatCount();
|
||||
static const FormatPtr GetFormatByIndex(const int index);
|
||||
static const FormatPtr GetFormatFromFilename(const String &filename,bool read);
|
||||
static const FormatPtr GetFormatFromName(const String &name);
|
||||
static const Format GetFormatByIndex(const int index);
|
||||
static const Format GetFormatFromFilename(const String &filename,bool read);
|
||||
static const Format GetFormatFromName(const String &name);
|
||||
};
|
||||
|
||||
}
|
|
@ -89,8 +89,8 @@ StringArray FormatASS2::GetWriteExtensions() const
|
|||
|
||||
///////////////
|
||||
// Constructor
|
||||
FormatHandlerASS::FormatHandlerASS(Model &_model,int version)
|
||||
: FormatHandler(_model), formatVersion(version)
|
||||
FormatHandlerASS::FormatHandlerASS(CModel &_model,int version)
|
||||
: CFormatHandler(_model), formatVersion(version)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
//
|
||||
|
||||
#pragma once
|
||||
#include "format.h"
|
||||
#include "format_handler.h"
|
||||
#include "format_ass_dialogue.h"
|
||||
#include "format_ass_style.h"
|
||||
|
@ -46,21 +45,21 @@
|
|||
namespace Athenasub {
|
||||
|
||||
// Prototypes
|
||||
class Model;
|
||||
class CModel;
|
||||
class TextFileWriter;
|
||||
|
||||
// Advanced Substation Alpha format handler
|
||||
class FormatHandlerASS : public FormatHandler {
|
||||
class FormatHandlerASS : public CFormatHandler {
|
||||
private:
|
||||
int formatVersion;
|
||||
|
||||
EntryPtr MakeEntry(const String &data,SectionPtr section,int version);
|
||||
Entry MakeEntry(const String &data,SectionPtr section,int version);
|
||||
void ProcessGroup(String cur,String &curGroup,int &version);
|
||||
void WriteSection(TextFileWriter &writer,SectionPtr section);
|
||||
void MakeValid();
|
||||
|
||||
public:
|
||||
FormatHandlerASS(Model &model,int version);
|
||||
FormatHandlerASS(CModel &model,int version);
|
||||
~FormatHandlerASS();
|
||||
|
||||
void Load(wxInputStream &file,const String encoding);
|
||||
|
@ -79,14 +78,14 @@ namespace Athenasub {
|
|||
bool HasMargins() const { return true; }
|
||||
bool HasActors() const { return true; }
|
||||
|
||||
DialoguePtr CreateDialogue() const { return DialoguePtr(new DialogueASS()); }
|
||||
StylePtr CreateStyle() const { return StylePtr(new StyleASS()); }
|
||||
Dialogue CreateDialogue() const { return Dialogue(new DialogueASS()); }
|
||||
Style CreateStyle() const { return Style(new StyleASS()); }
|
||||
};
|
||||
|
||||
// Substation Alpha
|
||||
class FormatSSA : public FormatASSFamily {
|
||||
public:
|
||||
FormatHandlerPtr GetHandler(Model &model) const { return FormatHandlerPtr(new FormatHandlerASS(model,0)); }
|
||||
FormatHandler GetHandler(CModel &model) const { return FormatHandler(new FormatHandlerASS(model,0)); }
|
||||
String GetName() const { return L"Substation Alpha"; }
|
||||
StringArray GetReadExtensions() const;
|
||||
StringArray GetWriteExtensions() const;
|
||||
|
@ -95,7 +94,7 @@ namespace Athenasub {
|
|||
// Advanced Substation Alpha
|
||||
class FormatASS : public FormatASSFamily {
|
||||
public:
|
||||
FormatHandlerPtr GetHandler(Model &model) const { return FormatHandlerPtr(new FormatHandlerASS(model,1)); }
|
||||
FormatHandler GetHandler(CModel &model) const { return FormatHandler(new FormatHandlerASS(model,1)); }
|
||||
String GetName() const { return L"Advanced Substation Alpha"; }
|
||||
StringArray GetReadExtensions() const;
|
||||
StringArray GetWriteExtensions() const;
|
||||
|
@ -104,7 +103,7 @@ namespace Athenasub {
|
|||
// Advanced Substation Alpha 2
|
||||
class FormatASS2 : public FormatASSFamily {
|
||||
public:
|
||||
FormatHandlerPtr GetHandler(Model &model) const { return FormatHandlerPtr(new FormatHandlerASS(model,2)); }
|
||||
FormatHandler GetHandler(CModel &model) const { return FormatHandler(new FormatHandlerASS(model,2)); }
|
||||
String GetName() const { return L"Advanced Substation Alpha 2"; }
|
||||
StringArray GetReadExtensions() const;
|
||||
StringArray GetWriteExtensions() const;
|
||||
|
|
|
@ -97,8 +97,8 @@ bool DialogueASS::Parse(wxString rawData, int version)
|
|||
}
|
||||
|
||||
// Get times
|
||||
time[0].Parse(tkn.GetString());
|
||||
time[1].Parse(tkn.GetString());
|
||||
time[0].ParseString(tkn.GetString());
|
||||
time[1].ParseString(tkn.GetString());
|
||||
|
||||
// Get style and actor
|
||||
text[1] = tkn.GetString(true);
|
||||
|
|
|
@ -38,15 +38,16 @@
|
|||
#include "section_entry_dialogue.h"
|
||||
#include "format_ass_dialogue_delta.h"
|
||||
#include "serialize.h"
|
||||
#include "athenatime.h"
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
// Dialogue
|
||||
class DialogueASS : public Dialogue, public SerializeText {
|
||||
class DialogueASS : public CDialogue, public SerializeText {
|
||||
friend class DialogueASSDeltaCoder;
|
||||
|
||||
private:
|
||||
array<Time,2> time;
|
||||
array<CTime,2> time;
|
||||
array<String,4> text; // 0 = text, 1 = style, 2 = actor, 3 = effect
|
||||
array<short,4> margin;
|
||||
int layer;
|
||||
|
@ -62,7 +63,7 @@ namespace Athenasub {
|
|||
|
||||
// Basic features
|
||||
String GetDefaultGroup() const { return L"Events"; }
|
||||
EntryPtr Clone() const { return EntryPtr(new DialogueASS(*this)); }
|
||||
Entry Clone() const { return Entry(new DialogueASS(*this)); }
|
||||
//DeltaCoderPtr GetDeltaCoder() const { return DeltaCoderPtr(new DialogueASSDeltaCoder()); }
|
||||
|
||||
// Capabilities
|
||||
|
@ -72,8 +73,8 @@ namespace Athenasub {
|
|||
bool HasMargins() const { return true; }
|
||||
|
||||
// Read accessors
|
||||
Time GetStartTime() const { return time[0]; }
|
||||
Time GetEndTime() const { return time[1]; }
|
||||
const ITime& GetStartTime() const { return time[0]; }
|
||||
const ITime& GetEndTime() const { return time[1]; }
|
||||
bool IsComment() const { return isComment; }
|
||||
int GetLayer() const { return layer; }
|
||||
int GetMargin(int n) const { return margin.at(n); }
|
||||
|
@ -83,8 +84,8 @@ namespace Athenasub {
|
|||
const String& GetUserField() const { return text[3]; }
|
||||
|
||||
// Write acessors
|
||||
void SetStartTime(Time setStart) { time[0] = setStart; }
|
||||
void SetEndTime(Time setEnd) { time[1] = setEnd; }
|
||||
void SetStartTime(Time setStart) { time[0].SetMS(setStart->GetMS()); }
|
||||
void SetEndTime(Time setEnd) { time[1].SetMS(setEnd->GetMS()); }
|
||||
void SetComment(bool _isComment) { isComment = _isComment; }
|
||||
void SetLayer(int _layer) { layer = _layer; }
|
||||
void SetMargin(int _margin,int value) { margin.at(_margin) = value; }
|
||||
|
|
|
@ -55,8 +55,8 @@ VoidPtr DialogueASSDeltaCoder::EncodeDelta(VoidPtr _from,VoidPtr _to,bool withTe
|
|||
unsigned short mask = 0;
|
||||
if (from->isComment != to->isComment) mask |= 0x0001;
|
||||
if (from->layer != to->layer) mask |= 0x0002;
|
||||
if (from->time[0] != to->time[0]) mask |= 0x0004;
|
||||
if (from->time[1] != to->time[1]) mask |= 0x0008;
|
||||
if (from->time[0].GetMS() != to->time[0].GetMS()) mask |= 0x0004;
|
||||
if (from->time[1].GetMS() != to->time[1].GetMS()) mask |= 0x0008;
|
||||
for (size_t i=0;i<4;i++) {
|
||||
if (from->margin[i] != to->margin[i]) mask |= 0x0010 << i;
|
||||
if (withTextFields && from->text[i] != to->text[i]) mask |= 0x0100 << i;
|
||||
|
|
|
@ -34,13 +34,13 @@
|
|||
//
|
||||
|
||||
#pragma once
|
||||
#include "deltacoder.h"
|
||||
#include "interfaces.h"
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
// Delta coder
|
||||
class DialogueASS;
|
||||
class DialogueASSDeltaCoder : public DeltaCoder {
|
||||
class DialogueASSDeltaCoder : public IDeltaCoder {
|
||||
private:
|
||||
void GetDelta(int mask,char *dst,shared_ptr<DialogueASS> to) const;
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
//
|
||||
|
||||
#include "format_ass_style.h"
|
||||
#include "tokenizer.h"
|
||||
#include "utils.h"
|
||||
#include "../tokenizer.h"
|
||||
#include "../utils.h"
|
||||
using namespace Athenasub;
|
||||
|
||||
|
||||
|
|
|
@ -34,21 +34,21 @@
|
|||
//
|
||||
|
||||
#pragma once
|
||||
#include "section_entry_style.h"
|
||||
#include "serialize.h"
|
||||
#include "../section_entry_style.h"
|
||||
#include "../serialize.h"
|
||||
#include "tr1.h"
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
// Style
|
||||
class StyleASS : public Style, public SerializeText {
|
||||
class StyleASS : public CStyle, public SerializeText {
|
||||
private:
|
||||
String name;
|
||||
String font;
|
||||
float fontSize;
|
||||
int formatVersion;
|
||||
|
||||
array<Colour,5> colour; // 0 = Primary, 1 = Secondary, 2 = Tertiary, 3 = Outline, 4 = Shadow
|
||||
array<CColour,5> colour; // 0 = Primary, 1 = Secondary, 2 = Tertiary, 3 = Outline, 4 = Shadow
|
||||
array<int,4> margin;
|
||||
|
||||
bool bold;
|
||||
|
@ -80,7 +80,7 @@ namespace Athenasub {
|
|||
|
||||
// Basic features
|
||||
String GetDefaultGroup() const;
|
||||
EntryPtr Clone() const { return EntryPtr(new StyleASS(*this)); }
|
||||
Entry Clone() const { return Entry(new StyleASS(*this)); }
|
||||
|
||||
// Indexing
|
||||
virtual bool IsIndexable() const { return true; }
|
||||
|
@ -90,7 +90,7 @@ namespace Athenasub {
|
|||
String GetName() const { return name; }
|
||||
String GetFontName() const { return font; }
|
||||
float GetFontSize() const { return fontSize; }
|
||||
Colour GetColour(int n) const { return colour.at(n); }
|
||||
const IColour& GetColour(int n) const { return colour.at(n); }
|
||||
int GetMargin(int n) const { return margin.at(n); }
|
||||
};
|
||||
|
||||
|
|
|
@ -33,22 +33,24 @@
|
|||
// Contact: mailto:amz@aegisub.net
|
||||
//
|
||||
|
||||
#include "athenasub.h"
|
||||
#include "libathenasub.h"
|
||||
#include "format_handler.h"
|
||||
#include "format_manager.h"
|
||||
using namespace Athenasub;
|
||||
|
||||
|
||||
extern "C" LibAthenaSub* CreateLibAthenasub(const char* hostName) {
|
||||
return new LibAthenaSub(hostName);
|
||||
extern "C" ILibAthenaSub* CreateLibAthenasub(const char* hostName) {
|
||||
return new CLibAthenaSub(hostName);
|
||||
}
|
||||
|
||||
|
||||
LibAthenaSub::LibAthenaSub(const char* hostName) {
|
||||
CLibAthenaSub::CLibAthenaSub(const char* hostName) {
|
||||
(void) hostName;
|
||||
Athenasub::SetHostApplicationName(String(hostName,wxConvUTF8));
|
||||
//Athenasub::SetHostApplicationName(String(hostName,wxConvUTF8));
|
||||
FormatManager::InitializeFormats();
|
||||
}
|
||||
|
||||
|
||||
ModelPtr LibAthenaSub::CreateModel() {
|
||||
return ModelPtr(new Model());
|
||||
Model CLibAthenaSub::CreateModel() {
|
||||
return Model(new CModel());
|
||||
}
|
||||
|
|
|
@ -36,19 +36,15 @@
|
|||
#pragma once
|
||||
|
||||
#include "tr1.h"
|
||||
#include "interfaces.h"
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
class Model;
|
||||
typedef shared_ptr<Model> ModelPtr;
|
||||
|
||||
class LibAthenaSub {
|
||||
class CLibAthenaSub : public ILibAthenaSub {
|
||||
public:
|
||||
LibAthenaSub(const char* hostName);
|
||||
CLibAthenaSub(const char* hostName);
|
||||
|
||||
ModelPtr CreateModel();
|
||||
Model CreateModel();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
extern "C" Athenasub::LibAthenaSub* CreateLibAthenasub(const char* hostName);
|
|
@ -34,12 +34,13 @@
|
|||
//
|
||||
|
||||
#include "Athenasub.h"
|
||||
#include "model.h"
|
||||
using namespace Athenasub;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// Adds a listener to be notified whenever things change
|
||||
void Model::AddListener(ViewPtr listener)
|
||||
void CModel::AddListener(View listener)
|
||||
{
|
||||
wxASSERT(listener);
|
||||
listeners.push_back(listener);
|
||||
|
@ -48,29 +49,29 @@ void Model::AddListener(ViewPtr listener)
|
|||
|
||||
////////////////////////
|
||||
// Notify all listeners
|
||||
void Model::DispatchNotifications(const Notification ¬ification) const
|
||||
void CModel::DispatchNotifications(Notification notification) const
|
||||
{
|
||||
for (ViewList::const_iterator cur=listeners.begin();cur!=listeners.end();cur++) {
|
||||
(*cur)->Notify(notification);
|
||||
//(*cur)->Notify(notification);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Processes an action list
|
||||
void Model::ProcessActionList(const ActionList &_actionList,int type)
|
||||
void CModel::ProcessActionList(ActionList _actionList,int type)
|
||||
{
|
||||
// Copy the list
|
||||
ActionListPtr actions = ActionListPtr(new ActionList(_actionList));
|
||||
ActionList actions = ActionList(new CActionList(_actionList));
|
||||
|
||||
// Setup undo
|
||||
ActionListPtr undo = ActionListPtr(new ActionList(actions->model,actions->actionName,actions->owner,actions->undoAble));
|
||||
ActionList undo = ActionList(new CActionList(actions->model,actions->actionName,actions->owner,actions->undoAble));
|
||||
ActionStack *stack;
|
||||
if (type == 1) stack = &redoStack;
|
||||
else stack = &undoStack;
|
||||
|
||||
// Execute actions
|
||||
std::list<ActionPtr>::const_iterator cur;
|
||||
std::list<Action>::const_iterator cur;
|
||||
for (cur=actions->actions.begin();cur!=actions->actions.end();cur++) {
|
||||
// Inserts the opposite into the undo action first
|
||||
if (actions->undoAble) undo->AddActionStart((*cur)->GetAntiAction(*this));
|
||||
|
@ -92,7 +93,7 @@ void Model::ProcessActionList(const ActionList &_actionList,int type)
|
|||
|
||||
//////////////////
|
||||
// Load subtitles
|
||||
void Model::Load(wxInputStream &input,const FormatPtr _format,const String encoding)
|
||||
void CModel::Load(wxInputStream &input,const FormatPtr _format,const String encoding)
|
||||
{
|
||||
// Autodetect format
|
||||
if (!_format) {
|
||||
|
@ -119,7 +120,7 @@ void Model::Load(wxInputStream &input,const FormatPtr _format,const String encod
|
|||
|
||||
//////////////////
|
||||
// Save subtitles
|
||||
void Model::Save(wxOutputStream &output,const FormatPtr _format,const String encoding)
|
||||
void CModel::Save(wxOutputStream &output,const FormatPtr _format,const String encoding)
|
||||
{
|
||||
// Use another format
|
||||
if (_format && _format != format) {
|
||||
|
@ -138,17 +139,17 @@ void Model::Save(wxOutputStream &output,const FormatPtr _format,const String enc
|
|||
|
||||
/////////////////////////
|
||||
// Inserts a new section
|
||||
void Model::AddSection(String name)
|
||||
void CModel::AddSection(String name)
|
||||
{
|
||||
SectionPtr prev = GetSection(name);
|
||||
if (prev) THROW_ATHENA_EXCEPTION(Exception::Section_Already_Exists);
|
||||
sections.push_back(SectionPtr(new Section(name)));
|
||||
sections.push_back(SectionPtr(new CSection(name)));
|
||||
}
|
||||
|
||||
|
||||
//////////////////
|
||||
// Gets a section
|
||||
SectionPtr Model::GetSection(String name) const
|
||||
SectionPtr CModel::GetSection(String name) const
|
||||
{
|
||||
size_t len = sections.size();
|
||||
for (size_t i=0;i<len;i++) {
|
||||
|
@ -160,7 +161,7 @@ SectionPtr Model::GetSection(String name) const
|
|||
|
||||
////////////////////////
|
||||
// Get section by index
|
||||
SectionPtr Model::GetSectionByIndex(size_t index) const
|
||||
SectionPtr CModel::GetSectionByIndex(size_t index) const
|
||||
{
|
||||
return sections.at(index);
|
||||
}
|
||||
|
@ -168,7 +169,7 @@ SectionPtr Model::GetSectionByIndex(size_t index) const
|
|||
|
||||
/////////////////////
|
||||
// Get section count
|
||||
size_t Model::GetSectionCount() const
|
||||
size_t CModel::GetSectionCount() const
|
||||
{
|
||||
return sections.size();
|
||||
}
|
||||
|
@ -176,7 +177,7 @@ size_t Model::GetSectionCount() const
|
|||
|
||||
//////////
|
||||
// Clear
|
||||
void Model::Clear()
|
||||
void CModel::Clear()
|
||||
{
|
||||
sections.clear();
|
||||
undoStack.clear();
|
||||
|
@ -186,12 +187,12 @@ void Model::Clear()
|
|||
|
||||
//////////////////
|
||||
// Can undo/redo?
|
||||
bool Model::CanUndo(const String owner) const
|
||||
bool CModel::CanUndo(const String owner) const
|
||||
{
|
||||
(void) owner;
|
||||
return undoStack.size() > 0;
|
||||
}
|
||||
bool Model::CanRedo(const String owner) const
|
||||
bool CModel::CanRedo(const String owner) const
|
||||
{
|
||||
(void) owner;
|
||||
return redoStack.size() > 0;
|
||||
|
@ -200,7 +201,7 @@ bool Model::CanRedo(const String owner) const
|
|||
|
||||
///////////////////
|
||||
// Perform an undo
|
||||
void Model::Undo(const String owner)
|
||||
void CModel::Undo(const String owner)
|
||||
{
|
||||
ActivateStack(undoStack,true,owner);
|
||||
}
|
||||
|
@ -208,7 +209,7 @@ void Model::Undo(const String owner)
|
|||
|
||||
//////////////////
|
||||
// Perform a redo
|
||||
void Model::Redo(const String owner)
|
||||
void CModel::Redo(const String owner)
|
||||
{
|
||||
ActivateStack(redoStack,false,owner);
|
||||
}
|
||||
|
@ -216,7 +217,7 @@ void Model::Redo(const String owner)
|
|||
|
||||
/////////////////////
|
||||
// Perform undo/redo
|
||||
void Model::ActivateStack(ActionStack &stack,bool isUndo,const String &owner)
|
||||
void CModel::ActivateStack(ActionStack &stack,bool isUndo,const String &owner)
|
||||
{
|
||||
// TODO: do something with this
|
||||
(void) owner;
|
||||
|
@ -231,13 +232,13 @@ void Model::ActivateStack(ActionStack &stack,bool isUndo,const String &owner)
|
|||
|
||||
//////////////////////////
|
||||
// Get undo/redo messages
|
||||
String Model::GetUndoMessage(const String owner) const
|
||||
String CModel::GetUndoMessage(const String owner) const
|
||||
{
|
||||
(void) owner;
|
||||
if (CanUndo()) return undoStack.back()->GetName();
|
||||
return L"";
|
||||
}
|
||||
String Model::GetRedoMessage(const String owner) const
|
||||
String CModel::GetRedoMessage(const String owner) const
|
||||
{
|
||||
(void) owner;
|
||||
if (CanRedo()) return redoStack.back()->GetName();
|
||||
|
@ -247,7 +248,7 @@ String Model::GetRedoMessage(const String owner) const
|
|||
|
||||
//////////////////////////////////////
|
||||
// Create a controller for this model
|
||||
ControllerPtr Athenasub::Model::CreateController()
|
||||
ControllerPtr Athenasub::CModel::CreateController()
|
||||
{
|
||||
return ControllerPtr(new Controller(*this));
|
||||
return ControllerPtr(new CController(*this));
|
||||
}
|
||||
|
|
|
@ -37,40 +37,30 @@
|
|||
#include <list>
|
||||
#include <vector>
|
||||
#include <wx/wfstream.h>
|
||||
#include "athenasub.h"
|
||||
#include "actionlist.h"
|
||||
#include "section.h"
|
||||
#include "api.h"
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
// Prototypes
|
||||
class View;
|
||||
typedef shared_ptr<View> ViewPtr;
|
||||
class Notification;
|
||||
class Format;
|
||||
|
||||
// Model class
|
||||
// Stores the subtitle data
|
||||
class Model {
|
||||
friend class FormatHandler;
|
||||
friend class ActionList;
|
||||
friend class Controller;
|
||||
friend class Action;
|
||||
|
||||
typedef std::list<ViewPtr> ViewList;
|
||||
typedef std::list<ActionListPtr> ActionStack;
|
||||
typedef shared_ptr<Format> FormatPtr;
|
||||
typedef shared_ptr<Controller> ControllerPtr;
|
||||
class CModel : public IModel {
|
||||
friend class CFormatHandler;
|
||||
friend class CActionList;
|
||||
friend class CController;
|
||||
friend class CAction;
|
||||
|
||||
private:
|
||||
std::vector<SectionPtr> sections;
|
||||
std::vector<CSection> sections;
|
||||
ActionStack undoStack;
|
||||
ActionStack redoStack;
|
||||
ViewList listeners;
|
||||
bool readOnly;
|
||||
FormatPtr format;
|
||||
Format format;
|
||||
|
||||
void ProcessActionList(const ActionList &actionList,int type=0);
|
||||
void ProcessActionList(ActionList actionList,int type=0);
|
||||
|
||||
String GetUndoMessage(const String owner=L"") const;
|
||||
String GetRedoMessage(const String owner=L"") const;
|
||||
|
@ -78,26 +68,26 @@ namespace Athenasub {
|
|||
bool CanRedo(const String owner=L"") const;
|
||||
void Undo(const String owner=L"");
|
||||
void Redo(const String owner=L"");
|
||||
void ActivateStack(ActionStack &stack,bool isUndo,const String &owner);
|
||||
void ActivateStack(ActionStack stack,bool isUndo,const String &owner);
|
||||
|
||||
void DispatchNotifications(const Notification ¬ification) const;
|
||||
|
||||
void AddSection(String name);
|
||||
SectionPtr GetSection(String name) const;
|
||||
SectionPtr GetSectionByIndex(size_t index) const;
|
||||
size_t GetSectionCount() const;
|
||||
void DispatchNotifications(Notification notification) const;
|
||||
|
||||
void Clear();
|
||||
void Load(wxInputStream &input,const FormatPtr format=FormatPtr(),const String encoding=L"");
|
||||
void Save(wxOutputStream &output,const FormatPtr format=FormatPtr(),const String encoding=L"UTF-8");
|
||||
void Load(wxInputStream &input,Format format=Format(),const String encoding=L"");
|
||||
void Save(wxOutputStream &output,Format format=Format(),const String encoding=L"UTF-8");
|
||||
|
||||
protected:
|
||||
void AddSection(String name);
|
||||
Section GetSection(String name) const;
|
||||
Section GetSectionByIndex(size_t index) const;
|
||||
size_t GetSectionCount() const;
|
||||
|
||||
public:
|
||||
ControllerPtr CreateController();
|
||||
|
||||
const FormatPtr GetFormat() const { return format; }
|
||||
void AddListener(ViewPtr listener);
|
||||
Controller CreateController();
|
||||
Format GetFormat() const { return format; }
|
||||
void AddListener(View listener);
|
||||
};
|
||||
|
||||
typedef shared_ptr<Model> ModelPtr;
|
||||
typedef shared_ptr<CModel> ModelPtr;
|
||||
|
||||
}
|
|
@ -40,7 +40,7 @@ using namespace Athenasub;
|
|||
|
||||
///////////////
|
||||
// Constructor
|
||||
Section::Section(String _name)
|
||||
CSection::CSection(String _name)
|
||||
{
|
||||
name = _name;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ Section::Section(String _name)
|
|||
|
||||
///////////////////
|
||||
// Append an entry
|
||||
void Section::AddEntry(EntryPtr entry,int pos)
|
||||
void CSection::AddEntry(Entry entry,int pos)
|
||||
{
|
||||
// Insert to entry list
|
||||
if (pos == -1) entries.push_back(entry);
|
||||
|
@ -63,10 +63,10 @@ void Section::AddEntry(EntryPtr entry,int pos)
|
|||
|
||||
/////////////////////////
|
||||
// Removes the nth entry
|
||||
void Section::RemoveEntryByIndex(size_t i)
|
||||
void CSection::RemoveEntryByIndex(size_t i)
|
||||
{
|
||||
// Get entry iterator and erase
|
||||
std::vector<EntryPtr>::iterator entry = entries.begin()+i;
|
||||
std::vector<Entry>::iterator entry = entries.begin()+i;
|
||||
entries.erase(entry);
|
||||
|
||||
// If it's indexable, remove it from index as well
|
||||
|
@ -76,7 +76,7 @@ void Section::RemoveEntryByIndex(size_t i)
|
|||
|
||||
/////////////////////////////////
|
||||
// Removes an entry by its value
|
||||
void Section::RemoveEntry(EntryPtr entry)
|
||||
void CSection::RemoveEntry(Entry entry)
|
||||
{
|
||||
size_t len = entries.size();
|
||||
for (size_t i=0;i<len;i++) {
|
||||
|
@ -91,15 +91,7 @@ void Section::RemoveEntry(EntryPtr entry)
|
|||
|
||||
////////////////////////////
|
||||
// Retrieves entry by index
|
||||
EntryPtr Section::GetEntry(size_t i) const
|
||||
{
|
||||
return entries[i];
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// Retrieves a reference to an entry
|
||||
EntryPtr& Section::GetEntryRef(size_t i)
|
||||
Entry CSection::GetEntry(size_t i) const
|
||||
{
|
||||
return entries[i];
|
||||
}
|
||||
|
@ -107,7 +99,7 @@ EntryPtr& Section::GetEntryRef(size_t i)
|
|||
|
||||
/////////////////////////
|
||||
// Get number of entries
|
||||
size_t Section::GetEntryCount() const
|
||||
size_t CSection::GetEntryCount() const
|
||||
{
|
||||
return entries.size();
|
||||
}
|
||||
|
@ -115,7 +107,7 @@ size_t Section::GetEntryCount() const
|
|||
|
||||
//////////////////
|
||||
// Set a property
|
||||
void Section::SetProperty(const String &key,const String &value)
|
||||
void CSection::SetProperty(const String &key,const String &value)
|
||||
{
|
||||
properties[key] = value;
|
||||
}
|
||||
|
@ -123,7 +115,7 @@ void Section::SetProperty(const String &key,const String &value)
|
|||
|
||||
//////////////////////
|
||||
// Removes a property
|
||||
void Section::UnsetProperty(const String &key)
|
||||
void CSection::UnsetProperty(const String &key)
|
||||
{
|
||||
std::map<String,String>::iterator iter = properties.find(key);
|
||||
if (iter != properties.end()) properties.erase(iter);
|
||||
|
@ -132,7 +124,7 @@ void Section::UnsetProperty(const String &key)
|
|||
|
||||
//////////////////////////
|
||||
// Get a property's value
|
||||
String Section::GetProperty(const String &key) const
|
||||
String CSection::GetProperty(const String &key) const
|
||||
{
|
||||
std::map<String,String>::const_iterator iter = properties.find(key);
|
||||
if (iter != properties.end()) return iter->second;
|
||||
|
@ -142,7 +134,7 @@ String Section::GetProperty(const String &key) const
|
|||
|
||||
///////////////////////////////
|
||||
// Checks if it has a property
|
||||
bool Section::HasProperty(const String &key) const
|
||||
bool CSection::HasProperty(const String &key) const
|
||||
{
|
||||
return properties.find(key) != properties.end();
|
||||
}
|
||||
|
@ -150,7 +142,7 @@ bool Section::HasProperty(const String &key) const
|
|||
|
||||
//////////////////////
|
||||
// Get property count
|
||||
size_t Section::GetPropertyCount() const
|
||||
size_t CSection::GetPropertyCount() const
|
||||
{
|
||||
return properties.size();
|
||||
}
|
||||
|
@ -158,7 +150,7 @@ size_t Section::GetPropertyCount() const
|
|||
|
||||
///////////////////////////////////
|
||||
// Get name of a property by index
|
||||
String Section::GetPropertyName(size_t n) const
|
||||
String CSection::GetPropertyName(size_t n) const
|
||||
{
|
||||
std::map<String,String>::const_iterator iter=properties.begin();
|
||||
for (size_t i=0 ; iter!=properties.end() ; iter++,i++) {
|
||||
|
@ -170,9 +162,9 @@ String Section::GetPropertyName(size_t n) const
|
|||
|
||||
///////////////////////
|
||||
// Retrieve from index
|
||||
EntryPtr Section::GetFromIndex(String key) const
|
||||
Entry CSection::GetFromIndex(String key) const
|
||||
{
|
||||
std::map<String,EntryPtr>::const_iterator result = index.find(key);
|
||||
std::map<String,Entry>::const_iterator result = index.find(key);
|
||||
if (result != index.end()) return result->second;
|
||||
return EntryPtr();
|
||||
return Entry();
|
||||
}
|
||||
|
|
|
@ -34,26 +34,24 @@
|
|||
//
|
||||
|
||||
#pragma once
|
||||
#include "athenastring.h"
|
||||
#include "athenasub.h"
|
||||
#include "section_entry.h"
|
||||
#include "tr1.h"
|
||||
#include "api.h"
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
// Section class
|
||||
class Section {
|
||||
class CSection : public ISection {
|
||||
private:
|
||||
std::vector<EntryPtr> entries;
|
||||
std::vector<Entry> entries;
|
||||
std::map<String,String> properties;
|
||||
std::map<String,EntryPtr> index;
|
||||
std::map<String,Entry> index;
|
||||
String name;
|
||||
|
||||
public:
|
||||
Section(String name);
|
||||
~Section() {}
|
||||
CSection(String name);
|
||||
~CSection() {}
|
||||
|
||||
// Section name
|
||||
void SetName(const String& newName) { name = newName; }
|
||||
|
@ -68,16 +66,16 @@ namespace Athenasub {
|
|||
String GetPropertyName(size_t index) const;
|
||||
|
||||
// Indexed
|
||||
EntryPtr GetFromIndex(String key) const;
|
||||
Entry GetFromIndex(String key) const;
|
||||
|
||||
// Entries
|
||||
void AddEntry(EntryPtr entry,int pos=-1);
|
||||
void AddEntry(Entry entry,int pos=-1);
|
||||
void RemoveEntryByIndex(size_t index);
|
||||
void RemoveEntry(EntryPtr entry);
|
||||
EntryPtr GetEntry(size_t index) const;
|
||||
EntryPtr& GetEntryRef(size_t index);
|
||||
void RemoveEntry(Entry entry);
|
||||
Entry GetEntry(size_t index) const;
|
||||
Entry& GetEntryRef(size_t index) const;
|
||||
size_t GetEntryCount() const;
|
||||
};
|
||||
typedef shared_ptr<Section> SectionPtr;
|
||||
typedef shared_ptr<CSection> SectionPtr;
|
||||
|
||||
}
|
|
@ -42,34 +42,8 @@ using namespace Athenasub;
|
|||
|
||||
/////////////////////////////////
|
||||
// Returns a static empty string
|
||||
const String& Entry::EmptyString() const
|
||||
const String& CDialogue::EmptyString()
|
||||
{
|
||||
static const String str = _T("");
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
const PlainTextPtr Entry::GetAsPlain(const EntryPtr &ptr)
|
||||
{
|
||||
(void) ptr; return PlainTextPtr();
|
||||
}
|
||||
const DialoguePtr Entry::GetAsDialogue(const EntryPtr &ptr)
|
||||
{
|
||||
return dynamic_pointer_cast<Dialogue>(ptr);
|
||||
}
|
||||
const DialogueConstPtr Entry::GetAsDialogue(const EntryConstPtr &ptr)
|
||||
{
|
||||
return dynamic_pointer_cast<const Dialogue>(ptr);
|
||||
}
|
||||
const StylePtr Entry::GetAsStyle(const EntryPtr &ptr)
|
||||
{
|
||||
return dynamic_pointer_cast<Style>(ptr);
|
||||
}
|
||||
const AttachmentPtr Entry::GetAsFile(const EntryPtr &ptr)
|
||||
{
|
||||
(void) ptr; return AttachmentPtr();
|
||||
}
|
||||
const RawEntryPtr Entry::GetAsRaw(const EntryPtr &ptr)
|
||||
{
|
||||
(void) ptr; return RawEntryPtr();
|
||||
}
|
||||
|
|
|
@ -34,22 +34,18 @@
|
|||
//
|
||||
|
||||
#pragma once
|
||||
#include "athenastring.h"
|
||||
#include "api.h"
|
||||
#include <list>
|
||||
#include "athenasub.h"
|
||||
|
||||
|
||||
namespace Athenasub {
|
||||
// Prototypes
|
||||
class Model;
|
||||
class Notification;
|
||||
|
||||
// View interface
|
||||
// Implement this to listen to modifications in a model
|
||||
class View {
|
||||
public:
|
||||
virtual ~View();
|
||||
|
||||
void Register(Model &model);
|
||||
virtual void Notify(const Notification ¬ification) = 0;
|
||||
// Section plain-text entry
|
||||
class CPlainText : public IEntry {
|
||||
public:
|
||||
SectionEntryType GetType() const { return SECTION_ENTRY_PLAIN; }
|
||||
virtual ~CPlainText() {}
|
||||
virtual String GetText() const =0;
|
||||
virtual void SetText(const String &_data) =0;
|
||||
};
|
||||
|
||||
}
|
|
@ -35,26 +35,26 @@
|
|||
|
||||
|
||||
#pragma once
|
||||
#include "exception.h"
|
||||
#include "athenatime.h"
|
||||
#include "athenasub.h"
|
||||
#include "section_entry.h"
|
||||
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
// Dialogue class
|
||||
class Dialogue : public Entry {
|
||||
class CDialogue : public IDialogue {
|
||||
private:
|
||||
static const bool dodgeWarning = true;
|
||||
void ThrowUnsupported() const { if (dodgeWarning) THROW_ATHENA_EXCEPTION(Exception::Unsupported_Format_Feature); }
|
||||
static const String& EmptyString();
|
||||
|
||||
public:
|
||||
// Destructor
|
||||
virtual ~Dialogue() {}
|
||||
virtual ~CDialogue() {}
|
||||
|
||||
// Type
|
||||
SectionEntryType GetType() const { return SECTION_ENTRY_DIALOGUE; }
|
||||
Dialogue *GetAsDialogue() { return this; }
|
||||
Dialogue GetAsDialogue() { return Dialogue(this); }
|
||||
|
||||
// Capabilities
|
||||
virtual bool HasText() const { return false; }
|
||||
|
@ -67,8 +67,8 @@ namespace Athenasub {
|
|||
|
||||
// Read accessors
|
||||
virtual const String& GetText() const { ThrowUnsupported(); return EmptyString(); }
|
||||
virtual Time GetStartTime() const { ThrowUnsupported(); return 0; }
|
||||
virtual Time GetEndTime() const { ThrowUnsupported(); return 0; }
|
||||
// virtual ITime& GetStartTime() const { ThrowUnsupported(); return Time(); }
|
||||
// virtual ITime& GetEndTime() const { ThrowUnsupported(); return Time(); }
|
||||
virtual int GetStartFrame() const { ThrowUnsupported(); return 0; }
|
||||
virtual int GetEndFrame() const { ThrowUnsupported(); return 0; }
|
||||
virtual bool IsComment() const { ThrowUnsupported(); return false; }
|
||||
|
@ -78,7 +78,7 @@ namespace Athenasub {
|
|||
virtual const String& GetActor() const { ThrowUnsupported(); return EmptyString(); }
|
||||
virtual const String& GetUserField() const { ThrowUnsupported(); return EmptyString(); }
|
||||
|
||||
// Write acessors
|
||||
// Write accessors
|
||||
virtual void SetText(const String& text) { (void) text; ThrowUnsupported(); }
|
||||
virtual void SetStartTime(Time start) { (void) start; ThrowUnsupported(); }
|
||||
virtual void SetEndTime(Time end) { (void) end; ThrowUnsupported(); }
|
|
@ -35,32 +35,31 @@
|
|||
|
||||
|
||||
#pragma once
|
||||
#include "exception.h"
|
||||
#include "athenasub.h"
|
||||
#include "colour.h"
|
||||
#include "section_entry.h"
|
||||
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
// Style class
|
||||
class Style : public Entry {
|
||||
class CStyle : public IStyle {
|
||||
private:
|
||||
static const bool dodgeWarning = true;
|
||||
void ThrowUnsupported() const { if (dodgeWarning) THROW_ATHENA_EXCEPTION(Exception::Unsupported_Format_Feature); }
|
||||
|
||||
public:
|
||||
// Destructor
|
||||
virtual ~Style() {}
|
||||
virtual ~CStyle() {}
|
||||
|
||||
// Type
|
||||
SectionEntryType GetType() const { return SECTION_ENTRY_STYLE; }
|
||||
Style *GetAsStyle() { return this; }
|
||||
Style GetAsStyle() { return Style(this); }
|
||||
|
||||
// Read accessors
|
||||
virtual String GetName() const=0;
|
||||
virtual String GetFontName() const { ThrowUnsupported(); return L""; }
|
||||
virtual float GetFontSize() const { ThrowUnsupported(); return 0.0f; }
|
||||
virtual Colour GetColour(int n) const { (void) n; ThrowUnsupported(); return Colour(); }
|
||||
//virtual IColour& GetColour(int n) const { (void) n; ThrowUnsupported(); return Colour(); }
|
||||
virtual int GetMargin(int n) const { (void) n; ThrowUnsupported(); return 0; }
|
||||
};
|
||||
|
|
@ -33,13 +33,13 @@
|
|||
// Contact: mailto:amz@aegisub.net
|
||||
//
|
||||
|
||||
#include "athenasub.h"
|
||||
#include "selection.h"
|
||||
using namespace Athenasub;
|
||||
|
||||
|
||||
///////////////
|
||||
// Constructor
|
||||
Selection::Selection()
|
||||
CSelection::CSelection()
|
||||
: count(0)
|
||||
{
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ Selection::Selection()
|
|||
|
||||
////////////////
|
||||
// Adds a range
|
||||
void Selection::AddRange(const Range &range)
|
||||
void CSelection::AddRange(const Range &range)
|
||||
{
|
||||
ranges.push_back(range);
|
||||
UpdateCount();
|
||||
|
@ -56,7 +56,7 @@ void Selection::AddRange(const Range &range)
|
|||
|
||||
///////////////////
|
||||
// Removes a range
|
||||
void Selection::RemoveRange(const Range &range)
|
||||
void CSelection::RemoveRange(const Range &range)
|
||||
{
|
||||
// TODO
|
||||
(void) range;
|
||||
|
@ -66,7 +66,7 @@ void Selection::RemoveRange(const Range &range)
|
|||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Normalizes all ranges, that is, gets rid of overlaps and whatnot
|
||||
void Selection::NormalizeRanges()
|
||||
void CSelection::NormalizeRanges()
|
||||
{
|
||||
// Has anything to do?
|
||||
if (ranges.size() == 0) return;
|
||||
|
@ -112,7 +112,7 @@ void Selection::NormalizeRanges()
|
|||
|
||||
//////////////////
|
||||
// Get a specific
|
||||
size_t Selection::GetLine(size_t n) const
|
||||
size_t CSelection::GetLine(size_t n) const
|
||||
{
|
||||
// Find the nth line
|
||||
size_t cur = 0;
|
||||
|
@ -127,8 +127,8 @@ size_t Selection::GetLine(size_t n) const
|
|||
|
||||
|
||||
////////////////////////////
|
||||
// Append another selection
|
||||
void Selection::AddSelection (const Selection ¶m)
|
||||
// Append another CSelection
|
||||
void CSelection::AddSelection (const Selection ¶m)
|
||||
{
|
||||
(void) param;
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ void Selection::AddSelection (const Selection ¶m)
|
|||
|
||||
////////////////
|
||||
// Update count
|
||||
void Selection::UpdateCount()
|
||||
void CSelection::UpdateCount()
|
||||
{
|
||||
count = 0;
|
||||
size_t len = ranges.size();
|
||||
|
@ -147,8 +147,8 @@ void Selection::UpdateCount()
|
|||
|
||||
|
||||
//////////////////////////////
|
||||
// Subtract another selection
|
||||
void Selection::RemoveSelection (const Selection ¶m)
|
||||
// Subtract another CSelection
|
||||
void CSelection::RemoveSelection (const Selection ¶m)
|
||||
{
|
||||
(void) param;
|
||||
}
|
||||
|
|
|
@ -35,34 +35,35 @@
|
|||
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include "range.h"
|
||||
#include "athenasub.h"
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
// Selection class
|
||||
class Selection {
|
||||
class CSelection : public ISelection {
|
||||
private:
|
||||
std::vector<Range> ranges;
|
||||
size_t count;
|
||||
void UpdateCount();
|
||||
CSelection();
|
||||
|
||||
public:
|
||||
Selection();
|
||||
virtual ~CSelection() {}
|
||||
|
||||
void AddLine(size_t line) { AddRange(Range(line,line+1)); }
|
||||
void AddRange(const Range &range);
|
||||
void RemoveLine(size_t line) { RemoveRange(Range(line,line+1)); }
|
||||
void RemoveRange(const Range &range);
|
||||
void AddSelection (const Selection ¶m);
|
||||
void RemoveSelection (const Selection ¶m);
|
||||
void NormalizeRanges ();
|
||||
virtual void AddLine(size_t line) { AddRange(Range(line,line+1)); }
|
||||
virtual void AddRange(const Range &range);
|
||||
virtual void RemoveLine(size_t line) { RemoveRange(Range(line,line+1)); }
|
||||
virtual void RemoveRange(const Range &range);
|
||||
virtual void AddSelection (const Selection ¶m);
|
||||
virtual void RemoveSelection (const Selection ¶m);
|
||||
virtual void NormalizeRanges ();
|
||||
|
||||
size_t GetCount() const { return count; }
|
||||
size_t GetRanges() const { return ranges.size(); }
|
||||
size_t GetLine(size_t n) const;
|
||||
size_t GetLineInRange(size_t n,size_t range) const { return ranges.at(range).GetLine(n); }
|
||||
size_t GetLinesInRange(size_t range) const { return ranges.at(range).GetSize(); }
|
||||
bool IsContiguous() const { return GetRanges() <= 1; }
|
||||
virtual size_t GetCount() const { return count; }
|
||||
virtual size_t GetRanges() const { return ranges.size(); }
|
||||
virtual size_t GetLine(size_t n) const;
|
||||
virtual size_t GetLineInRange(size_t n,size_t range) const { return ranges.at(range).GetLine(n); }
|
||||
virtual size_t GetLinesInRange(size_t range) const { return ranges.at(range).GetSize(); }
|
||||
virtual bool IsContiguous() const { return GetRanges() <= 1; }
|
||||
|
||||
};
|
||||
|
|
@ -34,12 +34,13 @@
|
|||
//
|
||||
|
||||
#include "Athenasub.h"
|
||||
#include "athenatime.h"
|
||||
using namespace Athenasub;
|
||||
|
||||
|
||||
//////////////////////
|
||||
// Generates a string
|
||||
String Time::GetString(int ms_precision,int h_precision) const
|
||||
String CTime::GetString(int ms_precision,int h_precision) const
|
||||
{
|
||||
// Enforce sanity
|
||||
ms_precision = Mid(0,ms_precision,3);
|
||||
|
@ -109,7 +110,7 @@ String Time::GetString(int ms_precision,int h_precision) const
|
|||
|
||||
///////////////////
|
||||
// Parses a string
|
||||
void Time::Parse(const String &data)
|
||||
void CTime::ParseString(const String &data)
|
||||
{
|
||||
// Break into an array of values
|
||||
array<size_t,4> values;
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
//
|
||||
|
||||
#define ATHENA_DLL
|
||||
#include <aegilib/athenasub.h>
|
||||
#include <wx/wfstream.h>
|
||||
#include <athenasub/athenawin.h>
|
||||
#include <iostream>
|
||||
#include <wx/stopwatch.h>
|
||||
#include "text_file_reader.h"
|
||||
|
@ -50,13 +50,16 @@ int main()
|
|||
|
||||
try {
|
||||
// Set up the lib
|
||||
//FormatManager::InitializeFormats();
|
||||
//Athenasub::SetHostApplicationName(L"Aegilib test program");
|
||||
LibAthenaSub* lib = CreateLibAthenasub("Aegisub test program");
|
||||
HMODULE module = LoadLibrary(_T("athenasub.dll"));
|
||||
if (!module) {
|
||||
cout << "Failed to load library, aborting.\n";
|
||||
return 1;
|
||||
}
|
||||
LibAthenaSub lib = Athenasub::Create(module,"Aegilib test program");
|
||||
|
||||
// Subtitles model
|
||||
ModelPtr subs = lib->CreateModel();
|
||||
ControllerPtr control = subs->CreateController();
|
||||
Model subs = lib->CreateModel();
|
||||
Controller control = subs->CreateController();
|
||||
wxStopWatch timer;
|
||||
|
||||
// Load subtitles
|
||||
|
@ -82,15 +85,15 @@ int main()
|
|||
cout << "Executing action " << n << " times... ";
|
||||
timer.Start();
|
||||
for (size_t i=0;i<n;i++) {
|
||||
ActionListPtr actions = control->CreateActionList(L"Test");
|
||||
Selection selection;
|
||||
selection.AddRange(Range(0,5000));
|
||||
selection.AddRange(Range(4500,5500));
|
||||
selection.AddRange(Range(9000,9100));
|
||||
std::vector<EntryPtr> entries = actions->ModifyLines(selection,L"Events");
|
||||
ActionList actions = control->CreateActionList(L"Test");
|
||||
Selection selection = control->CreateSelection();
|
||||
selection->AddRange(Range(0,5000));
|
||||
selection->AddRange(Range(4500,5500));
|
||||
selection->AddRange(Range(9000,9100));
|
||||
std::vector<Entry> entries = actions->ModifyLines(selection,L"Events");
|
||||
size_t len = entries.size();
|
||||
for (size_t i=0;i<len;i++) {
|
||||
DialoguePtr diag = dynamic_pointer_cast<Dialogue> (entries[i]);
|
||||
Dialogue diag = dynamic_pointer_cast<IDialogue> (entries[i]);
|
||||
diag->SetStartTime(diag->GetStartTime() - 55555);
|
||||
diag->SetEndTime(diag->GetEndTime() + 5555);
|
||||
}
|
||||
|
@ -117,7 +120,7 @@ int main()
|
|||
cout << "Done in " << timer.Time() << " ms.\n";
|
||||
|
||||
// Get style test
|
||||
StyleConstPtr style = control->GetStyle(L"japro1_star");
|
||||
ConstStyle 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
|
||||
|
@ -130,15 +133,5 @@ int main()
|
|||
cout << "\n\nException: " << e.what() << endl << endl;
|
||||
}
|
||||
|
||||
if (false) {
|
||||
wchar_t myArray[] = { 0xD834, 0xDD1E, 0 };
|
||||
String str = wxString(myArray);
|
||||
cout << "Length: " << str.Length() << ". Contents: " << str[0] << "," << str[1] << endl;
|
||||
wxCharBuffer buf = str.mb_str(wxConvUTF8);
|
||||
unsigned char *chr = (unsigned char *) buf.data();
|
||||
cout << "UTF-8 Length: " << strlen(buf) << ". Contents: " << (size_t)chr[0] << "," << (size_t)chr[1] << "," << (size_t)chr[2] << "," << (size_t)chr[3] << endl;
|
||||
str = wxString(buf,wxConvUTF8);
|
||||
cout << "Length: " << str.Length() << ". Contents: " << str[0] << "," << str[1] << endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -139,12 +139,12 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="2"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
LinkTimeCodeGeneration="0"
|
||||
LinkTimeCodeGeneration="1"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
|
|
Loading…
Reference in a new issue