Changeset 95:650a1718e5b5 in rrlib_rtti


Ignore:
Timestamp:
29.06.2017 22:36:43 (22 months ago)
Author:
Max Reichardt <max.reichardt@…>
Branch:
17.03
Phase:
public
Message:

Fixes issues with DeepCopyOperation function/trait and adds test case

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • detail/generic_operations.h

    r94 r95  
    144144 
    145145 
    146 template < typename T, bool Tunderlying_type = !std::is_same<typename UnderlyingType<T>::type, T>::value, bool Tconvertible = std::is_convertible<T, typename UnderlyingType<T>::type>::value, bool Tconvertible_normalized = std::is_convertible<T, typename NormalizedType<T>::type>::value > 
    147 struct DeepCopyOperation : std::conditional<serialization::IsSerializableContainer<T>::value, detail::DeepCopyOperationContainer<typename NormalizedType<T>::type>, detail::DeepCopyOperationNonContainer<typename NormalizedType<T>::type>>::type 
    148 {}; 
     146template < typename T, bool Tcontainer = serialization::IsSerializableContainer<T>::value, bool Tunderlying_type = !std::is_same<typename UnderlyingType<T>::type, T>::value, bool Tconvertible = std::is_convertible<T, typename UnderlyingType<T>::type>::value, bool Tconvertible_normalized = std::is_convertible<T, typename NormalizedType<T>::type>::value > 
     147struct DeepCopyOperation : std::conditional<Tcontainer, detail::DeepCopyOperationContainer<typename NormalizedType<T>::type>, detail::DeepCopyOperationNonContainer<T>>::type 
     148{}; 
     149 
     150// specializations to reduce the many equivalent std::vector deep copy operations 
    149151template <typename T> // e.g. for std::vector<size_t> and std::vector<long int>, which is not assignable 
    150 struct DeepCopyOperation<T, false, true, false> 
     152struct DeepCopyOperation<T, true, false, true, false> 
    151153{ 
    152154  inline static void DeepCopy(const T& source, T& destination) 
     
    156158  } 
    157159}; 
    158 template <typename T, bool Tconvertible_normalized> 
    159 struct DeepCopyOperation<T, true, true, Tconvertible_normalized> : rtti::DeepCopyOperation<typename UnderlyingType<T>::type> 
    160 {}; 
    161 template <typename T, bool Tconvertible_normalized> 
    162 struct DeepCopyOperation<T, true, false, Tconvertible_normalized> 
     160template <typename T, bool Tconvertible, bool Tconvertible_normalized> 
     161struct DeepCopyOperation<T, true, true, Tconvertible, Tconvertible_normalized> 
    163162{ 
    164163  inline static void DeepCopy(const T& source, T& destination) 
  • tests/rtti.cpp

    r91 r95  
    6565//---------------------------------------------------------------------- 
    6666 
     67enum class tTestEnum 
     68{ 
     69  VALUE1, 
     70  VALUE2, 
     71  VALUE3, 
     72  VALUE4 
     73}; 
     74 
    6775//---------------------------------------------------------------------- 
    6876// Const values 
     
    101109  RRLIB_UNIT_TESTS_ADD_TEST(TestGenericOperations); 
    102110  RRLIB_UNIT_TESTS_ADD_TEST(TestDataTypeInstantiation); 
     111  RRLIB_UNIT_TESTS_ADD_TEST(TestDeepCopy); 
    103112  RRLIB_UNIT_TESTS_END_SUITE; 
    104113 
     
    183192  } 
    184193 
     194  void TestDeepCopy() 
     195  { 
     196    { 
     197      std::vector<size_t> v1 = { 1, 3, 4 }, v2; 
     198      rrlib::rtti::GenericOperations<std::vector<size_t>>::DeepCopy(v1, v2); 
     199      RRLIB_UNIT_TESTS_ASSERT(v1 == v2); 
     200    } 
     201    { 
     202      std::vector<long int> v1 = { 1, 3, 4 }, v2; 
     203      rrlib::rtti::GenericOperations<std::vector<long int>>::DeepCopy(v1, v2); 
     204      RRLIB_UNIT_TESTS_ASSERT(v1 == v2); 
     205    } 
     206    { 
     207      std::vector<tTestEnum> v1 = { tTestEnum::VALUE1, tTestEnum::VALUE3, tTestEnum::VALUE4 }, v2; 
     208      rrlib::rtti::GenericOperations<std::vector<tTestEnum>>::DeepCopy(v1, v2); 
     209      RRLIB_UNIT_TESTS_ASSERT(v1 == v2); 
     210    } 
     211    { 
     212      long int i1 = 1, i2 = 2; 
     213      rrlib::rtti::GenericOperations<long int>::DeepCopy(i1, i2); 
     214      RRLIB_UNIT_TESTS_ASSERT(i1 == i2); 
     215    } 
     216    { 
     217      tTestEnum i1 = tTestEnum::VALUE1, i2 = tTestEnum::VALUE3; 
     218      rrlib::rtti::GenericOperations<tTestEnum>::DeepCopy(i1, i2); 
     219      RRLIB_UNIT_TESTS_ASSERT(i1 == i2); 
     220    } 
     221  } 
     222 
    185223}; 
    186224 
Note: See TracChangeset for help on using the changeset viewer.