Change some enums into enum classes

This commit is contained in:
Thomas Goyne 2013-06-12 15:54:19 -07:00
parent e99f4c4da1
commit de7b09f7f7
17 changed files with 45 additions and 45 deletions

View file

@ -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);
}

View file

@ -42,12 +42,12 @@
#include <boost/ptr_container/ptr_vector.hpp>
#include <vector>
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<AssOverrideTag> 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<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
std::auto_ptr<boost::ptr_vector<AssDialogueBlock>> ParseTags() const;

View file

@ -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()];
}

View file

@ -37,13 +37,13 @@
#include <boost/intrusive/list_hook.hpp>
#include <string>
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<boost::intrusive::link_mode<boost::intrusive::auto_unlink>>::type {

View file

@ -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));
}

View file

@ -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(); }

View file

@ -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;
}

View file

@ -26,7 +26,7 @@ class AssParser {
int version;
std::unique_ptr<AssAttachment> attach;
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);

View file

@ -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

View file

@ -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;
}
}

View file

@ -981,7 +981,7 @@ struct edit_clear_text : public Command {
AssDialogue *line = c->selectionController->GetActiveLine();
boost::ptr_vector<AssDialogueBlock> 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);

View file

@ -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) {

View file

@ -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;
}

View file

@ -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; });
}

View file

@ -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) {

View file

@ -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<AssDialogueBlockOverride*>(&b);

View file

@ -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();