Changeset 19:d53a682e5e97 in finroc_plugins_composite_ports


Ignore:
Timestamp:
25.08.2020 15:54:56 (17 months ago)
Author:
Max Reichardt <max.reichardt@…>
Branch:
default
Phase:
public
Message:

Adds option to instantiate only one half of a nested interface

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • tInterface.h

    r17 r19  
    153153   * \param custom_connect_function Custom connect function for this interface 
    154154   */ 
    155   template <typename TParent, bool Tenable = std::is_base_of<tInterfaceBase, typename std::decay<TParent>::type>::value> 
     155  template < typename TParent, bool Tenable = std::is_base_of<tInterfaceBase, typename std::decay<TParent>::type>::value || std::is_base_of<tInterfaceBase::tBackend, typename std::decay<TParent>::type>::value > 
    156156  tInterface(typename std::enable_if<Tenable, const rrlib::rtti::tType&>::type interface_type, TParent* parent, const std::string& name, tPrimaryPortType primary_port_type = tPrimaryPortType::ANY, const tConnectFunction& custom_connect_function = tConnectFunction()) : 
    157     tInterfaceBase(CreateBackend(interface_type, *parent, name, primary_port_type, custom_connect_function)) 
     157    tInterfaceBase(tBase::CreateBackend(interface_type, parent, name, primary_port_type, custom_connect_function, cPRIMARY_RELATION_ID, cCONVENIENCE_PORT)) 
    158158  { 
    159159  } 
     
    192192  } 
    193193 
    194   static tBackend* CreateBackend(rrlib::rtti::tType interface_type, tInterfaceBase& parent, const std::string& name, tPrimaryPortType primary_port_type, const tConnectFunction& custom_connect_function) 
    195   { 
    196     if (parent.Backend() == nullptr) 
    197     { 
    198       return nullptr; 
    199     } 
    200     tBackend* parent_backend = parent.Backend()->GetBackend(cPRIMARY_RELATION_ID); 
    201     bool partial_interface = false; 
    202     assert(parent_backend || parent.Backend()->IsPartialInterface()); 
    203     if (!parent_backend) 
    204     { 
    205       const internal::tInterfaceTypeInfo& info = static_cast<const internal::tInterfaceTypeInfo&>(interface_type.SharedTypeInfo()); 
    206       interface_type = info.GetPartialType(); 
    207       partial_interface = interface_type && primary_port_type != tPrimaryPortType::ANY; 
    208       if (partial_interface) 
    209       { 
    210         parent_backend = parent.Backend(); 
    211       } 
    212     } 
    213     return parent_backend ? new tInterfaceBase::tBackend(interface_type, cCONVENIENCE_PORT ? parent.ParentComponent() : parent.Backend(), parent_backend, cPRIMARY_RELATION_ID, name, cCONVENIENCE_PORT, custom_connect_function, nullptr, parent.Backend()->PrimaryPortType(), partial_interface) : nullptr; 
    214   } 
    215  
    216194}; 
    217195 
  • tInterfaceBase.cpp

    r17 r19  
    213213} 
    214214 
     215tInterfaceBase::tBackend* tInterfaceBase::CreateBackend(rrlib::rtti::tType interface_type, tInterfaceBase* parent, const std::string& name, tPrimaryPortType primary_port_type, const tConnectFunction& custom_connect_function, int primary_relation_id, bool convience_port_type) 
     216{ 
     217  assert(parent); 
     218  if (parent->Backend() == nullptr) 
     219  { 
     220    return nullptr; 
     221  } 
     222  tBackend* parent_backend = parent->Backend()->GetBackend(primary_relation_id); 
     223  bool partial_interface = false; 
     224  assert(parent_backend || parent->Backend()->IsPartialInterface()); 
     225  if (!parent_backend) 
     226  { 
     227    const internal::tInterfaceTypeInfo& info = static_cast<const internal::tInterfaceTypeInfo&>(interface_type.SharedTypeInfo()); 
     228    interface_type = info.GetPartialType(); 
     229    partial_interface = interface_type && primary_port_type != tPrimaryPortType::ANY; 
     230    if (partial_interface) 
     231    { 
     232      parent_backend = parent->Backend(); 
     233    } 
     234  } 
     235  return parent_backend ? new tInterfaceBase::tBackend(interface_type, convience_port_type ? parent->ParentComponent() : parent->Backend(), parent_backend, primary_relation_id, name, convience_port_type, custom_connect_function, nullptr, parent->Backend()->PrimaryPortType(), partial_interface) : nullptr; 
     236} 
     237 
     238tInterfaceBase::tBackend* tInterfaceBase::CreateBackend(rrlib::rtti::tType interface_type, tInterfaceBase::tBackend* parent, const std::string& name, tPrimaryPortType primary_port_type, const tConnectFunction& custom_connect_function, int primary_relation_id, bool convience_port_type) 
     239{ 
     240  const internal::tInterfaceTypeInfo& info = static_cast<const internal::tInterfaceTypeInfo&>(interface_type.SharedTypeInfo()); 
     241  return parent ? new tInterfaceBase::tBackend(info.GetPartialType(), convience_port_type ? parent->parent_component : parent, parent, primary_relation_id, name, convience_port_type, custom_connect_function, nullptr, parent->PrimaryPortType(), true) : nullptr; 
     242} 
     243 
    215244 
    216245tInterfaceBase::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) : 
     
    327356  core::tFrameworkElement* parent = nullptr; 
    328357  bool do_not_create_primary_port_type = relation_backend_mapping.front().second == nullptr; 
    329   bool partial_interface_direction_is_output = this->GetParent()->GetFlag(tFlag::INTERFACE_FOR_OUTPUTS); 
     358  bool partial_interface_direction_is_output = GetAggregator(*this)->GetFlag(tFlag::INTERFACE_FOR_OUTPUTS); 
    330359  bool partial_interface_primary_relation_direction_is_output = !partial_interface_direction_is_output; 
    331360  if (GetParent() && typeid(*GetParent()).name() == typeid(tBackend).name()) 
     
    495524  if (parent && partial_interface) 
    496525  { 
    497     if ((partial_interface_direction_is_output && parent->GetFlag(tFlag::INTERFACE_FOR_INPUTS)) || ((!partial_interface_direction_is_output) && parent->GetFlag(tFlag::INTERFACE_FOR_OUTPUTS))) 
     526    auto aggregator = GetAggregator(*parent); 
     527    if ((partial_interface_direction_is_output && aggregator->GetFlag(tFlag::INTERFACE_FOR_INPUTS)) || ((!partial_interface_direction_is_output) && aggregator->GetFlag(tFlag::INTERFACE_FOR_OUTPUTS))) 
    498528    { 
    499529      parent = nullptr; 
  • tInterfaceBase.h

    r18 r19  
    354354protected: 
    355355 
     356  static tBackend* CreateBackend(rrlib::rtti::tType interface_type, tInterfaceBase* parent, const std::string& name, tPrimaryPortType primary_port_type, const tConnectFunction& custom_connect_function, int primary_relation_id, bool convience_port_type); 
     357  static tBackend* CreateBackend(rrlib::rtti::tType interface_type, tInterfaceBase::tBackend* parent, const std::string& name, tPrimaryPortType primary_port_type, const tConnectFunction& custom_connect_function, int primary_relation_id, bool convience_port_type); 
     358 
    356359  /*! 
    357360   * \return Parent as passed to tInterface constructor (typically component) 
Note: See TracChangeset for help on using the changeset viewer.