boost::shared_ptr<yarn::element> assistant_factory::make(const yarn::intermediate_model& im) const { yarn::name_factory nf; const auto n(nf.build_element_in_model(im.name(), assistant_name)); auto r(boost::make_shared<assistant>()); r->name(n); r->origin_type(im.origin_type()); return r; }
void hydrator::read_element(const boost::property_tree::ptree& pt, yarn::intermediate_model& m) const { yarn::name_builder b; const auto in_global_module(pt.get(in_global_module_key, false)); if (!in_global_module) b.model_name(m.name().location()); const auto simple_name_value(pt.get<std::string>(simple_name_key)); b.simple_name(simple_name_value); const auto i(pt.find(internal_modules_key)); if (i != pt.not_found()) { std::list<std::string> ipp; for (auto& item : pt.get_child(internal_modules_key)) ipp.push_back(item.second.get_value<std::string>()); if (!ipp.empty()) b.internal_modules(ipp); else { BOOST_LOG_SEV(lg, debug) << "Ignoring empty internal module path. " << "Type: " << simple_name_value; } } yarn::name n(b.build()); const auto documentation(pt.get_optional<std::string>(documentation_key)); const auto lambda([&](yarn::element& e) { BOOST_LOG_SEV(lg, debug) << "Processing element: " << n.qualified(); e.name(n); e.origin_type(m.origin_type()); e.generation_type(m.generation_type()); e.in_global_module(in_global_module); if (documentation) e.documentation(*documentation); const auto scope(dynamic::scope_types::entity); e.extensions(create_dynamic_extensions(pt, scope)); }); const auto meta_type_value(pt.get<std::string>(meta_type_key)); if (meta_type_value == meta_type_object_value) { yarn::object o; lambda(o); const auto ot(pt.get_optional<std::string>(object_type_key)); o.object_type(to_object_type(ot)); m.objects().insert(std::make_pair(n.qualified(), o)); } else if (meta_type_value == meta_type_primitive_value) { yarn::primitive p; const auto dit(pt.get(is_default_enumeration_type_key, false)); p.is_default_enumeration_type(dit); lambda(p); m.primitives().insert(std::make_pair(n.qualified(), p)); } else { BOOST_LOG_SEV(lg, error) << invalid_meta_type << meta_type_value; BOOST_THROW_EXCEPTION( hydration_error(invalid_meta_type + meta_type_value)); } }