Changeset 119:f7a4f44a0789 in finroc_plugins_data_ports


Ignore:
Timestamp:
11.08.2017 19:19:25 (2 years ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
17.03
Phase:
public
Message:

Makes port classes of fundamental/numeric C++ type no longer use tNumber as buffer type in backend (this is no longer needed with type casting - and simplifies code)

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • api/tBoundedPort.h

    r101 r119  
    7474class tBoundedPort : public std::conditional<definitions::cSINGLE_THREADED, api::tSingleThreadedCheapCopyPort<T>, optimized::tCheapCopyPort>::type 
    7575{ 
    76   static_assert((!std::is_integral<T>::value) || TYPE == tPortImplementationType::NUMERIC || definitions::cSINGLE_THREADED, "Type must be numeric for numeric type"); 
    77  
    78   typedef typename std::conditional<TYPE == tPortImplementationType::NUMERIC, numeric::tNumber, T>::type tBufferType; 
    7976  typedef tPortImplementation<T, TYPE> tImplementationVariation; 
    8077  typedef typename std::conditional<definitions::cSINGLE_THREADED, api::tSingleThreadedCheapCopyPort<T>, optimized::tCheapCopyPort>::type tPortBase; 
     
    114111    bounds = new_bounds; 
    115112#ifndef RRLIB_SINGLE_THREADED 
    116     tBufferType value_buffer = tBufferType(); 
    117     this->CopyCurrentValue(value_buffer, tStrategy::NEVER_PULL); 
    118     T value = tImplementationVariation::ToValue(value_buffer); 
     113    T value = T(); 
     114    this->CopyCurrentValue(value, tStrategy::NEVER_PULL); 
    119115    if (!bounds.InBounds(value)) 
    120116    { 
    121117      typename tPortBase::tUnusedManagerPointer new_buffer(optimized::tGlobalBufferPools::Instance().GetUnusedBuffer(this->GetCheaplyCopyableTypeIndex()).release()); 
    122       tImplementationVariation::Assign(new_buffer->GetObject().template GetData<tBufferType>(), bounds.GetOutOfBoundsDefault()); 
     118      tImplementationVariation::Assign(new_buffer->GetObject().template GetData<T>(), bounds.GetOutOfBoundsDefault()); 
    123119      this->BrowserPublishRaw(new_buffer); // If port is already connected, could this have undesirable side-effects? (I do not think so - otherwise we need to do something more sophisticated here) 
    124120    } 
     
    158154      return "Buffer has wrong type"; 
    159155    } 
    160     const tBufferType& value_buffer = buffer->GetObject().template GetData<tBufferType>(); 
    161     T value = tImplementationVariation::ToValue(value_buffer); 
     156    const T& value = buffer->GetObject().template GetData<T>(); 
    162157    if (!bounds.InBounds(value)) 
    163158    { 
     
    218213  bool NonStandardAssignImplementation(TPublishingData& publishing_data, tChangeStatus change_constant) 
    219214  { 
    220     const tBufferType& value_buffer = publishing_data.published_buffer->GetObject().template GetData<tBufferType>(); 
    221     T value = tImplementationVariation::ToValue(value_buffer); 
     215    const T& value = publishing_data.published_buffer->GetObject().template GetData<T>(); 
    222216    if (!bounds.InBounds(value)) 
    223217    { 
     
    229223      typename tPortBase::tUnusedManagerPointer buffer = this->GetUnusedBuffer(publishing_data); 
    230224      publishing_data.Init(buffer); 
    231       tImplementationVariation::Assign(publishing_data.published_buffer->GetObject().template GetData<tBufferType>(), 
    232                                        bounds.GetOutOfBoundsAction() == tOutOfBoundsAction::ADJUST_TO_RANGE ? bounds.ToBounds(value) : bounds.GetOutOfBoundsDefault()); 
     225      publishing_data.published_buffer->GetObject().template GetData<T>() = bounds.GetOutOfBoundsAction() == tOutOfBoundsAction::ADJUST_TO_RANGE ? bounds.ToBounds(value) : bounds.GetOutOfBoundsDefault(); 
    233226      publishing_data.published_buffer->SetTimestamp(timestamp); 
    234227    } 
  • api/tGenericPortImplementation.h

    r114 r119  
    140140   * Buffers to be published using this port should be acquired using this function. 
    141141   * The buffer might contain old data, so it should be cleared prior to using. 
    142    * 
    143    * Note: The returned buffer is always of the port's actual buffer type (e.g. no int, double etc. - but tNumber) 
    144142   */ 
    145143  inline tPortDataPointer<rrlib::rtti::tGenericObject> GetUnusedBuffer(core::tAbstractPort& port) 
  • api/tPortImplementation.h

    r114 r119  
    138138}; 
    139139 
    140 // numeric cheap-copy implementation 
    141 template <typename T> 
    142 struct tCheapCopyPortImplementation<T, tPortImplementationType::NUMERIC> : 
    143   public tCheapCopyPortBaseImplementation<T, numeric::tNumber, tPortImplementationType::NUMERIC, true> 
    144 { 
    145   typedef numeric::tNumber tPortBuffer; 
    146  
    147   static inline void Assign(numeric::tNumber& buffer, T value) 
    148   { 
    149     buffer.SetValue(value); 
    150   } 
    151  
    152   static inline T ToValue(const numeric::tNumber& value) 
    153   { 
    154     return value.Value<T>(); 
    155   } 
    156 }; 
    157  
    158 // tNumber cheap-copy implementation 
    159 template <> 
    160 struct tCheapCopyPortImplementation<numeric::tNumber, tPortImplementationType::NUMERIC> : 
    161   public tCheapCopyPortBaseImplementation<numeric::tNumber, numeric::tNumber, tPortImplementationType::CHEAP_COPY, true> 
    162 { 
    163   typedef numeric::tNumber tPortBuffer; 
    164  
    165   static inline void Assign(numeric::tNumber& buffer, const numeric::tNumber value) 
    166   { 
    167     buffer = value; 
    168   } 
    169  
    170   static inline numeric::tNumber ToValue(const numeric::tNumber& value) 
    171   { 
    172     return value; 
    173   } 
    174 }; 
    175  
    176140// implementation for all type handled by tCheapCopyPort port implementation 
    177141template <typename T, tPortImplementationType TYPE> 
  • api/tPortImplementationTypeTrait.h

    r69 r119  
    6767  STANDARD, 
    6868  CHEAP_COPY, 
    69   NUMERIC, 
    7069  CHEAP_COPY_SINGLE_THREADED 
    7170}; 
     
    8281{ 
    8382  /*! Port implementation to use */ 
    84   static const tPortImplementationType type = (IsNumeric<T>::value && (!definitions::cSINGLE_THREADED)) ? tPortImplementationType::NUMERIC : 
    85       (tIsCheaplyCopiedType<T>::value ? (definitions::cSINGLE_THREADED ? tPortImplementationType::CHEAP_COPY_SINGLE_THREADED : 
    86                                          tPortImplementationType::CHEAP_COPY) : tPortImplementationType::STANDARD); 
     83  static const tPortImplementationType type = tIsCheaplyCopiedType<T>::value ? (definitions::cSINGLE_THREADED ? tPortImplementationType::CHEAP_COPY_SINGLE_THREADED : 
     84      tPortImplementationType::CHEAP_COPY) : tPortImplementationType::STANDARD; 
    8785}; 
    8886 
  • common/tConversionConnector.cpp

    r107 r119  
    7575{ 
    7676  static_assert(sizeof(destination_port_generic_memory) == sizeof(tGenericPort), "Adjust array size"); 
    77   tGenericPort destination_port_generic = tGenericPort::Wrap(destination_port, true); 
     77  tGenericPort destination_port_generic = tGenericPort::Wrap(destination_port); 
    7878  memcpy(destination_port_generic_memory, &destination_port_generic, sizeof(tGenericPort)); 
    7979} 
  • tGenericPort.h

    r107 r119  
    124124   * 
    125125   * (It's preferred to add listeners before port is initialized) 
    126    * (Note: Buffer in 'value' always has data type of port backend (e.g. tNumber instead of double) 
    127126   */ 
    128127  template <typename TListener> 
     
    136135   * 
    137136   * (It's preferred to add listeners before port is initialized) 
    138    * (Note: Buffer in 'value' always has data type of port backend (e.g. tNumber instead of double) 
    139137   */ 
    140138  template <typename TListener> 
     
    224222   * \return Buffer with port's current value with read lock. 
    225223   * 
    226    * Note: Buffer always has data type of port backend (e.g. tNumber instead of double) 
    227224   * If this is not desired, use pass-by-value-Get Operation above. 
    228225   */ 
     
    241238 
    242239  /*! 
    243    * Note: Buffer always has data type of port backend (e.g. tNumber instead of double) 
    244240   * If this is not desired, use pass-by-value-Publish Operation below. 
    245241   * 
     
    317313   * 
    318314   * \param wrap Type-less tAbstractPort to wrap as tGenericPort 
    319    * \param use_backend_type_only Use only the internal data type that used in the port backend? (e.g. tNumber instead of double; relevant e.g. for Get() and Publish() methods) 
    320    */ 
    321   static tGenericPort Wrap(core::tAbstractPort& wrap, bool use_backend_type_only = false) 
     315   */ 
     316  static tGenericPort Wrap(core::tAbstractPort& wrap) 
    322317  { 
    323318    if (!IsDataFlowType(wrap.GetDataType())) 
     
    327322    tGenericPort port; 
    328323    port.SetWrapped(&wrap); 
    329     port.implementation = api::tGenericPortImplementation::GetImplementation( 
    330                             ((!use_backend_type_only) && wrap.GetWrapperDataType()) ? wrap.GetWrapperDataType() : wrap.GetDataType()); 
     324    port.implementation = api::tGenericPortImplementation::GetImplementation(wrap.GetDataType()); 
    331325    return port; 
    332326  } 
     327 
     328  static tGenericPort Wrap(core::tAbstractPort& wrap, bool unused) __attribute__((deprecated)) 
     329  { 
     330    return Wrap(wrap); 
     331  } 
     332 
    333333 
    334334//---------------------------------------------------------------------- 
  • tPort.h

    r107 r119  
    140140    { 
    141141      SetWrapped(tImplementation::CreatePort(creation_info)); 
    142       GetWrapped()->SetWrapperDataType(rrlib::rtti::tDataType<T>()); 
    143142      if (creation_info.DefaultValueSet()) 
    144143      { 
Note: See TracChangeset for help on using the changeset viewer.