Changeset 484:1a2da4a0243c in finroc_core


Ignore:
Timestamp:
20.03.2021 11:35:42 (5 weeks ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
17.03
Phase:
public
Tags:
tip
Message:

Adds scoped port factories (only handle port creation below the specified framework element)

Location:
port
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • port/tPortFactory.cpp

    r362 r484  
    6666// Implementation 
    6767//---------------------------------------------------------------------- 
     68 
     69namespace 
     70{ 
     71 
    6872/*! 
    6973 * \return List of all available port factories 
     
    7579} 
    7680 
     81class tFactoryAnnotation : public core::tAnnotation 
     82{ 
     83public: 
     84 
     85  tFactoryAnnotation(tPortFactory& factory) : 
     86    factory(factory) 
     87  {} 
     88 
     89  tPortFactory& factory; 
     90}; 
     91 
     92} 
     93 
     94 
    7795tPortFactory::tPortFactory() 
    7896{ 
     
    8098} 
    8199 
     100tPortFactory::tPortFactory(core::tFrameworkElement* handles_elements_below) 
     101{ 
     102  if (handles_elements_below) 
     103  { 
     104    handles_elements_below->EmplaceAnnotation<tFactoryAnnotation>(*this); 
     105  } 
     106} 
     107 
    82108tAbstractPort* tPortFactory::CreatePort(const std::string& port_name, tFrameworkElement& parent, const rrlib::rtti::tType& dt, tFrameworkElement::tFlags flags) 
    83109{ 
     110  { 
     111    auto check_element_for_attached_factory = &parent; 
     112    while (check_element_for_attached_factory) 
     113    { 
     114      auto annotation = check_element_for_attached_factory->GetAnnotation<tFactoryAnnotation>(); 
     115      if (annotation && annotation->factory.HandlesDataType(dt)) 
     116      { 
     117        return &annotation->factory.CreatePortImplementation(port_name, parent, dt, flags); 
     118      } 
     119      check_element_for_attached_factory = check_element_for_attached_factory->GetParent(); 
     120    } 
     121  } 
     122 
    84123  std::vector<tPortFactory*>& list = FactoryList(); 
    85124  for (auto it = list.begin(); it != list.end(); ++it) 
  • port/tPortFactory.h

    r447 r484  
    8585 
    8686  /*! 
     87   * Creates factory that handles only port creation below the specified element 
     88   * 
     89   * \param handles_elements_below Framework element that this factory is attached to (inactive/unused if nullptr) 
     90   */ 
     91  tPortFactory(core::tFrameworkElement* handles_elements_below); 
     92 
     93 
     94  /*! 
    8795   * External interface for anyone who wants to create a port of specified type. 
    8896   * For RPC types this will create routing ports only. 
Note: See TracChangeset for help on using the changeset viewer.