typename LIB::Ptr library () { const std::string lname = LIB::library_namespace(); //instead of LIB::type_name(); Component::Ptr clib = get_child_ptr(lname); typename LIB::Ptr lib; if ( is_null(clib) ) // doesnt exist so build it { CF::Common::TypeInfo::instance().regist< LIB >( lname ); lib = create_component_ptr< LIB >(lname); cf_assert( is_not_null(lib) ); return lib; } // try to convert existing ptr to LIB::Ptr and return it lib = clib->as_ptr<LIB>(); if( is_null(lib) ) // conversion failed throw CastingFailed( FromHere(), "Found component in CLibraries with name " + lname + " but is not the actual library " + LIB::type_name() ); return lib; }
ElementLoop& BoundaryTerm::access_element_loop( const std::string& type_name ) { // ensure that the fields are present link_fields(); // get the element loop or create it if does not exist ElementLoop::Ptr loop; Common::Component::Ptr cloop = get_child_ptr( "LOOP" ); if( is_null( cloop ) ) { const std::string update_vars_type = physical_model().get_child( RDM::Tags::update_vars() ) .as_type<Physics::Variables>() .type(); loop = build_component_abstract_type_reduced< FaceLoop >( "FaceLoopT<" + type_name + "," + update_vars_type + ">" , "LOOP"); add_component(loop); } else loop = cloop->as_ptr_checked<ElementLoop>(); return *loop; }
CActionDirector& CActionDirector::append(const CAction::Ptr& action) { Component::Ptr existing_child = get_child_ptr(action->name()); if(is_null(existing_child)) { if(action->has_parent()) { CLink& action_link = create_component<CLink>(action->name()); action_link.link_to(action); } else { add_component(action); } on_action_added(*action); } else { // If a child with the given name existed, check that it corresponds to the supplied action CAction::Ptr existing_action = boost::dynamic_pointer_cast<CAction>(existing_child); if(is_null(existing_action)) throw ValueExists(FromHere(), "A component named " + action->name() + " already exists in " + uri().string() + ", but it is not a CAction"); if(existing_action != action) throw ValueExists(FromHere(), "An action named " + action->name() + " already exists in " + uri().string() + ", but it is different from the appended action"); } Option& actions_prop = option("ActionOrder"); std::vector<std::string> actions; actions_prop.put_value(actions); actions.push_back(action->name()); actions_prop.change_value(actions); return *this; }