Changeset 12:d8358d32e422 in rrlib_rtti_conversion


Ignore:
Timestamp:
28.01.2019 15:39:40 (3 months ago)
Author:
Max Reichardt <max.reichardt@…>
Branch:
17.03
Children:
13:9904a55fa400, 14:f68f39f38f15
Phase:
public
Message:

Extends FOR_EACH conversion operation to support std::vector<bool> (with its non-standard memory layout)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • defined_conversions.cpp

    r10 r12  
    145145 
    146146const unsigned int cSTRING_OPERATION_DEFAULT_FLAGS = 0; 
     147const rrlib::rtti::tType cBOOL_VECTOR_TYPE = rrlib::rtti::tDataType<std::vector<bool>>(); 
     148 
    147149 
    148150class tToStringOperation : public tRegisteredConversionOperation 
     
    421423      if (size) 
    422424      { 
    423         tTypedConstPointer source_first = source_object.GetVectorElement(0); 
    424         tTypedPointer destination_first = destination_object.GetVectorElement(0); 
    425         operation.Continue(source_first, destination_first); 
    426         if (size > 1) 
    427         { 
    428           tTypedConstPointer source_next = source_object.GetVectorElement(1); 
    429           tTypedPointer destination_next = destination_object.GetVectorElement(1); 
    430           operation.Continue(source_next, destination_next); 
    431           size_t offset_source = static_cast<const char*>(source_next.GetRawDataPointer()) - static_cast<const char*>(source_first.GetRawDataPointer()); 
    432           size_t offset_destination = static_cast<const char*>(destination_next.GetRawDataPointer()) - static_cast<const char*>(destination_first.GetRawDataPointer()); 
    433           for (size_t i = 2; i < size; i++) 
     425        if (source_type == cBOOL_VECTOR_TYPE) 
     426        { 
     427          bool wrapped_bool = false; 
     428          tTypedPointer temp_source_pointer(&wrapped_bool); 
     429          const std::vector<bool>& source = *source_object.Get<std::vector<bool>>(); 
     430 
     431          wrapped_bool = source[0]; 
     432          tTypedPointer destination_first = destination_object.GetVectorElement(0); 
     433          operation.Continue(temp_source_pointer, destination_first); 
     434          if (size > 1) 
    434435          { 
    435             source_next = tTypedConstPointer(static_cast<const char*>(source_next.GetRawDataPointer()) + offset_source, source_element_type); 
    436             destination_next = tTypedPointer(static_cast<char*>(destination_next.GetRawDataPointer()) + offset_destination, destination_element_type); 
     436            wrapped_bool = source[1]; 
     437            tTypedPointer destination_next = destination_object.GetVectorElement(1); 
     438            operation.Continue(temp_source_pointer, destination_next); 
     439            size_t offset_destination = static_cast<const char*>(destination_next.GetRawDataPointer()) - static_cast<const char*>(destination_first.GetRawDataPointer()); 
     440            for (size_t i = 2; i < size; i++) 
     441            { 
     442              wrapped_bool = source[i]; 
     443              destination_next = tTypedPointer(static_cast<char*>(destination_next.GetRawDataPointer()) + offset_destination, destination_element_type); 
     444              operation.Continue(temp_source_pointer, destination_next); 
     445            } 
     446          } 
     447        } 
     448        else if (destination_type == cBOOL_VECTOR_TYPE) 
     449        { 
     450          bool wrapped_bool = false; 
     451          tTypedPointer temp_destination_pointer(&wrapped_bool); 
     452          std::vector<bool>& destination = *destination_object.Get<std::vector<bool>>(); 
     453 
     454          tTypedConstPointer source_first = source_object.GetVectorElement(0); 
     455          operation.Continue(source_first, temp_destination_pointer); 
     456          destination[0] = wrapped_bool; 
     457          if (size > 1) 
     458          { 
     459            tTypedConstPointer source_next = source_object.GetVectorElement(1); 
     460            operation.Continue(source_next, temp_destination_pointer); 
     461            size_t offset_source = static_cast<const char*>(source_next.GetRawDataPointer()) - static_cast<const char*>(source_first.GetRawDataPointer()); 
     462            destination[1] = wrapped_bool; 
     463            for (size_t i = 2; i < size; i++) 
     464            { 
     465              source_next = tTypedConstPointer(static_cast<const char*>(source_next.GetRawDataPointer()) + offset_source, source_element_type); 
     466              operation.Continue(source_next, temp_destination_pointer); 
     467              destination[i] = wrapped_bool; 
     468            } 
     469          } 
     470        } 
     471        else 
     472        { 
     473          tTypedConstPointer source_first = source_object.GetVectorElement(0); 
     474          tTypedPointer destination_first = destination_object.GetVectorElement(0); 
     475          operation.Continue(source_first, destination_first); 
     476          if (size > 1) 
     477          { 
     478            tTypedConstPointer source_next = source_object.GetVectorElement(1); 
     479            tTypedPointer destination_next = destination_object.GetVectorElement(1); 
    437480            operation.Continue(source_next, destination_next); 
     481            size_t offset_source = static_cast<const char*>(source_next.GetRawDataPointer()) - static_cast<const char*>(source_first.GetRawDataPointer()); 
     482            size_t offset_destination = static_cast<const char*>(destination_next.GetRawDataPointer()) - static_cast<const char*>(destination_first.GetRawDataPointer()); 
     483            for (size_t i = 2; i < size; i++) 
     484            { 
     485              source_next = tTypedConstPointer(static_cast<const char*>(source_next.GetRawDataPointer()) + offset_source, source_element_type); 
     486              destination_next = tTypedPointer(static_cast<char*>(destination_next.GetRawDataPointer()) + offset_destination, destination_element_type); 
     487              operation.Continue(source_next, destination_next); 
     488            } 
    438489          } 
    439490        } 
     
    464515        size_t source_element_offset = source_type.GetSize() / size; 
    465516        tTypedConstPointer source(static_cast<const char*>(source_object.GetRawDataPointer()), source_element_type); 
    466         tTypedPointer destination_first = destination_object.GetVectorElement(0); 
    467         operation.Continue(source, destination_first); 
    468         if (size > 1) 
    469         { 
    470           tTypedConstPointer source(static_cast<const char*>(source_object.GetRawDataPointer()) + source_element_offset, source_element_type); 
    471           tTypedPointer destination_next = destination_object.GetVectorElement(1); 
    472           operation.Continue(source, destination_next); 
    473           size_t offset_destination = static_cast<const char*>(destination_next.GetRawDataPointer()) - static_cast<const char*>(destination_first.GetRawDataPointer()); 
    474           for (size_t i = 2; i < size; i++) 
     517 
     518        if (destination_type == cBOOL_VECTOR_TYPE) 
     519        { 
     520          bool wrapped_bool = false; 
     521          tTypedPointer temp_destination_pointer(&wrapped_bool); 
     522          std::vector<bool>& destination = *destination_object.Get<std::vector<bool>>(); 
     523 
     524          operation.Continue(source, temp_destination_pointer); 
     525          destination[0] = wrapped_bool; 
     526          if (size > 1) 
    475527          { 
    476             tTypedConstPointer source(static_cast<const char*>(source_object.GetRawDataPointer()) + i * source_element_offset, source_element_type); 
    477             destination_next = tTypedPointer(static_cast<char*>(destination_next.GetRawDataPointer()) + offset_destination, destination_element_type); 
     528            tTypedConstPointer source(static_cast<const char*>(source_object.GetRawDataPointer()) + source_element_offset, source_element_type); 
     529            operation.Continue(source, temp_destination_pointer); 
     530            destination[1] = wrapped_bool; 
     531            for (size_t i = 2; i < size; i++) 
     532            { 
     533              tTypedConstPointer source(static_cast<const char*>(source_object.GetRawDataPointer()) + i * source_element_offset, source_element_type); 
     534              operation.Continue(source, temp_destination_pointer); 
     535              destination[i] = wrapped_bool; 
     536            } 
     537          } 
     538        } 
     539        else 
     540        { 
     541          tTypedPointer destination_first = destination_object.GetVectorElement(0); 
     542          operation.Continue(source, destination_first); 
     543          if (size > 1) 
     544          { 
     545            tTypedConstPointer source(static_cast<const char*>(source_object.GetRawDataPointer()) + source_element_offset, source_element_type); 
     546            tTypedPointer destination_next = destination_object.GetVectorElement(1); 
    478547            operation.Continue(source, destination_next); 
     548            size_t offset_destination = static_cast<const char*>(destination_next.GetRawDataPointer()) - static_cast<const char*>(destination_first.GetRawDataPointer()); 
     549            for (size_t i = 2; i < size; i++) 
     550            { 
     551              tTypedConstPointer source(static_cast<const char*>(source_object.GetRawDataPointer()) + i * source_element_offset, source_element_type); 
     552              destination_next = tTypedPointer(static_cast<char*>(destination_next.GetRawDataPointer()) + offset_destination, destination_element_type); 
     553              operation.Continue(source, destination_next); 
     554            } 
    479555          } 
    480556        } 
Note: See TracChangeset for help on using the changeset viewer.