Changeset 13:dbd30988fdb1 in finroc_plugins_composite_ports


Ignore:
Timestamp:
30.04.2020 17:29:13 (3 years ago)
Author:
Max Reichardt <max.reichardt@…>
Branch:
default
Phase:
public
Message:

Adds convenience method tInterfaceBase::FindInterfacesBelow

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tInterfaceBase.cpp

    r10 r13  
    3636#include "core/tRuntimeEnvironment.h" 
    3737#include "rrlib/util/string.h" 
     38#include "rrlib/rtti_conversion/tStaticCastOperation.h" 
    3839 
    3940//---------------------------------------------------------------------- 
     
    132133//} 
    133134 
     135void FindInterfacesBelowImplementation(std::vector<tInterfaceBase>& result, core::tFrameworkElement& parent, const rrlib::rtti::tType& type, bool skip_derived_interfaces) 
     136{ 
     137  for (auto it = parent.ChildrenBegin(); it != parent.ChildrenEnd(); ++it) 
     138  { 
     139    bool is_backend = typeid(*it) == typeid(tInterfaceBase::tBackend); 
     140    if (is_backend) 
     141    { 
     142      tInterfaceBase::tBackend& candidate = static_cast<tInterfaceBase::tBackend&>(*it); 
     143      if (candidate.IsPrimaryBackend() && (candidate.GetDataType() == type || ((!skip_derived_interfaces) && rrlib::rtti::conversion::tStaticCastOperation::IsImplicitlyConvertibleTo(candidate.GetDataType(), type)))) 
     144      { 
     145        result.emplace_back(&candidate); 
     146        continue; 
     147      } 
     148    } 
     149    if ((!it->IsPort()) || is_backend) 
     150    { 
     151      FindInterfacesBelowImplementation(result, *it, type, skip_derived_interfaces); 
     152    } 
     153  } 
     154} 
     155 
    134156} 
    135157 
     
    182204    } 
    183205  } 
     206} 
     207 
     208std::vector<tInterfaceBase> tInterfaceBase::FindInterfacesBelow(core::tFrameworkElement& parent, const rrlib::rtti::tType& type, bool skip_derived_interfaces) 
     209{ 
     210  std::vector<tInterfaceBase> result; 
     211  if (type.GetTypeClassification() == rrlib::rtti::tTypeClassification::PORT_COMPOSITE_INTERFACE) 
     212  { 
     213    FindInterfacesBelowImplementation(result, parent, type, skip_derived_interfaces); 
     214  } 
     215  return result; 
    184216} 
    185217 
  • tInterfaceBase.h

    r8 r13  
    122122    return static_cast<tBackend*>(this->GetWrapped()); 
    123123  } 
     124 
     125  /*! 
     126   * Searches for interfaces of specified type below parent element. 
     127   * 
     128   * \param parent Parent element below which to search for interface 
     129   * \param type Type of interface to search for 
     130   * \param skip_derived_interfaces By default subclasses of interfaces are also included. They are skipped if this parameter is true. 
     131   * \return Any interfaces found. Returns empty vector if type is not an interface type. 
     132   */ 
     133  static std::vector<tInterfaceBase> FindInterfacesBelow(core::tFrameworkElement& parent, const rrlib::rtti::tType& type, bool skip_derived_interfaces = false); 
    124134 
    125135  /*! 
Note: See TracChangeset for help on using the changeset viewer.