Change some enums into enum classes
This commit is contained in:
parent
e99f4c4da1
commit
de7b09f7f7
17 changed files with 45 additions and 45 deletions
|
@ -46,7 +46,7 @@ AssAttachment::AssAttachment(agi::fs::path const& name, AssEntryGroup group)
|
||||||
file->seekg(0, std::ios::beg);
|
file->seekg(0, std::ios::beg);
|
||||||
file->read(&data[0], data.size());
|
file->read(&data[0], data.size());
|
||||||
|
|
||||||
entry_data = (group == ENTRY_FONT ? "fontname: " : "filename: ") + filename.get() + "\r\n";
|
entry_data = (group == AssEntryGroup::FONT ? "fontname: " : "filename: ") + filename.get() + "\r\n";
|
||||||
entry_data = entry_data.get() + agi::ass::UUEncode(data);
|
entry_data = entry_data.get() + agi::ass::UUEncode(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,12 +42,12 @@
|
||||||
#include <boost/ptr_container/ptr_vector.hpp>
|
#include <boost/ptr_container/ptr_vector.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
enum AssBlockType {
|
enum class AssBlockType {
|
||||||
BLOCK_BASE,
|
BASE,
|
||||||
BLOCK_PLAIN,
|
PLAIN,
|
||||||
BLOCK_COMMENT,
|
COMMENT,
|
||||||
BLOCK_OVERRIDE,
|
OVERRIDE,
|
||||||
BLOCK_DRAWING
|
DRAWING
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @class AssDialogueBlock
|
/// @class AssDialogueBlock
|
||||||
|
@ -85,13 +85,13 @@ public:
|
||||||
class AssDialogueBlockPlain : public AssDialogueBlock {
|
class AssDialogueBlockPlain : public AssDialogueBlock {
|
||||||
public:
|
public:
|
||||||
using AssDialogueBlock::text;
|
using AssDialogueBlock::text;
|
||||||
AssBlockType GetType() const override { return BLOCK_PLAIN; }
|
AssBlockType GetType() const override { return AssBlockType::PLAIN; }
|
||||||
AssDialogueBlockPlain(std::string const& text = std::string()) : AssDialogueBlock(text) { }
|
AssDialogueBlockPlain(std::string const& text = std::string()) : AssDialogueBlock(text) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
class AssDialogueBlockComment : public AssDialogueBlock {
|
class AssDialogueBlockComment : public AssDialogueBlock {
|
||||||
public:
|
public:
|
||||||
AssBlockType GetType() const override { return BLOCK_COMMENT; }
|
AssBlockType GetType() const override { return AssBlockType::COMMENT; }
|
||||||
AssDialogueBlockComment(std::string const& text = std::string()) : AssDialogueBlock("{" + text + "}") { }
|
AssDialogueBlockComment(std::string const& text = std::string()) : AssDialogueBlock("{" + text + "}") { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ class AssDialogueBlockDrawing : public AssDialogueBlock {
|
||||||
public:
|
public:
|
||||||
int Scale;
|
int Scale;
|
||||||
|
|
||||||
AssBlockType GetType() const override { return BLOCK_DRAWING; }
|
AssBlockType GetType() const override { return AssBlockType::DRAWING; }
|
||||||
AssDialogueBlockDrawing(std::string const& text, int scale) : AssDialogueBlock(text), Scale(scale) { }
|
AssDialogueBlockDrawing(std::string const& text, int scale) : AssDialogueBlock(text), Scale(scale) { }
|
||||||
void TransformCoords(int trans_x,int trans_y,double mult_x,double mult_y);
|
void TransformCoords(int trans_x,int trans_y,double mult_x,double mult_y);
|
||||||
};
|
};
|
||||||
|
@ -110,7 +110,7 @@ public:
|
||||||
|
|
||||||
std::vector<AssOverrideTag> Tags;
|
std::vector<AssOverrideTag> Tags;
|
||||||
|
|
||||||
AssBlockType GetType() const override { return BLOCK_OVERRIDE; }
|
AssBlockType GetType() const override { return AssBlockType::OVERRIDE; }
|
||||||
std::string GetText() override;
|
std::string GetText() override;
|
||||||
void ParseTags();
|
void ParseTags();
|
||||||
void AddTag(std::string const& tag);
|
void AddTag(std::string const& tag);
|
||||||
|
@ -154,7 +154,7 @@ public:
|
||||||
/// Raw text data
|
/// Raw text data
|
||||||
boost::flyweight<std::string> Text;
|
boost::flyweight<std::string> Text;
|
||||||
|
|
||||||
AssEntryGroup Group() const override { return ENTRY_DIALOGUE; }
|
AssEntryGroup Group() const override { return AssEntryGroup::DIALOGUE; }
|
||||||
|
|
||||||
/// Parse text as ASS and return block information
|
/// Parse text as ASS and return block information
|
||||||
std::auto_ptr<boost::ptr_vector<AssDialogueBlock>> ParseTags() const;
|
std::auto_ptr<boost::ptr_vector<AssDialogueBlock>> ParseTags() const;
|
||||||
|
|
|
@ -42,5 +42,5 @@ std::string const& AssEntry::GroupHeader(bool ssa) const {
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
|
|
||||||
return (ssa ? ssa_headers : ass_headers)[Group()];
|
return (ssa ? ssa_headers : ass_headers)[(int)Group()];
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,13 +37,13 @@
|
||||||
#include <boost/intrusive/list_hook.hpp>
|
#include <boost/intrusive/list_hook.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
enum AssEntryGroup {
|
enum class AssEntryGroup {
|
||||||
ENTRY_INFO = 0,
|
INFO = 0,
|
||||||
ENTRY_STYLE,
|
STYLE,
|
||||||
ENTRY_FONT,
|
FONT,
|
||||||
ENTRY_GRAPHIC,
|
GRAPHIC,
|
||||||
ENTRY_DIALOGUE,
|
DIALOGUE,
|
||||||
ENTRY_GROUP_MAX
|
GROUP_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
class AssEntry : public boost::intrusive::make_list_base_hook<boost::intrusive::link_mode<boost::intrusive::auto_unlink>>::type {
|
class AssEntry : public boost::intrusive::make_list_base_hook<boost::intrusive::link_mode<boost::intrusive::auto_unlink>>::type {
|
||||||
|
|
|
@ -111,11 +111,11 @@ void AssFile::InsertLine(AssEntry *entry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssFile::InsertAttachment(agi::fs::path const& filename) {
|
void AssFile::InsertAttachment(agi::fs::path const& filename) {
|
||||||
AssEntryGroup group = ENTRY_GRAPHIC;
|
AssEntryGroup group = AssEntryGroup::GRAPHIC;
|
||||||
|
|
||||||
auto ext = boost::to_lower_copy(filename.extension().string());
|
auto ext = boost::to_lower_copy(filename.extension().string());
|
||||||
if (ext == ".ttf" || ext == ".ttc" || ext == ".pfb")
|
if (ext == ".ttf" || ext == ".ttc" || ext == ".pfb")
|
||||||
group = ENTRY_FONT;
|
group = AssEntryGroup::FONT;
|
||||||
|
|
||||||
InsertLine(new AssAttachment(filename, group));
|
InsertLine(new AssAttachment(filename, group));
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ public:
|
||||||
AssInfo(std::string const& key, std::string const& value) : key(key), value(value) { }
|
AssInfo(std::string const& key, std::string const& value) : key(key), value(value) { }
|
||||||
|
|
||||||
AssEntry *Clone() const override { return new AssInfo(*this); }
|
AssEntry *Clone() const override { return new AssInfo(*this); }
|
||||||
AssEntryGroup Group() const override { return ENTRY_INFO; }
|
AssEntryGroup Group() const override { return AssEntryGroup::INFO; }
|
||||||
const std::string GetEntryData() const override { return key + ": " + value; }
|
const std::string GetEntryData() const override { return key + ": " + value; }
|
||||||
std::string GetSSAText() const override { return boost::iequals(key, "scripttype: v4.00+") ? "ScriptType: v4.00" : GetEntryData(); }
|
std::string GetSSAText() const override { return boost::iequals(key, "scripttype: v4.00+") ? "ScriptType: v4.00" : GetEntryData(); }
|
||||||
|
|
||||||
|
|
|
@ -107,12 +107,12 @@ void AssParser::ParseStyleLine(std::string const& data) {
|
||||||
|
|
||||||
void AssParser::ParseFontLine(std::string const& data) {
|
void AssParser::ParseFontLine(std::string const& data) {
|
||||||
if (boost::starts_with(data, "fontname: "))
|
if (boost::starts_with(data, "fontname: "))
|
||||||
attach.reset(new AssAttachment(data.substr(10), ENTRY_FONT));
|
attach.reset(new AssAttachment(data.substr(10), AssEntryGroup::FONT));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssParser::ParseGraphicsLine(std::string const& data) {
|
void AssParser::ParseGraphicsLine(std::string const& data) {
|
||||||
if (boost::starts_with(data, "filename: "))
|
if (boost::starts_with(data, "filename: "))
|
||||||
attach.reset(new AssAttachment(data.substr(10), ENTRY_GRAPHIC));
|
attach.reset(new AssAttachment(data.substr(10), AssEntryGroup::GRAPHIC));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssParser::AddLine(std::string const& data) {
|
void AssParser::AddLine(std::string const& data) {
|
||||||
|
@ -158,10 +158,10 @@ void AssParser::AddLine(std::string const& data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssParser::InsertLine(AssEntry *entry) {
|
void AssParser::InsertLine(AssEntry *entry) {
|
||||||
AssEntry *position = insertion_positions[entry->Group()];
|
AssEntry *position = insertion_positions[(size_t)entry->Group()];
|
||||||
if (position)
|
if (position)
|
||||||
target->Line.insert(++target->Line.iterator_to(*position), *entry);
|
target->Line.insert(++target->Line.iterator_to(*position), *entry);
|
||||||
else
|
else
|
||||||
target->Line.push_back(*entry);
|
target->Line.push_back(*entry);
|
||||||
insertion_positions[entry->Group()] = entry;
|
insertion_positions[(size_t)entry->Group()] = entry;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ class AssParser {
|
||||||
int version;
|
int version;
|
||||||
std::unique_ptr<AssAttachment> attach;
|
std::unique_ptr<AssAttachment> attach;
|
||||||
void (AssParser::*state)(std::string const&);
|
void (AssParser::*state)(std::string const&);
|
||||||
std::array<AssEntry*, ENTRY_GROUP_MAX> insertion_positions;
|
std::array<AssEntry*, (size_t)AssEntryGroup::GROUP_MAX> insertion_positions;
|
||||||
|
|
||||||
void InsertLine(AssEntry *entry);
|
void InsertLine(AssEntry *entry);
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ public:
|
||||||
|
|
||||||
const std::string GetEntryData() const override { return data; }
|
const std::string GetEntryData() const override { return data; }
|
||||||
std::string GetSSAText() const override;
|
std::string GetSSAText() const override;
|
||||||
AssEntryGroup Group() const override { return ENTRY_STYLE; }
|
AssEntryGroup Group() const override { return AssEntryGroup::STYLE; }
|
||||||
AssEntry *Clone() const override;
|
AssEntry *Clone() const override;
|
||||||
|
|
||||||
/// Convert an ASS alignment to the equivalent SSA alignment
|
/// Convert an ASS alignment to the equivalent SSA alignment
|
||||||
|
|
|
@ -119,10 +119,10 @@ namespace {
|
||||||
{
|
{
|
||||||
switch (e->Group())
|
switch (e->Group())
|
||||||
{
|
{
|
||||||
case ENTRY_DIALOGUE: return AssFile::COMMIT_DIAG_ADDREM;
|
case AssEntryGroup::DIALOGUE: return AssFile::COMMIT_DIAG_ADDREM;
|
||||||
case ENTRY_STYLE: return AssFile::COMMIT_STYLES;
|
case AssEntryGroup::STYLE: return AssFile::COMMIT_STYLES;
|
||||||
case ENTRY_FONT: return AssFile::COMMIT_ATTACHMENT;
|
case AssEntryGroup::FONT: return AssFile::COMMIT_ATTACHMENT;
|
||||||
case ENTRY_GRAPHIC: return AssFile::COMMIT_ATTACHMENT;
|
case AssEntryGroup::GRAPHIC: return AssFile::COMMIT_ATTACHMENT;
|
||||||
default: return AssFile::COMMIT_SCRIPTINFO;
|
default: return AssFile::COMMIT_SCRIPTINFO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -981,7 +981,7 @@ struct edit_clear_text : public Command {
|
||||||
AssDialogue *line = c->selectionController->GetActiveLine();
|
AssDialogue *line = c->selectionController->GetActiveLine();
|
||||||
boost::ptr_vector<AssDialogueBlock> blocks(line->ParseTags());
|
boost::ptr_vector<AssDialogueBlock> blocks(line->ParseTags());
|
||||||
line->Text = join(blocks
|
line->Text = join(blocks
|
||||||
| filtered([](AssDialogueBlock const& b) { return b.GetType() != BLOCK_PLAIN; })
|
| filtered([](AssDialogueBlock const& b) { return b.GetType() != AssBlockType::PLAIN; })
|
||||||
| transformed(get_text),
|
| transformed(get_text),
|
||||||
"");
|
"");
|
||||||
c->ass->Commit(_("clear line"), AssFile::COMMIT_DIAG_TEXT, -1, line);
|
c->ass->Commit(_("clear line"), AssFile::COMMIT_DIAG_TEXT, -1, line);
|
||||||
|
|
|
@ -57,7 +57,7 @@ static void add_hotkey(wxSizer *sizer, wxWindow *parent, const char *command, wx
|
||||||
|
|
||||||
// Skip over override blocks, comments, and whitespace between blocks
|
// Skip over override blocks, comments, and whitespace between blocks
|
||||||
static bool bad_block(AssDialogueBlock &block) {
|
static bool bad_block(AssDialogueBlock &block) {
|
||||||
return block.GetType() != BLOCK_PLAIN || boost::all(block.GetText(), boost::is_space());
|
return block.GetType() != AssBlockType::PLAIN || boost::all(block.GetText(), boost::is_space());
|
||||||
}
|
}
|
||||||
|
|
||||||
DialogTranslation::DialogTranslation(agi::Context *c)
|
DialogTranslation::DialogTranslation(agi::Context *c)
|
||||||
|
@ -246,7 +246,7 @@ void DialogTranslation::UpdateDisplay() {
|
||||||
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (auto& block : blocks) {
|
for (auto& block : blocks) {
|
||||||
if (block.GetType() == BLOCK_PLAIN) {
|
if (block.GetType() == AssBlockType::PLAIN) {
|
||||||
int cur_size = original_text->GetReverseUnicodePosition(original_text->GetLength());
|
int cur_size = original_text->GetReverseUnicodePosition(original_text->GetLength());
|
||||||
original_text->AppendTextRaw(block.GetText().c_str());
|
original_text->AppendTextRaw(block.GetText().c_str());
|
||||||
if (i == cur_block) {
|
if (i == cur_block) {
|
||||||
|
|
|
@ -119,8 +119,8 @@ void SubsController::Load(agi::fs::path const& filename, std::string charset) {
|
||||||
// Check if the file has at least one style and at least one dialogue line
|
// Check if the file has at least one style and at least one dialogue line
|
||||||
for (auto const& line : temp.Line) {
|
for (auto const& line : temp.Line) {
|
||||||
AssEntryGroup type = line.Group();
|
AssEntryGroup type = line.Group();
|
||||||
if (type == ENTRY_STYLE) found_style = true;
|
if (type == AssEntryGroup::STYLE) found_style = true;
|
||||||
if (type == ENTRY_DIALOGUE) found_dialogue = true;
|
if (type == AssEntryGroup::DIALOGUE) found_dialogue = true;
|
||||||
if (found_style && found_dialogue) break;
|
if (found_style && found_dialogue) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -203,7 +203,7 @@ void SubtitleFormat::StripComments(AssFile &file) {
|
||||||
|
|
||||||
void SubtitleFormat::StripNonDialogue(AssFile &file) {
|
void SubtitleFormat::StripNonDialogue(AssFile &file) {
|
||||||
file.Line.remove_and_dispose_if([](AssEntry const& e) {
|
file.Line.remove_and_dispose_if([](AssEntry const& e) {
|
||||||
return e.Group() != ENTRY_DIALOGUE;
|
return e.Group() != AssEntryGroup::DIALOGUE;
|
||||||
}, [](AssEntry *e) { delete e; });
|
}, [](AssEntry *e) { delete e; });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,14 +88,14 @@ void AssSubtitleFormat::ReadFile(AssFile *target, agi::fs::path const& filename,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline std::string format(AssEntryGroup group, bool ssa) {
|
static inline std::string format(AssEntryGroup group, bool ssa) {
|
||||||
if (group == ENTRY_DIALOGUE) {
|
if (group == AssEntryGroup::DIALOGUE) {
|
||||||
if (ssa)
|
if (ssa)
|
||||||
return "Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text" LINEBREAK;
|
return "Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text" LINEBREAK;
|
||||||
else
|
else
|
||||||
return "Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text" LINEBREAK;
|
return "Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text" LINEBREAK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (group == ENTRY_STYLE) {
|
if (group == AssEntryGroup::STYLE) {
|
||||||
if (ssa)
|
if (ssa)
|
||||||
return "Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding" LINEBREAK;
|
return "Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding" LINEBREAK;
|
||||||
else
|
else
|
||||||
|
@ -113,7 +113,7 @@ void AssSubtitleFormat::WriteFile(const AssFile *src, agi::fs::path const& filen
|
||||||
file.WriteLineToFile("; http://www.aegisub.org/");
|
file.WriteLineToFile("; http://www.aegisub.org/");
|
||||||
|
|
||||||
bool ssa = agi::fs::HasExtension(filename, "ssa");
|
bool ssa = agi::fs::HasExtension(filename, "ssa");
|
||||||
AssEntryGroup group = ENTRY_INFO;
|
AssEntryGroup group = AssEntryGroup::INFO;
|
||||||
|
|
||||||
for (auto const& line : src->Line) {
|
for (auto const& line : src->Line) {
|
||||||
if (line.Group() != group) {
|
if (line.Group() != group) {
|
||||||
|
|
|
@ -277,7 +277,7 @@ namespace
|
||||||
{
|
{
|
||||||
switch (b.GetType())
|
switch (b.GetType())
|
||||||
{
|
{
|
||||||
case BLOCK_PLAIN:
|
case AssBlockType::PLAIN:
|
||||||
// find special characters and convert them
|
// find special characters and convert them
|
||||||
{
|
{
|
||||||
std::string text = b.GetText();
|
std::string text = b.GetText();
|
||||||
|
@ -319,7 +319,7 @@ namespace
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BLOCK_OVERRIDE:
|
case AssBlockType::OVERRIDE:
|
||||||
// find relevant tags and process them
|
// find relevant tags and process them
|
||||||
{
|
{
|
||||||
AssDialogueBlockOverride *ob = static_cast<AssDialogueBlockOverride*>(&b);
|
AssDialogueBlockOverride *ob = static_cast<AssDialogueBlockOverride*>(&b);
|
||||||
|
|
|
@ -125,7 +125,7 @@ void LibassSubtitlesProvider::LoadSubtitles(AssFile *subs) {
|
||||||
data.clear();
|
data.clear();
|
||||||
data.reserve(0x4000);
|
data.reserve(0x4000);
|
||||||
|
|
||||||
AssEntryGroup group = ENTRY_GROUP_MAX;
|
AssEntryGroup group = AssEntryGroup::GROUP_MAX;
|
||||||
for (auto const& line : subs->Line) {
|
for (auto const& line : subs->Line) {
|
||||||
if (group != line.Group()) {
|
if (group != line.Group()) {
|
||||||
group = line.Group();
|
group = line.Group();
|
||||||
|
|
Loading…
Reference in a new issue