EnumReader now warns about the correct string,

parse_enum function throws if the string can not be parsed

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1341 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2009-01-11 00:45:21 +00:00
parent 8c1cf2a0a6
commit c8dd777bca
5 changed files with 24 additions and 15 deletions
+14
View File
@@ -411,3 +411,17 @@ template <> void Reader::handle(FileName& f) {
handle(static_cast<String&>(f));
}
}
// ----------------------------------------------------------------------------- : EnumReader
void EnumReader::warnIfNotDone(Reader* errors_to) {
if (!done) {
// warning: unknown value
errors_to->warning(_ERROR_1_("unrecognized value", read));
}
}
void EnumReader::errorIfNotDone() {
if (!done) {
throw ParseError(_ERROR_1_("unrecognized value", read));
}
}
+5 -6
View File
@@ -256,15 +256,12 @@ void Reader::handle(IndexMap<K,V>& m) {
template<> void Reader::handle<Enum>(Enum& enum_) { \
EnumReader reader(getValue()); \
reflect_ ## Enum(enum_, reader); \
if (!reader.isDone()) { \
/* warning: unknown value */ \
warning(_ERROR_1_("unrecognized value", value)); \
} \
reader.warnIfNotDone(this); \
} \
bool parse_enum(const String& value, Enum& out) { \
void parse_enum(const String& value, Enum& out) { \
EnumReader reader(value); \
reflect_ ## Enum(out, reader); \
return reader.isDone(); \
reader.errorIfNotDone(); \
}
/// 'Tag' to be used when reflecting enumerations for Reader
@@ -287,6 +284,8 @@ class EnumReader {
}
inline bool isDone() const { return done; }
void warnIfNotDone(Reader* errors_to);
void errorIfNotDone();
private:
String read; ///< The string to match to a value name