void knitting_options_validator::validate(const knitting_options& o) { if (o.target().empty()) { BOOST_LOG_SEV(lg, error) << missing_target; BOOST_THROW_EXCEPTION(validation_error(missing_target)); } if (o.output_directory_path().empty()) { BOOST_LOG_SEV(lg, error) << missing_output_dir; BOOST_THROW_EXCEPTION(validation_error(missing_output_dir)); } }
const std::basic_string<charT>& get_single_string( const std::vector<std::basic_string<charT> >& v, bool allow_empty = false) { static std::basic_string<charT> empty; if (v.size() > 1) boost::throw_exception(validation_error(validation_error::multiple_values_not_allowed)); else if (v.size() == 1) return v.front(); else if (!allow_empty) boost::throw_exception(validation_error(validation_error::at_least_one_value_required)); return empty; }
void mappings_validator::validate(const std::unordered_map<std::string, std::list<mapping>>& mappings_by_set_name) const { BOOST_LOG_SEV(lg, debug) << "Started mappings validation."; BOOST_LOG_SEV(lg, debug) << "Mapping sets found: " << mappings_by_set_name.size(); bool has_default(false); for (const auto& pair : mappings_by_set_name) { const auto& n(pair.first); BOOST_LOG_SEV(lg, trace) << "Started validating mapping set: " << n; if (n == default_mapping_set_name) has_default = true; const auto& mappings(pair.second); /* * Mapping set must have at least one mapping. */ if (mappings.empty()) { BOOST_LOG_SEV(lg, error) << empty_mapping_set << n; BOOST_THROW_EXCEPTION(validation_error(empty_mapping_set + n)); } for (const auto& mapping : mappings) validate(mapping); BOOST_LOG_SEV(lg, trace) << "Finished validating mapping set."; } /* * The default mapping set must be present. */ if (!has_default) { BOOST_LOG_SEV(lg, error) << missing_default_mapping_set; BOOST_THROW_EXCEPTION(validation_error(missing_default_mapping_set)); } BOOST_LOG_SEV(lg, debug) << "Finished mappings validation."; }
void validator::validate_yarn(const processed_object& po) const { if (po.yarn_object_type() == yarn_object_types::object) return; // nothing to validate for yarn objects. /* * Non-yarn objects are not allowed to have stereotypes. */ if (!po.stereotypes().empty()) { BOOST_LOG_SEV(lg, error) << stereotypes_require_yarn_object << ": " << po.stereotypes(); BOOST_THROW_EXCEPTION( validation_error(stereotypes_require_yarn_object)); } }
void validator::validate(const text_template& tt) const { std::unordered_set<std::string> s; for (const auto& kvp : tt.properties().supplied_kvps()) s.insert(kvp.first); BOOST_LOG_SEV(lg, debug) << " Supplied keys: " << s; const auto& e(tt.properties().expected_keys()); BOOST_LOG_SEV(lg, debug) << " Expected keys: " << e; /* * Ensure that all expected keys have been supplied. We may have * received additional keys, but we don't care about those. */ for (const auto ek : e) { const auto i(s.find(ek)); if (i == s.end()) { BOOST_LOG_SEV(lg, error) << key_error + ek; BOOST_THROW_EXCEPTION(validation_error(key_error + ek)); } } }
void validator::validate_uml(const processed_object& po) const { if (po.dia_object_type() == dia_object_types::invalid) { BOOST_LOG_SEV(lg, error) << no_uml_type; BOOST_THROW_EXCEPTION(validation_error(no_uml_type)); } }