Changeset 176:57957d1c76ae in finroc_plugins_data_ports


Ignore:
Timestamp:
12.03.2021 00:41:47 (6 weeks ago)
Author:
Max Reichardt <max.reichardt@…>
Branch:
17.03
Phase:
public
Message:

Moves CaptureAllMetadata function to tMetadataStack - together with minor adjustments for integration into finroc components

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • metadata/tMetadataStack.cpp

    r174 r176  
    3737// Internal includes with "" 
    3838//---------------------------------------------------------------------- 
     39#include "plugins/data_ports/tMetadata.h" 
    3940 
    4041//---------------------------------------------------------------------- 
     
    7980} 
    8081 
     82void tMetadataStack::CaptureAllMetadata(tMetadata& destination) 
     83{ 
     84  size_t stack_size = metadata::tMetadataStack::Size(); 
     85  if (!stack_size) 
     86  { 
     87    destination = tMetadata(); 
     88  } 
     89  else 
     90  { 
     91    void* pointers_memory[stack_size * sizeof(rrlib::rtti::tTypedPointer) / sizeof(void*)]; 
     92    memset(pointers_memory, 0, sizeof(pointers_memory)); 
     93    rrlib::rtti::tTypedConstPointer* pointers = reinterpret_cast<rrlib::rtti::tTypedConstPointer*>(pointers_memory); 
     94    auto current_pointer = pointers; 
     95    for (auto it = metadata::tMetadataStack::Begin(); it != metadata::tMetadataStack::End(); ++it, ++current_pointer) 
     96    { 
     97      assert(current_pointer - pointers < static_cast<long int>(stack_size)); 
     98      *current_pointer = *it; 
     99    } 
     100    assert(current_pointer == pointers + stack_size); 
     101    destination.CopyFrom(tMetadata::tElementRange(pointers, current_pointer)); 
     102  } 
     103} 
     104 
    81105//---------------------------------------------------------------------- 
    82106// End of namespace declaration 
  • metadata/tMetadataStack.h

    r174 r176  
    5555namespace data_ports 
    5656{ 
     57 
     58//---------------------------------------------------------------------- 
     59// Forward declarations / typedefs / enums 
     60//---------------------------------------------------------------------- 
     61 
     62class tMetadata; 
     63 
    5764namespace metadata 
    5865{ 
    59  
    60 //---------------------------------------------------------------------- 
    61 // Forward declarations / typedefs / enums 
    62 //---------------------------------------------------------------------- 
    6366 
    6467//---------------------------------------------------------------------- 
     
    7881public: 
    7982 
    80   typedef rrlib::rtti::tTypedConstPointer* tIterator; 
    81   typedef rrlib::util::tIteratorRange<rrlib::rtti::tTypedConstPointer*> tElementRange; 
     83  typedef const rrlib::rtti::tTypedConstPointer* tIterator; 
     84  typedef rrlib::util::tIteratorRange<const rrlib::rtti::tTypedConstPointer*> tElementRange; 
    8285  class tConstIterator; 
    8386 
     
    8992      tScopedContext(elements.End() - elements.Begin()), 
    9093      elements(elements), 
    91       first_entry(ParentContext() && typeid(*ParentContext()) == typeid(tScopedEntry) ? static_cast<tScopedEntry*>(ParentContext())->first_entry : this), 
     94      first_entry(IsScopedEntry(ParentContext()) ? static_cast<tScopedEntry*>(ParentContext())->first_entry : this), 
    9295      total_elements((elements.End() - elements.Begin()) + (first_entry != this ? static_cast<tScopedEntry*>(ParentContext())->total_elements : 0)), 
    9396      next_entry(nullptr) 
     
    112115    uint total_elements; 
    113116    tScopedEntry* next_entry; 
     117 
     118    static bool IsScopedEntry(common::tScopedContext* context) 
     119    { 
     120      return context && typeid(*context) == typeid(tScopedEntry); 
     121    } 
    114122  }; 
    115123 
     
    199207  } 
    200208 
     209  /*! 
     210   * Copies all meta data currently on stack to provided object 
     211   * 
     212   * \param destination Destination object. Will contain the meta data currently on stack after function call. 
     213   */ 
     214  static void CaptureAllMetadata(tMetadata& destination); 
     215 
    201216//---------------------------------------------------------------------- 
    202217// Private fields and methods 
  • metadata/tScopedMetadataGeneric.h

    r174 r176  
    7070class tScopedMetadataGeneric : public rrlib::util::tNoncopyable 
    7171{ 
    72   typedef rrlib::rtti::tTypedConstPointer* tIterator; 
    73   typedef rrlib::util::tIteratorRange<rrlib::rtti::tTypedConstPointer*> tElementRange; 
     72  typedef const rrlib::rtti::tTypedConstPointer* tIterator; 
     73  typedef rrlib::util::tIteratorRange<const rrlib::rtti::tTypedConstPointer*> tElementRange; 
    7474 
    7575//---------------------------------------------------------------------- 
  • tMetadata.cpp

    r174 r176  
    9191rrlib::rtti::tDataType<tMetadata> cMETA_DATA_TYPE; 
    9292 
    93 void CaptureAllMetadata(tMetadata& destination) 
    94 { 
    95   size_t stack_size = metadata::tMetadataStack::Size(); 
    96   if (!stack_size) 
    97   { 
    98     destination = tMetadata(); 
    99   } 
    100   else 
    101   { 
    102     void* pointers_memory[stack_size * sizeof(rrlib::rtti::tTypedPointer) / sizeof(void*)]; 
    103     memset(pointers_memory, 0, sizeof(pointers_memory)); 
    104     rrlib::rtti::tTypedConstPointer* pointers = reinterpret_cast<rrlib::rtti::tTypedConstPointer*>(pointers_memory); 
    105     auto current_pointer = pointers; 
    106     for (auto it = metadata::tMetadataStack::Begin(); it != metadata::tMetadataStack::End(); ++it, ++current_pointer) 
    107     { 
    108       assert(current_pointer - pointers < static_cast<long int>(stack_size)); 
    109       *current_pointer = *it; 
    110     } 
    111     assert(current_pointer == pointers + stack_size); 
    112     destination.CopyFrom(tMetadata::tElementRange(pointers, current_pointer)); 
    113   } 
    114 } 
    115  
    11693void CaptureSingleMetadata(const rrlib::rtti::tTypedPointer& destination) 
    11794{ 
     
    184161    size_t meta_data_offset = operation.GetCustomData().Get<tMetadataConversionOperationData>().metadata_offset; 
    185162    rrlib::rtti::tTypedPointer meta_data_destination(static_cast<char*>(destination_object.GetRawDataPointer()) + meta_data_offset, cMETA_DATA_TYPE); 
    186     CaptureAllMetadata(*meta_data_destination.Get<tMetadata>()); 
     163    metadata::tMetadataStack::CaptureAllMetadata(*meta_data_destination.Get<tMetadata>()); 
    187164  } 
    188165 
     
    236213  { 
    237214    tMetadata intermediate; 
    238     CaptureAllMetadata(intermediate); 
     215    metadata::tMetadataStack::CaptureAllMetadata(intermediate); 
    239216    operation.Continue(rrlib::rtti::tTypedConstPointer(&intermediate), destination_object); 
    240217  } 
     
    242219  static void FinalConversionFunctionAll(const rrlib::rtti::tTypedConstPointer& source_object, const rrlib::rtti::tTypedPointer& destination_object, const rrlib::rtti::conversion::tCurrentConversionOperation& operation) 
    243220  { 
    244     CaptureAllMetadata(*destination_object.Get<tMetadata>()); 
     221    metadata::tMetadataStack::CaptureAllMetadata(*destination_object.Get<tMetadata>()); 
    245222  } 
    246223 
  • tMetadata.h

    r174 r176  
    104104public: 
    105105 
    106   typedef rrlib::rtti::tTypedConstPointer* tIterator; 
    107   typedef rrlib::util::tIteratorRange<rrlib::rtti::tTypedConstPointer*> tElementRange; 
     106  typedef const rrlib::rtti::tTypedConstPointer* tIterator; 
     107  typedef rrlib::util::tIteratorRange<const rrlib::rtti::tTypedConstPointer*> tElementRange; 
    108108 
    109109 
Note: See TracChangeset for help on using the changeset viewer.