[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.
This commit is contained in:
John Firebaugh
2016-06-10 21:17:23 -07:00
parent 36bef21575
commit 282e626ac1
15 changed files with 194 additions and 258 deletions

View File

@@ -3,6 +3,7 @@
#include <mbgl/style/parser.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/enum.hpp>
#include <rapidjson/document.h>
@@ -46,8 +47,8 @@ TEST_P(StyleParserTest, ParseStyle) {
const uint32_t count = js_entry[rapidjson::SizeType(0)].GetUint();
const FixtureLogObserver::LogMessage message {
EventSeverityClass(js_entry[rapidjson::SizeType(1)].GetString()),
EventClass(js_entry[rapidjson::SizeType(2)].GetString()),
*Enum<EventSeverity>::toEnum(js_entry[rapidjson::SizeType(1)].GetString()),
*Enum<Event>::toEnum(js_entry[rapidjson::SizeType(2)].GetString()),
int64_t(-1),
js_entry[rapidjson::SizeType(3)].GetString()
};