Skip to content

Commit

Permalink
Schema message types should be extendable by subclasses.
Browse files Browse the repository at this point in the history
This is a rather primitive way of doing it, but it works and isn't a huge and complicated change.
  • Loading branch information
CelticMinstrel committed Oct 24, 2020
1 parent 0b8f54f commit d0561c7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
18 changes: 12 additions & 6 deletions src/serialization/schema_validator.cpp
Expand Up @@ -367,12 +367,6 @@ void schema_validator::print(message_info& el)
case MISSING_KEY:
missing_key_error(el.file, el.line, el.tag, el.key, create_exceptions_);
break;
case WRONG_TYPE:
wrong_type_error(el.file, el.line, el.tag, el.key, el.value, create_exceptions_);
break;
case WRONG_PATH:
wrong_path_error(el.file, el.line, el.tag, el.key, el.value, create_exceptions_);
break;
}
}

Expand Down Expand Up @@ -548,4 +542,16 @@ bool schema_self_validator::reference::can_find(const wml_tag& root, const confi
return root.find_tag(value_, root, cfg) != nullptr;
}

void schema_self_validator::print(message_info& el)
{
switch(el.type) {
case WRONG_TYPE:
wrong_type_error(el.file, el.line, el.tag, el.key, el.value, create_exceptions_);
break;
case WRONG_PATH:
wrong_path_error(el.file, el.line, el.tag, el.key, el.value, create_exceptions_);
break;
}
}

} // namespace schema_validation{
16 changes: 9 additions & 7 deletions src/serialization/schema_validator.hpp
Expand Up @@ -77,9 +77,8 @@ class schema_validator : public abstract_validator
typedef std::stack<cnt_map> cnt_stack;

protected:
enum message_type{ WRONG_TAG, EXTRA_TAG, MISSING_TAG, EXTRA_KEY, MISSING_KEY, WRONG_VALUE, WRONG_TYPE, WRONG_PATH };
private:
// error_cache
using message_type = int;
enum { WRONG_TAG, EXTRA_TAG, MISSING_TAG, EXTRA_KEY, MISSING_KEY, WRONG_VALUE, NEXT_ERROR };

/**
* Messages are cached.
Expand Down Expand Up @@ -112,20 +111,21 @@ class schema_validator : public abstract_validator
}
};

/** Controls the way to print errors. */
bool create_exceptions_;
private:

typedef std::deque<message_info> message_list;
typedef std::map<const config*, message_list> message_map;

void print(message_info&);
virtual void print(message_info&);

/** Reads config from input. */
bool read_config_file(const std::string& filename);

/** Shows, if validator is initialized with schema file. */
bool config_read_;

/** Controls the way to print errors. */
bool create_exceptions_;

/** Root of schema information. */
wml_tag root_;

Expand Down Expand Up @@ -182,6 +182,8 @@ class schema_self_validator : public schema_validator
std::multimap<std::string, std::string> derivations_;
int type_nesting_, condition_nesting_;
bool tag_path_exists(const config& cfg, const reference& ref);
void print(message_info& message) override;
enum { WRONG_TYPE = NEXT_ERROR, WRONG_PATH, NEXT_ERROR };
};

} // namespace schema_validation{

0 comments on commit d0561c7

Please sign in to comment.