Changeset 26:f783224f355c in finroc_plugins_composite_ports


Ignore:
Timestamp:
30.03.2021 00:37:55 (7 months ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Phase:
public
Message:

Optimizes skill modifier integration (in particular, modifiers may now be attached to any node in the framework element tree)

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tInterfaceBase.cpp

    r24 r26  
    118118} 
    119119 
    120 tInterfaceBase::tPrimaryPortType ModifierDefinesPartialInterface(const core::tFrameworkElement& parent_interface, const rrlib::rtti::tType& interface_type) 
    121 { 
    122   if ((!parent_interface.IsPort()) && parent_interface.GetFlag(tFlag::INTERFACE) && internal::IsComponent(parent_interface.GetParent())) 
    123   { 
    124     tInterfaceModifier* interface_modifier = parent_interface.GetParent()->GetAnnotation<tInterfaceModifier>(); 
    125     if (interface_modifier) 
    126     { 
    127       return interface_modifier->Implementation().PartialInterface(interface_type); 
    128     } 
    129   } 
    130   return tInterfaceBase::tPrimaryPortType::ANY; 
    131 } 
    132  
    133 tInterfaceBase::tPrimaryPortType ModifierDefinesPartialInterface(const core::tFrameworkElement* any_element, const rrlib::rtti::tType& interface_type) 
    134 { 
    135   if (any_element) 
    136   { 
    137     auto aggregator = GetAggregator(*any_element); 
    138     return ModifierDefinesPartialInterface(*aggregator, interface_type); 
     120tInterfaceModifier* GetModifier(const core::tFrameworkElement& any_element) 
     121{ 
     122  auto current_element = &any_element; 
     123  do 
     124  { 
     125    auto annotation = current_element->GetAnnotation<tInterfaceModifier>(); 
     126    if (annotation) 
     127    { 
     128      return annotation; 
     129    } 
     130    current_element = current_element->GetParent(); 
     131  } 
     132  while (current_element); 
     133  return nullptr; 
     134} 
     135 
     136tInterfaceBase::tPrimaryPortType ModifierDefinesPartialInterface(const core::tFrameworkElement& parent, const rrlib::rtti::tType& interface_type) 
     137{ 
     138  tInterfaceModifier* modifier = GetModifier(parent); 
     139  if (modifier) 
     140  { 
     141    return modifier->Implementation().PartialInterface(interface_type); 
    139142  } 
    140143  return tInterfaceBase::tPrimaryPortType::ANY; 
     
    293296 
    294297tInterfaceBase::tBackend::tBackend(const rrlib::rtti::tType& interface_type, core::tFrameworkElement* parent_component, core::tFrameworkElement* parent, int primary_relation_id, const std::string& name, bool convenience_port_type, const tConnectFunction& custom_connect_function, tCreateMissingComponentInterfaceFunction create_missing_component_interface_function, tPrimaryPortType primary_port_type, bool partial_interface) : 
    295   tAbstractPort(MakeCreationInfo(interface_type, name, *parent, partial_interface || tScopedExtraConstructorParameters::Get()->partial_interface || ModifierDefinesPartialInterface(parent, interface_type))), 
     298  tAbstractPort(MakeCreationInfo(interface_type, name, *parent, partial_interface || tScopedExtraConstructorParameters::Get()->partial_interface || ModifierDefinesPartialInterface(*parent, interface_type))), 
    296299  parent_component(parent_component), 
    297300  primary_backend(*this), 
     
    405408core::tAbstractPort* tInterfaceBase::tBackend::CreatePort(const core::tAbstractPortCreationInfo& creation_info, int primary_relation_id) const 
    406409{ 
    407   return cMODIFIER_DEFAULT_IMPLEMENTATION.CreatePort(creation_info, primary_relation_id); 
     410  auto modifier = GetModifier(*creation_info.parent); 
     411  return (modifier ? modifier->Implementation() : cMODIFIER_DEFAULT_IMPLEMENTATION).CreatePort(creation_info, primary_relation_id); 
    408412} 
    409413 
     
    463467 
    464468    const core::tFrameworkElementFlags relevant_flags = tFlag::SENSOR_DATA | tFlag::CONTROLLER_DATA | tFlag::INTERFACE_FOR_INPUTS | tFlag::INTERFACE_FOR_OUTPUTS | tFlag::PROXY_INTERFACE | tFlag::PARAMETER_INTERFACE; 
    465     tInterfaceModifier* interface_modifier = component_interface->GetParent()->GetAnnotation<tInterfaceModifier>(); 
     469    tInterfaceModifier* interface_modifier = GetModifier(*component_interface); 
    466470 
    467471    // Compute opcode sequence 
     
    580584      } 
    581585 
    582       if ((!new_candidate) && ((this->IsPartialInterface() && remaining_relations) || interface_modifier)) 
     586      if ((!new_candidate) && this->IsPartialInterface() && remaining_relations) 
    583587      { 
    584588        use_these_original_flags = target_set_flags; 
     
    591595      { 
    592596        new_candidate = (*create_missing_component_interface_function)(component_interface->GetParent(), target_set_flags); 
     597      } 
     598 
     599      if ((!new_candidate) && interface_modifier) 
     600      { 
     601        use_these_original_flags = target_set_flags; 
     602        parent_candidate = nullptr; 
     603        continue; 
    593604      } 
    594605 
  • tInterfaceModifier.h

    r23 r26  
    8787     * \param default_component_interface Component interface below which interface element would be created by default 
    8888     * \param primary_relation_id Primary relation ID, as used in interface classes (zero is primary port type) 
    89      * \return Return Component interface below which interface element should be created. Return nullptr will not create element. 
     89     * \return Return Component interface below which interface element should be created. Returning nullptr will not create element. 
    9090     */ 
    9191    virtual core::tPortGroup* GetComponentInterface(core::tPortGroup* default_component_interface, int primary_relation_id) const 
     
    102102     * \param creation_info Creation info that would be used in default implementation to create port 
    103103     * \param primary_relation_id Primary relation ID, as used in interface classes (zero is primary port type) 
     104     * \return Created port. nullptr if no port is to be created. 
    104105     */ 
    105106    virtual core::tAbstractPort* CreatePort(const core::tAbstractPortCreationInfo& creation_info, int primary_relation_id) const 
Note: See TracChangeset for help on using the changeset viewer.