Changeset 11:ca584c3bd2d4 in finroc_plugins_composite_ports


Ignore:
Timestamp:
26.03.2020 15:25:43 (12 months ago)
Author:
Max Reichardt <max.reichardt@…>
Branch:
default
Phase:
public
Message:

Adds another auto-connect function for convenience (ConnectUnconnectedMatchingInterfaces)

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • auto_connect.cpp

    r0 r11  
    3333// External includes (system with <>, local with "") 
    3434//---------------------------------------------------------------------- 
     35#include "rrlib/rtti_conversion/tStaticCastOperation.h" 
    3536 
    3637//---------------------------------------------------------------------- 
     
    137138} 
    138139 
     140void ConnectUnconnectedMatchingInterfaces(core::tPortGroup& source_component_interface, core::tPortGroup& destination_component_interface, bool connect_derived_interfaces) 
     141{ 
     142  for (auto destination_port = destination_component_interface.ChildPortsBegin(); destination_port != destination_component_interface.ChildPortsEnd(); ++destination_port) 
     143  { 
     144    if (destination_port->IsReady() && destination_port->GetDataType().GetTypeClassification() == rrlib::rtti::tTypeClassification::PORT_COMPOSITE_INTERFACE && destination_port->CountIncomingConnections() == 0) 
     145    { 
     146      for (auto source_port = source_component_interface.ChildPortsBegin(); source_port != source_component_interface.ChildPortsEnd(); ++source_port) 
     147      { 
     148        if (source_port->IsReady() && source_port->GetDataType().GetTypeClassification() == rrlib::rtti::tTypeClassification::PORT_COMPOSITE_INTERFACE && (source_port->GetDataType() == destination_port->GetDataType() || (connect_derived_interfaces && rrlib::rtti::conversion::tStaticCastOperation::IsImplicitlyConvertibleTo(source_port->GetDataType(), destination_port->GetDataType())))) 
     149        { 
     150          bool already_connected = false; 
     151          for (auto connector = source_port->OutgoingConnectionsBegin(); connector != source_port->OutgoingConnectionsEnd(); ++connector) 
     152          { 
     153            auto aggregator = core::tEdgeAggregator::GetAggregator(connector->Destination()); 
     154            if (aggregator == &destination_component_interface) 
     155            { 
     156              already_connected = true; 
     157              break; 
     158            } 
     159          } 
     160          if (!already_connected) 
     161          { 
     162            source_port->ConnectTo(*destination_port); 
     163          } 
     164        } 
     165      } 
     166    } 
     167  } 
     168} 
     169 
     170 
    139171//---------------------------------------------------------------------- 
    140172// End of namespace declaration 
  • auto_connect.h

    r0 r11  
    3636// External includes (system with <>, local with "") 
    3737//---------------------------------------------------------------------- 
     38#include "core/port/tPortGroup.h" 
    3839 
    3940//---------------------------------------------------------------------- 
     
    7172 */ 
    7273template <typename TComponent, typename TInterface> 
    73 static std::string ConnectChildComponentInterfaces(TComponent& composite_component, std::vector<TInterface>& interfaces_variable, const std::string& common_prefix, size_t start_index = 1, const std::string& common_postfix = ""); 
     74std::string ConnectChildComponentInterfaces(TComponent& composite_component, std::vector<TInterface>& interfaces_variable, const std::string& common_prefix, size_t start_index = 1, const std::string& common_postfix = ""); 
    7475 
    7576/*! 
     
    8182 */ 
    8283template <typename TComponent, typename TInterface> 
    83 static void ConnectFirstChildComponentInterface(TComponent& composite_component, TInterface& interface); 
     84void ConnectFirstChildComponentInterface(TComponent& composite_component, TInterface& interface); 
    8485 
     86/*! 
     87 * Connects unconnected port composite interfaces in destination component interface with any matching 
     88 * component interfaces found in source. 
     89 * This function does not connect interfaces in source that are already connected to destination. 
     90 * 
     91 * \param source_component_interface Component interface with outgoing data flow 
     92 * \param destination_component_interface Component interface with incoming data flow 
     93 * \param connect_derived_interfaces Whether to connect sub- and superclass port composite interfaces 
     94 */ 
     95void ConnectUnconnectedMatchingInterfaces(core::tPortGroup& source_component_interface, core::tPortGroup& destination_component_interface, bool connect_derived_interfaces = false); 
    8596 
    8697//---------------------------------------------------------------------- 
Note: See TracChangeset for help on using the changeset viewer.