Changeset 44:1822b86eb0d9 in rrlib_rtti_conversion


Ignore:
Timestamp:
13.05.2021 20:19:40 (6 weeks ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
17.03
Phase:
public
Message:

Adds 'to single element vector' type conversion operation

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • defined_conversions.cpp

    r40 r44  
    779779} cGET_TUPLE_ELEMENT; 
    780780 
     781class tToSingleElementVector : public tRegisteredConversionOperation 
     782{ 
     783public: 
     784  tToSingleElementVector() : tRegisteredConversionOperation(util::tManagedConstCharPointer("ToVector", false), tSupportedTypeFilter::TO_SINGLE_ELEMENT_VECTOR, tSupportedTypeFilter::TO_SINGLE_ELEMENT_VECTOR, nullptr) 
     785  {} 
     786 
     787  virtual tConversionOption GetConversionOption(const tType& source_type, const tType& destination_type, const tGenericObject* parameter) const override 
     788  { 
     789    if (destination_type.IsListType() && destination_type.GetElementType() == source_type) 
     790    { 
     791      return tConversionOption(source_type, destination_type, false, &FirstConversionFunction, &FinalConversionFunction); 
     792    } 
     793    return tConversionOption(); 
     794  } 
     795 
     796  static void FirstConversionFunction(const tTypedConstPointer& source_object, const tTypedPointer& destination_object, const tCurrentConversionOperation& operation) 
     797  { 
     798    tType inter_type = operation.compiled_operation.IntermediateType(); 
     799    char intermediate_memory[inter_type.GetSize(true)]; 
     800    auto intermediate_object = inter_type.EmplaceGenericObject(intermediate_memory); 
     801    FinalConversionFunction(source_object, *intermediate_object, operation); 
     802    operation.Continue(*intermediate_object, destination_object); 
     803  } 
     804 
     805  static void FinalConversionFunction(const tTypedConstPointer& source_object, const tTypedPointer& destination_object, const tCurrentConversionOperation& operation) 
     806  { 
     807    destination_object.ResizeVector(1); 
     808    auto destination_element = destination_object.GetVectorElement(0); 
     809    assert(destination_element.GetType().GetSize() == source_object.GetType().GetSize()); 
     810    destination_element.DeepCopyFrom(source_object); 
     811  } 
     812 
     813  static constexpr tConversionOption cCONVERSION_OPTION = tConversionOption(tDataType<std::vector<uint8_t>>(), tDataType<rrlib::serialization::tMemoryBuffer>(), true, &FirstConversionFunction, &FinalConversionFunction); 
     814 
     815} cTO_SINGLE_ELEMENT_VECTOR; 
     816 
    781817class tWrapByteVectorOperation : public tRegisteredConversionOperation 
    782818{ 
     
    787823  static void FirstConversionFunction(const tTypedConstPointer& source_object, const tTypedPointer& destination_object, const tCurrentConversionOperation& operation) 
    788824  { 
     825 
     826 
    789827    const std::vector<uint8_t>& vector = *source_object.Get<std::vector<uint8_t>>(); 
    790828    if (vector.size()) 
     
    10951133const tRegisteredConversionOperation& cARRAY_TO_VECTOR_OPERATION = cARRAY_TO_VECTOR; 
    10961134const tRegisteredConversionOperation& cGET_TUPLE_ELEMENT_OPERATION = cGET_TUPLE_ELEMENT; 
     1135const tRegisteredConversionOperation& cTO_SINGLE_ELEMENT_VECTOR_OPERATION = cTO_SINGLE_ELEMENT_VECTOR; 
    10971136 
    10981137const tRegisteredConversionOperation& cWRAP_BYTE_VECTOR_OPERATION = cWRAP_BYTE_VECTOR; 
  • defined_conversions.h

    r32 r44  
    8484extern const tRegisteredConversionOperation& cARRAY_TO_VECTOR_OPERATION;        //!< Converts std::array<T> to std::vector<T> 
    8585extern const tRegisteredConversionOperation& cGET_TUPLE_ELEMENT_OPERATION;      //!< Get element of std::pair or std::tuple object 
     86extern const tRegisteredConversionOperation& cTO_SINGLE_ELEMENT_VECTOR_OPERATION;  //!< Converts T to std::vector<T> with one element 
    8687 
    8788extern const tRegisteredConversionOperation& cWRAP_BYTE_VECTOR_OPERATION;       //!< Converts std::vector<uint> to a MemoryBuffer. This is particulary efficient (zero-copy) when first operation in a sequence. 
  • tRegisteredConversionOperation.h

    r42 r44  
    9292 
    9393  // For externally defined non-standard operations 
    94   EXTERNALLY_DEFINED 
     94  EXTERNALLY_DEFINED, 
     95 
     96  // Newer enum constants (appended after 2020) 
     97  TO_SINGLE_ELEMENT_VECTOR,  //!< Types supported by to single element vector operation 
    9598}; 
    9699 
Note: See TracChangeset for help on using the changeset viewer.