Changeset 182:f5d70b7d5aad in rrlib_serialization


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

Replaces IsConstElementContainer type trait with more meaningful IsAssociativeContainer type trait

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ContainerSerialization.h

    r171 r182  
    113113 * (allows different deserialization implementation for sets) 
    114114 */ 
    115 template <typename T, bool CONTAINER_HAS_CONST_ELEMENTS> 
     115template <typename T, bool Tassociative_container> 
    116116struct ContainerDeserializationDefaulImplementation 
    117117{ 
     
    236236  static void Deserialize(tInputStream& stream, TContainer& container) 
    237237  { 
    238     ContainerDeserializationDefaulImplementation<T, IsConstElementContainer<TContainer>::value>::Deserialize(stream, container); 
     238    ContainerDeserializationDefaulImplementation<T, IsAssociativeContainer<TContainer>::value>::Deserialize(stream, container); 
    239239  } 
    240240 
     
    284284  static void Deserialize(const xml::tNode& node, TContainer& container) 
    285285  { 
    286     ContainerDeserializationDefaulImplementation<T, IsConstElementContainer<TContainer>::value>::Deserialize(node, container); 
     286    ContainerDeserializationDefaulImplementation<T, IsAssociativeContainer<TContainer>::value>::Deserialize(node, container); 
    287287  } 
    288288 
  • tests/serialization.cpp

    r180 r182  
    9898static_assert(IsBinarySerializable<std::map<size_t, std::string>>::value == true, "Incorrect trait implementation"); 
    9999static_assert(IsXMLSerializable<std::map<size_t, std::string>>::value == true, "Incorrect trait implementation"); 
    100 static_assert(IsConstElementContainer<std::vector<std::string>>::value == false, "Incorrect trait implementation"); 
     100static_assert(IsAssociativeContainer<std::vector<std::string>>::value == false, "Incorrect trait implementation"); 
     101static_assert(IsAssociativeContainer<std::vector<double>>::value == false, "Incorrect trait implementation"); 
     102static_assert(IsAssociativeContainer<std::map<size_t, std::string>>::value == true, "Incorrect trait implementation"); 
    101103 
    102104static_assert(IsStringSerializable<bool>::value, "Incorrect trait implementation"); 
     
    105107 
    106108static_assert(IsSerializableContainer<std::set<std::string>>::value == true, "Incorrect trait implementation"); 
    107 static_assert(IsConstElementContainer<std::set<std::string>>::value == true, "Incorrect trait implementation"); 
     109static_assert(IsAssociativeContainer<std::set<std::string>>::value == true, "Incorrect trait implementation"); 
     110static_assert(IsAssociativeContainer<std::set<double>>::value == true, "Incorrect trait implementation"); 
    108111 
    109112static_assert(IsBinarySerializable<std::tuple<>>::value == true, "Incorrect trait implementation"); 
  • type_traits.h

    r171 r182  
    258258 
    259259/*! 
    260  * Type trait that checks whether T is a container with constant elements (such as std::set) 
    261  */ 
    262 template <typename T> 
    263 class IsConstElementContainer 
     260 * Type trait that checks whether T is an associative container (such as std::set or std::map) 
     261 */ 
     262template <typename T> 
     263class IsAssociativeContainer 
    264264{ 
    265265  template <typename U> 
     
    267267 
    268268  template <typename U = T> 
    269   static typename std::remove_reference<decltype(*Make<U>().begin())>::type TestBegin(void*); 
     269  static decltype(*Make<U>().begin()) TestBegin(void*); 
    270270  static void TestBegin(...); 
    271271 
    272272public: 
    273273 
    274   enum { value = std::is_const<decltype(TestBegin(nullptr))>::value }; 
     274  enum { value = IsSerializableMap<T>::value || std::is_const<typename std::remove_reference<decltype(TestBegin(nullptr))>::type>::value || (!std::is_reference<decltype(TestBegin(nullptr))>::value) }; 
     275}; 
     276 
     277template <> 
     278class IsAssociativeContainer<std::vector<bool>> 
     279{ 
     280public: 
     281  enum { value = 0 }; 
    275282}; 
    276283 
Note: See TracChangeset for help on using the changeset viewer.