Changeset 94:4374ed7c8735 in finroc_plugins_data_ports


Ignore:
Timestamp:
08.02.2015 10:01:48 (4 years ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Phase:
public
Message:

Added ApplyDefault() method to tGenericPort

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tGenericPort.h

    r78 r94  
    4848//---------------------------------------------------------------------- 
    4949#include "plugins/data_ports/api/tGenericPortImplementation.h" 
     50#include "plugins/data_ports/tEvent.h" 
    5051 
    5152//---------------------------------------------------------------------- 
     
    153154 
    154155  /*! 
     156   * Apply default value to port 
     157   * (not particularly efficient) 
     158   * 
     159   * apply_type_default_if_no_port_default_defined If no default value was set in constructor, use default of data type? (otherwise prints a warning) 
     160   */ 
     161  void ApplyDefault(bool apply_type_default_if_no_port_default_defined) 
     162  { 
     163    if (GetDefaultValue() || (!apply_type_default_if_no_port_default_defined)) 
     164    { 
     165      static_cast<common::tAbstractDataPort&>(*GetWrapped()).ApplyDefaultValue(); 
     166    } 
     167    else 
     168    { 
     169      tPortDataPointer<rrlib::rtti::tGenericObject> buffer = GetUnusedBuffer(); 
     170      std::unique_ptr<rrlib::rtti::tGenericObject> default_buffer(buffer->GetType().CreateInstanceGeneric()); 
     171      buffer->DeepCopyFrom(*default_buffer); 
     172      BrowserPublish(buffer); 
     173    } 
     174  } 
     175 
     176  /*! 
    155177   * Publish buffer through port 
    156178   * (not in normal operation, but from browser; difference: listeners on this port will be notified) 
Note: See TracChangeset for help on using the changeset viewer.