diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-06-10 21:17:23 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-06-13 17:22:05 -0700 |
commit | 282e626ac112b1ca7a9bf9f9d4c0239db8fbd97a (patch) | |
tree | f83ef7974687a84341dd616b364b2aa5a9c012a8 /src/mbgl/platform | |
parent | 36bef2157595e1455aa55c64c6c526f096dd1c8e (diff) | |
download | qtlocation-mapboxgl-282e626ac112b1ca7a9bf9f9d4c0239db8fbd97a.tar.gz |
[core] Make enum ↔ string conversion more generic-friendly
Rewrite enum.hpp in such a way that parseConstant can be defined generically for all enumerated types.
While there, properly validated enumerated property values.
Diffstat (limited to 'src/mbgl/platform')
-rw-r--r-- | src/mbgl/platform/event.cpp | 34 | ||||
-rw-r--r-- | src/mbgl/platform/log.cpp | 3 |
2 files changed, 36 insertions, 1 deletions
diff --git a/src/mbgl/platform/event.cpp b/src/mbgl/platform/event.cpp new file mode 100644 index 0000000000..68d75a2941 --- /dev/null +++ b/src/mbgl/platform/event.cpp @@ -0,0 +1,34 @@ +#include <mbgl/platform/event.hpp> +#include <mbgl/util/enum.hpp> + +namespace mbgl { + +MBGL_DEFINE_ENUM(EventSeverity, { + { EventSeverity::Debug, "DEBUG" }, + { EventSeverity::Info, "INFO" }, + { EventSeverity::Warning, "WARNING" }, + { EventSeverity::Error, "ERROR" }, + { EventSeverity(-1), "UNKNOWN" }, +}); + +MBGL_DEFINE_ENUM(Event, { + { Event::General, "General" }, + { Event::Setup, "Setup" }, + { Event::Shader, "Shader" }, + { Event::ParseStyle, "ParseStyle" }, + { Event::ParseTile, "ParseTile" }, + { Event::Render, "Render" }, + { Event::Style, "Style" }, + { Event::Database, "Database" }, + { Event::HttpRequest, "HttpRequest" }, + { Event::Sprite, "Sprite" }, + { Event::Image, "Image" }, + { Event::OpenGL, "OpenGL" }, + { Event::JNI, "JNI" }, + { Event::Android, "Android" }, + { Event::Crash, "Crash" }, + { Event::Glyph, "Glyph" }, + { Event(-1), "Unknown" }, +}); + +} // namespace mbgl diff --git a/src/mbgl/platform/log.cpp b/src/mbgl/platform/log.cpp index 2118511592..4b56435df0 100644 --- a/src/mbgl/platform/log.cpp +++ b/src/mbgl/platform/log.cpp @@ -1,4 +1,5 @@ #include <mbgl/platform/log.hpp> +#include <mbgl/util/enum.hpp> #include <cstdio> #include <cstdarg> @@ -54,7 +55,7 @@ void Log::record(EventSeverity severity, Event event, int64_t code, const std::s logStream << "{" << name << "}"; #endif - logStream << "[" << event << "]"; + logStream << "[" << Enum<Event>::toString(event) << "]"; if (code >= 0) { logStream << "(" << code << ")"; |