From de7b09f7f7c29b035a29647ce2463c189687cffe Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 12 Jun 2013 15:54:19 -0700 Subject: [PATCH] Change some enums into enum classes --- aegisub/src/ass_attachment.cpp | 2 +- aegisub/src/ass_dialogue.h | 22 +++++++++++----------- aegisub/src/ass_entry.cpp | 2 +- aegisub/src/ass_entry.h | 14 +++++++------- aegisub/src/ass_file.cpp | 4 ++-- aegisub/src/ass_info.h | 2 +- aegisub/src/ass_parser.cpp | 8 ++++---- aegisub/src/ass_parser.h | 2 +- aegisub/src/ass_style.h | 2 +- aegisub/src/auto4_lua_assfile.cpp | 8 ++++---- aegisub/src/command/edit.cpp | 2 +- aegisub/src/dialog_translation.cpp | 4 ++-- aegisub/src/subs_controller.cpp | 4 ++-- aegisub/src/subtitle_format.cpp | 2 +- aegisub/src/subtitle_format_ass.cpp | 6 +++--- aegisub/src/subtitle_format_ebu3264.cpp | 4 ++-- aegisub/src/subtitles_provider_libass.cpp | 2 +- 17 files changed, 45 insertions(+), 45 deletions(-) diff --git a/aegisub/src/ass_attachment.cpp b/aegisub/src/ass_attachment.cpp index 6217c7c61..d8f37b04b 100644 --- a/aegisub/src/ass_attachment.cpp +++ b/aegisub/src/ass_attachment.cpp @@ -46,7 +46,7 @@ AssAttachment::AssAttachment(agi::fs::path const& name, AssEntryGroup group) file->seekg(0, std::ios::beg); 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); } diff --git a/aegisub/src/ass_dialogue.h b/aegisub/src/ass_dialogue.h index 4ee3a1690..8da137a12 100644 --- a/aegisub/src/ass_dialogue.h +++ b/aegisub/src/ass_dialogue.h @@ -42,12 +42,12 @@ #include #include -enum AssBlockType { - BLOCK_BASE, - BLOCK_PLAIN, - BLOCK_COMMENT, - BLOCK_OVERRIDE, - BLOCK_DRAWING +enum class AssBlockType { + BASE, + PLAIN, + COMMENT, + OVERRIDE, + DRAWING }; /// @class AssDialogueBlock @@ -85,13 +85,13 @@ public: class AssDialogueBlockPlain : public AssDialogueBlock { public: 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) { } }; class AssDialogueBlockComment : public AssDialogueBlock { public: - AssBlockType GetType() const override { return BLOCK_COMMENT; } + AssBlockType GetType() const override { return AssBlockType::COMMENT; } AssDialogueBlockComment(std::string const& text = std::string()) : AssDialogueBlock("{" + text + "}") { } }; @@ -99,7 +99,7 @@ class AssDialogueBlockDrawing : public AssDialogueBlock { public: 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) { } void TransformCoords(int trans_x,int trans_y,double mult_x,double mult_y); }; @@ -110,7 +110,7 @@ public: std::vector Tags; - AssBlockType GetType() const override { return BLOCK_OVERRIDE; } + AssBlockType GetType() const override { return AssBlockType::OVERRIDE; } std::string GetText() override; void ParseTags(); void AddTag(std::string const& tag); @@ -154,7 +154,7 @@ public: /// Raw text data boost::flyweight Text; - AssEntryGroup Group() const override { return ENTRY_DIALOGUE; } + AssEntryGroup Group() const override { return AssEntryGroup::DIALOGUE; } /// Parse text as ASS and return block information std::auto_ptr> ParseTags() const; diff --git a/aegisub/src/ass_entry.cpp b/aegisub/src/ass_entry.cpp index 913f6e8bc..f6d06dbe4 100644 --- a/aegisub/src/ass_entry.cpp +++ b/aegisub/src/ass_entry.cpp @@ -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()]; } diff --git a/aegisub/src/ass_entry.h b/aegisub/src/ass_entry.h index 1871a6271..466d44b9a 100644 --- a/aegisub/src/ass_entry.h +++ b/aegisub/src/ass_entry.h @@ -37,13 +37,13 @@ #include #include -enum AssEntryGroup { - ENTRY_INFO = 0, - ENTRY_STYLE, - ENTRY_FONT, - ENTRY_GRAPHIC, - ENTRY_DIALOGUE, - ENTRY_GROUP_MAX +enum class AssEntryGroup { + INFO = 0, + STYLE, + FONT, + GRAPHIC, + DIALOGUE, + GROUP_MAX }; class AssEntry : public boost::intrusive::make_list_base_hook>::type { diff --git a/aegisub/src/ass_file.cpp b/aegisub/src/ass_file.cpp index 69c9e92ca..fdea7c011 100644 --- a/aegisub/src/ass_file.cpp +++ b/aegisub/src/ass_file.cpp @@ -111,11 +111,11 @@ void AssFile::InsertLine(AssEntry *entry) { } 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()); if (ext == ".ttf" || ext == ".ttc" || ext == ".pfb") - group = ENTRY_FONT; + group = AssEntryGroup::FONT; InsertLine(new AssAttachment(filename, group)); } diff --git a/aegisub/src/ass_info.h b/aegisub/src/ass_info.h index 7b49c314c..0f5a14606 100644 --- a/aegisub/src/ass_info.h +++ b/aegisub/src/ass_info.h @@ -27,7 +27,7 @@ public: AssInfo(std::string const& key, std::string const& value) : key(key), value(value) { } 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; } std::string GetSSAText() const override { return boost::iequals(key, "scripttype: v4.00+") ? "ScriptType: v4.00" : GetEntryData(); } diff --git a/aegisub/src/ass_parser.cpp b/aegisub/src/ass_parser.cpp index 2917785c8..b2ff4125d 100644 --- a/aegisub/src/ass_parser.cpp +++ b/aegisub/src/ass_parser.cpp @@ -107,12 +107,12 @@ void AssParser::ParseStyleLine(std::string const& data) { void AssParser::ParseFontLine(std::string const& data) { 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) { 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) { @@ -158,10 +158,10 @@ void AssParser::AddLine(std::string const& data) { } void AssParser::InsertLine(AssEntry *entry) { - AssEntry *position = insertion_positions[entry->Group()]; + AssEntry *position = insertion_positions[(size_t)entry->Group()]; if (position) target->Line.insert(++target->Line.iterator_to(*position), *entry); else target->Line.push_back(*entry); - insertion_positions[entry->Group()] = entry; + insertion_positions[(size_t)entry->Group()] = entry; } diff --git a/aegisub/src/ass_parser.h b/aegisub/src/ass_parser.h index fb0a813ae..820638a8d 100644 --- a/aegisub/src/ass_parser.h +++ b/aegisub/src/ass_parser.h @@ -26,7 +26,7 @@ class AssParser { int version; std::unique_ptr attach; void (AssParser::*state)(std::string const&); - std::array insertion_positions; + std::array insertion_positions; void InsertLine(AssEntry *entry); diff --git a/aegisub/src/ass_style.h b/aegisub/src/ass_style.h index bd2c3ded7..ead95b777 100644 --- a/aegisub/src/ass_style.h +++ b/aegisub/src/ass_style.h @@ -79,7 +79,7 @@ public: const std::string GetEntryData() const override { return data; } std::string GetSSAText() const override; - AssEntryGroup Group() const override { return ENTRY_STYLE; } + AssEntryGroup Group() const override { return AssEntryGroup::STYLE; } AssEntry *Clone() const override; /// Convert an ASS alignment to the equivalent SSA alignment diff --git a/aegisub/src/auto4_lua_assfile.cpp b/aegisub/src/auto4_lua_assfile.cpp index aaa10cc1c..112e29936 100644 --- a/aegisub/src/auto4_lua_assfile.cpp +++ b/aegisub/src/auto4_lua_assfile.cpp @@ -119,10 +119,10 @@ namespace { { switch (e->Group()) { - case ENTRY_DIALOGUE: return AssFile::COMMIT_DIAG_ADDREM; - case ENTRY_STYLE: return AssFile::COMMIT_STYLES; - case ENTRY_FONT: return AssFile::COMMIT_ATTACHMENT; - case ENTRY_GRAPHIC: return AssFile::COMMIT_ATTACHMENT; + case AssEntryGroup::DIALOGUE: return AssFile::COMMIT_DIAG_ADDREM; + case AssEntryGroup::STYLE: return AssFile::COMMIT_STYLES; + case AssEntryGroup::FONT: return AssFile::COMMIT_ATTACHMENT; + case AssEntryGroup::GRAPHIC: return AssFile::COMMIT_ATTACHMENT; default: return AssFile::COMMIT_SCRIPTINFO; } } diff --git a/aegisub/src/command/edit.cpp b/aegisub/src/command/edit.cpp index 417ba022f..b1225d81b 100644 --- a/aegisub/src/command/edit.cpp +++ b/aegisub/src/command/edit.cpp @@ -981,7 +981,7 @@ struct edit_clear_text : public Command { AssDialogue *line = c->selectionController->GetActiveLine(); boost::ptr_vector blocks(line->ParseTags()); 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), ""); c->ass->Commit(_("clear line"), AssFile::COMMIT_DIAG_TEXT, -1, line); diff --git a/aegisub/src/dialog_translation.cpp b/aegisub/src/dialog_translation.cpp index 3b30916d7..bb26a24c9 100644 --- a/aegisub/src/dialog_translation.cpp +++ b/aegisub/src/dialog_translation.cpp @@ -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 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) @@ -246,7 +246,7 @@ void DialogTranslation::UpdateDisplay() { size_t i = 0; for (auto& block : blocks) { - if (block.GetType() == BLOCK_PLAIN) { + if (block.GetType() == AssBlockType::PLAIN) { int cur_size = original_text->GetReverseUnicodePosition(original_text->GetLength()); original_text->AppendTextRaw(block.GetText().c_str()); if (i == cur_block) { diff --git a/aegisub/src/subs_controller.cpp b/aegisub/src/subs_controller.cpp index c40cb70be..9f8e69a9f 100644 --- a/aegisub/src/subs_controller.cpp +++ b/aegisub/src/subs_controller.cpp @@ -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 for (auto const& line : temp.Line) { AssEntryGroup type = line.Group(); - if (type == ENTRY_STYLE) found_style = true; - if (type == ENTRY_DIALOGUE) found_dialogue = true; + if (type == AssEntryGroup::STYLE) found_style = true; + if (type == AssEntryGroup::DIALOGUE) found_dialogue = true; if (found_style && found_dialogue) break; } diff --git a/aegisub/src/subtitle_format.cpp b/aegisub/src/subtitle_format.cpp index 66583d7fb..48b227609 100644 --- a/aegisub/src/subtitle_format.cpp +++ b/aegisub/src/subtitle_format.cpp @@ -203,7 +203,7 @@ void SubtitleFormat::StripComments(AssFile &file) { void SubtitleFormat::StripNonDialogue(AssFile &file) { file.Line.remove_and_dispose_if([](AssEntry const& e) { - return e.Group() != ENTRY_DIALOGUE; + return e.Group() != AssEntryGroup::DIALOGUE; }, [](AssEntry *e) { delete e; }); } diff --git a/aegisub/src/subtitle_format_ass.cpp b/aegisub/src/subtitle_format_ass.cpp index 194d3e00e..856d1cfa1 100644 --- a/aegisub/src/subtitle_format_ass.cpp +++ b/aegisub/src/subtitle_format_ass.cpp @@ -88,14 +88,14 @@ void AssSubtitleFormat::ReadFile(AssFile *target, agi::fs::path const& filename, #endif static inline std::string format(AssEntryGroup group, bool ssa) { - if (group == ENTRY_DIALOGUE) { + if (group == AssEntryGroup::DIALOGUE) { if (ssa) return "Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text" LINEBREAK; else return "Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text" LINEBREAK; } - if (group == ENTRY_STYLE) { + if (group == AssEntryGroup::STYLE) { if (ssa) return "Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding" LINEBREAK; else @@ -113,7 +113,7 @@ void AssSubtitleFormat::WriteFile(const AssFile *src, agi::fs::path const& filen file.WriteLineToFile("; http://www.aegisub.org/"); bool ssa = agi::fs::HasExtension(filename, "ssa"); - AssEntryGroup group = ENTRY_INFO; + AssEntryGroup group = AssEntryGroup::INFO; for (auto const& line : src->Line) { if (line.Group() != group) { diff --git a/aegisub/src/subtitle_format_ebu3264.cpp b/aegisub/src/subtitle_format_ebu3264.cpp index 6264380ca..a5ff8b6ee 100644 --- a/aegisub/src/subtitle_format_ebu3264.cpp +++ b/aegisub/src/subtitle_format_ebu3264.cpp @@ -277,7 +277,7 @@ namespace { switch (b.GetType()) { - case BLOCK_PLAIN: + case AssBlockType::PLAIN: // find special characters and convert them { std::string text = b.GetText(); @@ -319,7 +319,7 @@ namespace } break; - case BLOCK_OVERRIDE: + case AssBlockType::OVERRIDE: // find relevant tags and process them { AssDialogueBlockOverride *ob = static_cast(&b); diff --git a/aegisub/src/subtitles_provider_libass.cpp b/aegisub/src/subtitles_provider_libass.cpp index a26e5376a..a89dc1a31 100644 --- a/aegisub/src/subtitles_provider_libass.cpp +++ b/aegisub/src/subtitles_provider_libass.cpp @@ -125,7 +125,7 @@ void LibassSubtitlesProvider::LoadSubtitles(AssFile *subs) { data.clear(); data.reserve(0x4000); - AssEntryGroup group = ENTRY_GROUP_MAX; + AssEntryGroup group = AssEntryGroup::GROUP_MAX; for (auto const& line : subs->Line) { if (group != line.Group()) { group = line.Group();