Aegisub/aegisub/src/ass_file.h

177 lines
5.9 KiB
C
Raw Normal View History

2006-01-16 22:02:54 +01:00
// Copyright (c) 2005, 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 Project http://www.aegisub.org/
2006-01-16 22:02:54 +01:00
//
// $Id$
/// @file ass_file.h
/// @see ass_file.cpp
/// @ingroup subs_storage
///
2006-01-16 22:02:54 +01:00
#pragma once
///////////
// Headers
#ifndef AGI_PRE
2006-01-16 22:02:54 +01:00
#include <fstream>
#include <list>
#include <vector>
#include <wx/arrstr.h>
#endif
2006-01-16 22:02:54 +01:00
//////////////
// Prototypes
class FrameRate;
class AssDialogue;
class AssStyle;
class AssAttachment;
2006-01-16 22:02:54 +01:00
class AssDialogueBlock;
class AssDialogueBlockOverride;
class AssDialogueBlockPlain;
class AssEntry;
/// DOCME
/// @class AssFile
/// @brief DOCME
///
/// DOCME
2006-01-16 22:02:54 +01:00
class AssFile {
private:
/// DOCME
2006-01-16 22:02:54 +01:00
bool Modified;
/// DOCME
static std::list<AssFile*> UndoStack;
/// DOCME
static std::list<AssFile*> RedoStack;
/// DOCME
2006-01-16 22:02:54 +01:00
static bool StackModified;
static void StackClear();
public:
/// DOCME
2006-01-16 22:02:54 +01:00
std::list<AssEntry*> Line;
/// DOCME
2006-01-16 22:02:54 +01:00
wxString filename;
/// DOCME
2007-01-26 01:47:42 +01:00
wxString undodescription;
/// DOCME
2006-01-16 22:02:54 +01:00
bool loaded;
AssFile();
AssFile(AssFile &from);
~AssFile();
bool IsModified(); // Returns if file has unmodified changes
2007-01-26 01:47:42 +01:00
void FlagAsModified(wxString desc); // Flag file as being modified, will automatically put a copy on stack
2006-01-16 22:02:54 +01:00
void Clear(); // Wipes file
void CompressForStack(bool compress); // Compress/decompress for storage on stack
void LoadDefault(bool defline=true); // Loads default file. Pass false to prevent it from adding a default line too
2006-01-16 22:02:54 +01:00
void InsertStyle(AssStyle *style); // Inserts a style to file
void InsertAttachment(AssAttachment *attach); // Inserts an attachment
void InsertAttachment(wxString filename); // Inserts a file as an attachment
2006-01-16 22:02:54 +01:00
wxArrayString GetStyles(); // Gets a list of all styles available
AssStyle *GetStyle(wxString name); // Gets style by its name
//wxString GetString(); // Returns the whole file as a single string
void Load(wxString file,wxString charset=_T(""),bool addToRecent=true); // Load from a file
2006-01-16 22:02:54 +01:00
void Save(wxString file,bool setfilename=false,bool addToRecent=true,const wxString encoding=_T("")); // Save to a file. Pass true to second argument if this isn't a copy
void SaveMemory(std::vector<char> &dst,const wxString encoding=_T("")); // Save to a memory string
2006-01-16 22:02:54 +01:00
void Export(wxString file); // Saves exported copy, with effects applied
void AddToRecent(wxString file); // Adds file name to list of recently opened files
bool CanSave(); // Returns true if the file can be saved in its current format
static wxString GetWildcardList(int mode); // Returns the list of wildcards supported (0 = open, 1 = save, 2 = export)
2006-01-16 22:02:54 +01:00
void GetResolution(int &w,int &h); // Get resolution
int GetScriptInfoAsInt(const wxString key); // Returns the value in a [Script Info] key as int.
wxString GetScriptInfo(const wxString key); // Returns the value in a [Script Info] key as string.
2006-01-16 22:02:54 +01:00
void SetScriptInfo(const wxString key,const wxString value); // Sets the value of a [Script Info] key. Adds it if it doesn't exist.
void AddComment(const wxString comment); // Adds a ";" comment under [Script Info].
int AddLine(wxString data,wxString group,int lasttime,int &version,wxString *outGroup=NULL);
2006-01-16 22:02:54 +01:00
2007-01-26 01:47:42 +01:00
static void StackPop(); // Pop subs from stack and sets 'top' to it
static void StackRedo(); // Redoes action on stack
static void StackPush(wxString desc); // Puts a copy of 'top' on the stack
static void StackReset(); // Resets stack. Do this before loading new subtitles.
static bool IsUndoStackEmpty(); // Checks if undo stack is empty
static bool IsRedoStackEmpty(); // Checks if undo stack is empty
static wxString GetUndoDescription(); // Gets field undodescription from back of UndoStack
static wxString GetRedoDescription(); // Gets field undodescription from back of RedoStack
/// DOCME
2007-01-26 01:47:42 +01:00
static bool Popping; // Flags the stack as popping. You must unset this after popping
/// DOCME
2007-01-26 01:47:42 +01:00
static AssFile *top; // Current script file. It is "above" the stack.
2006-01-16 22:02:54 +01:00
};
/// DOCME
2006-01-16 22:02:54 +01:00
typedef std::list<AssEntry*>::iterator entryIter;
//////////////////////////////////////////////////////
// Hack to get STL sort to work on a list of pointers
template <typename T>
/// DOCME
/// @class LessByPointedToValue
/// @brief DOCME
///
/// DOCME
2006-01-16 22:02:54 +01:00
class LessByPointedToValue : std::binary_function<T const *, T const *, bool> {
public:
/// @brief DOCME
/// @param x
/// @param y
///
2006-01-16 22:02:54 +01:00
bool operator()(T const * x, T const * y) const {
return std::less<T>()(*x, *y);
}
};