void json_hydrator::read_module_path(const boost::property_tree::ptree& pt, model& m, qname& qn) const { const auto i(pt.find(module_path_key)); if (i == pt.not_found()) return; for (auto j(i->second.begin()); j != i->second.end(); ++j) { const auto module_name(j->second.get_value<std::string>()); qn.module_path().push_back(module_name); qname module_qn; module_qn.simple_name(module_name); module_qn.model_name(model_name(m)); auto mp(qn.module_path()); mp.pop_back(); module_qn.module_path(mp); const auto i(m.modules().find(module_qn)); if (i == m.modules().end()) { module mod; mod.name(module_qn); mod.origin_type(m.origin_type()); mod.generation_type(m.generation_type()); m.modules().insert(std::make_pair(module_qn, mod)); } } }
/** * @brief Add comparable support for qnames. * * This is required as part of the current (very sub-optimal) * implementation of concept processing. */ inline bool operator<(const qname& lhs, const qname& rhs) { return lhs.model_name() < rhs.model_name() || (lhs.model_name() == rhs.model_name() && (lhs.external_module_path() < rhs.external_module_path() || (lhs.external_module_path() == rhs.external_module_path() && (lhs.simple_name() < rhs.simple_name())))); }
boost::optional<qname> containing_module(model& m, const qname& qn) { if (qn.model_name().empty() || qn.simple_name() == m.name().model_name()) { BOOST_LOG_SEV(lg, debug) << "Type has no containing module: " << string_converter::convert(qn); return boost::optional<qname>(); } qname module_qn; module_qn.model_name(qn.model_name()); if (qn.module_path().empty()) { module_qn.simple_name(qn.model_name()); } else { module_qn.simple_name(qn.module_path().back()); module_qn.module_path(qn.module_path()); module_qn.module_path().pop_back(); } const auto i(m.modules().find(module_qn)); if (i != m.modules().end()) return module_qn; BOOST_LOG_SEV(lg, debug) << "Could not find containing module: " << string_converter::convert(module_qn); return boost::optional<qname>();; }
void merger::check_qname(const std::string& model_name, const qname& key, const qname& value) const { if (key.model_name() != model_name) { std::ostringstream s; s << "Type does not belong to this model. Model name: '" << model_name << "'. Type qname: " << key; BOOST_LOG_SEV(lg, error) << s.str(); BOOST_THROW_EXCEPTION(merging_error(s.str())); } if (key != value) { std::ostringstream s; s << "Inconsistency between key and value qnames: " << " key: " << key << " value: " << value; BOOST_LOG_SEV(lg, error) << s.str(); BOOST_THROW_EXCEPTION(merging_error(s.str())); } }
std::string string_converter::convert(const qname& qn) { std::ostringstream s; for (const auto& m : qn.external_module_path()) s << "<" << m << ">"; if (!qn.model_name().empty()) s << "<" << qn.model_name() << ">"; for (const auto& m : qn.module_path()) s << "<" << m << ">"; if (!qn.simple_name().empty()) s << "<" << qn.simple_name() << ">"; return s.str(); }