commit 71ed687f0b9e0777ce110e0ef7a909ff3521c9f2
parent 05180720e7759164443d90942cc9003c6b0fb27d
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sat, 29 Sep 2018 06:16:06 -0400
refactor string to enum mapping
Diffstat:
4 files changed, 62 insertions(+), 61 deletions(-)
diff --git a/src/package.cpp b/src/package.cpp
@@ -27,30 +27,26 @@ using namespace std;
Package::Type Package::getType(const char *type)
{
- if(!strcmp(type, "script"))
- return ScriptType;
- else if(!strcmp(type, "extension"))
- return ExtensionType;
- else if(!strcmp(type, "effect"))
- return EffectType;
- else if(!strcmp(type, "data"))
- return DataType;
- else if(!strcmp(type, "theme"))
- return ThemeType;
- else if(!strcmp(type, "langpack"))
- return LangPackType;
- else if(!strcmp(type, "webinterface"))
- return WebInterfaceType;
- else if(!strcmp(type, "projecttpl"))
- return ProjectTemplateType;
- else if(!strcmp(type, "tracktpl"))
- return TrackTemplateType;
- else if(!strcmp(type, "midinotenames"))
- return MIDINoteNamesType;
- else if(!strcmp(type, "autoitem"))
- return AutomationItemType;
- else
- return UnknownType;
+ const std::pair<const char *, Type> map[]{
+ {"script", ScriptType},
+ {"extension", ExtensionType},
+ {"effect", EffectType},
+ {"data", DataType},
+ {"theme", ThemeType},
+ {"langpack", LangPackType},
+ {"webinterface", WebInterfaceType},
+ {"projecttpl", ProjectTemplateType},
+ {"tracktpl", TrackTemplateType},
+ {"midinotenames", MIDINoteNamesType},
+ {"autoitem", AutomationItemType},
+ };
+
+ for(auto &[key, value] : map) {
+ if(!strcmp(type, key))
+ return value;
+ }
+
+ return UnknownType;
}
string Package::displayType(const Type type)
diff --git a/src/platform.cpp b/src/platform.cpp
@@ -18,37 +18,39 @@
#include "platform.hpp"
#include <cstring>
+#include <utility>
auto Platform::parse(const char *platform) -> Enum
{
- if(!strcmp(platform, "all"))
- return GenericPlatform;
- else if(!strcmp(platform, "windows"))
- return WindowsPlatform;
- else if(!strcmp(platform, "win32"))
- return Win32Platform;
- else if(!strcmp(platform, "win64"))
- return Win64Platform;
- else if(!strcmp(platform, "darwin"))
- return DarwinPlatform;
- else if(!strcmp(platform, "darwin32"))
- return Darwin32Platform;
- else if(!strcmp(platform, "darwin64"))
- return Darwin64Platform;
- else if(!strcmp(platform, "linux"))
- return LinuxPlatform;
- else if(!strcmp(platform, "linux32"))
- return Linux32Platform;
- else if(!strcmp(platform, "linux64"))
- return Linux64Platform;
- else
- return UnknownPlatform;
+ const std::pair<const char *, Enum> map[]{
+ {"all", GenericPlatform},
+
+ {"windows", WindowsPlatform},
+ {"win32", Win32Platform},
+ {"win64", Win64Platform},
+
+ {"darwin", DarwinPlatform},
+ {"darwin32", Darwin32Platform},
+ {"darwin64", Darwin64Platform},
+
+ {"linux", LinuxPlatform},
+ {"linux32", Linux32Platform},
+ {"linux64", Linux64Platform},
+ };
+
+ for(auto &[key, value] : map) {
+ if(!strcmp(platform, key))
+ return value;
+ }
+
+ return UnknownPlatform;
}
bool Platform::test() const
{
switch(m_value) {
case GenericPlatform:
+
#ifdef __APPLE__
case DarwinPlatform:
# ifdef __x86_64__
@@ -56,6 +58,7 @@ bool Platform::test() const
# else
case Darwin32Platform:
# endif
+
#elif __linux__
case LinuxPlatform:
# ifdef __x86_64__
@@ -63,6 +66,7 @@ bool Platform::test() const
# else
case Linux32Platform:
# endif
+
#elif _WIN32
case WindowsPlatform:
# ifdef _WIN64
diff --git a/src/source.cpp b/src/source.cpp
@@ -26,20 +26,21 @@ using namespace std;
auto Source::getSection(const char *name) -> Section
{
- if(!strcmp(name, "main"))
- return MainSection;
- else if(!strcmp(name, "midi_editor"))
- return MIDIEditorSection;
- else if(!strcmp(name, "midi_inlineeditor"))
- return MIDIInlineEditorSection;
- else if(!strcmp(name, "midi_eventlisteditor"))
- return MIDIEventListEditorSection;
- else if(!strcmp(name, "mediaexplorer"))
- return MediaExplorerSection;
- else if(!strcmp(name, "true"))
- return ImplicitSection;
- else
- return UnknownSection;
+ const std::pair<const char *, Section> map[]{
+ {"main", MainSection},
+ {"midi_editor", MIDIEditorSection},
+ {"midi_inlineeditor", MIDIInlineEditorSection},
+ {"midi_eventlisteditor", MIDIEventListEditorSection},
+ {"mediaexplorer", MediaExplorerSection},
+ {"true", ImplicitSection},
+ };
+
+ for(auto &[key, value] : map) {
+ if(!strcmp(name, key))
+ return value;
+ }
+
+ return UnknownSection;
}
auto Source::detectSection(const Path &category) -> Section
diff --git a/src/transaction.cpp b/src/transaction.cpp
@@ -266,7 +266,7 @@ void Transaction::registerScript(const HostTicket ®, const bool isLastCall)
vector<int> sections;
- for(const auto &[flag, id] : sectionMap) {
+ for(auto &[flag, id] : sectionMap) {
if(reg.file.sections & flag)
sections.push_back(id);
}