Changeset 196:ce376af93525 in rrlib_serialization


Ignore:
Timestamp:
28.03.2020 21:01:44 (11 months ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
17.03
Children:
197:e6cd53ec58ca, 198:eda7de072dc4
Phase:
public
Message:

Adds type trait IsXMLSerializationDefaultImplementation - and helper class to be able to detect this (not particularly pretty)

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • serialization.h

    r172 r196  
    307307namespace internal 
    308308{ 
     309 
    309310template <int ELEMENT, typename ... TArgs> 
    310311struct tTupleXmlSerializer 
     
    372373 
    373374template <typename ... TArgs> 
    374 inline typename std::enable_if < std::is_same < util::tIntegerSequence<serialization::IsXMLSerializable<typename std::remove_cv<typename std::remove_reference<TArgs>::type>::type>::value...>, util::tIntegerSequence < true || serialization::IsXMLSerializable<typename std::remove_cv<typename std::remove_reference<TArgs>::type>::type>::value... >>::value, xml::tNode& >::type 
     375typename std::enable_if < std::is_same < util::tIntegerSequence<serialization::IsXMLSerializable<typename std::remove_cv<typename std::remove_reference<TArgs>::type>::type>::value...>, util::tIntegerSequence < true || serialization::IsXMLSerializable<typename std::remove_cv<typename std::remove_reference<TArgs>::type>::type>::value... >>::value, serialization::internal::tXMLNodeFromDefaultImplementation& >::type 
    375376    operator<< (xml::tNode &node, const std::tuple<TArgs...> &tuple) 
    376377{ 
    377378  serialization::internal::tTupleXmlSerializer < static_cast<int>(std::tuple_size<std::tuple<TArgs...>>::value) - 1, TArgs... >::SerializeTuple(node, tuple); 
    378   return node; 
     379  return reinterpret_cast<serialization::internal::tXMLNodeFromDefaultImplementation&>(node); 
    379380} 
    380381 
    381382template <typename ... TArgs> 
    382 inline typename std::enable_if < std::is_same < util::tIntegerSequence<serialization::IsXMLSerializable<TArgs>::value...>, util::tIntegerSequence < true || serialization::IsXMLSerializable<TArgs>::value... >>::value, const xml::tNode& >::type 
     383typename std::enable_if < std::is_same < util::tIntegerSequence<serialization::IsXMLSerializable<TArgs>::value...>, util::tIntegerSequence < true || serialization::IsXMLSerializable<TArgs>::value... >>::value, const serialization::internal::tXMLNodeFromDefaultImplementation& >::type 
    383384    operator>> (const xml::tNode &node, std::tuple<TArgs...> &tuple) 
    384385{ 
    385386  serialization::internal::tTupleXmlDeserializer < static_cast<int>(std::tuple_size<std::tuple<TArgs...>>::value) - 1, TArgs... >::DeserializeTuple(node.FirstChild(), tuple); 
    386   return node; 
    387 } 
    388  
    389 template <typename T> 
    390 inline typename std::enable_if < serialization::IsSerializableContainer<T>::value && (!serialization::IsSerializableMap<T>::value) && 
     387  return reinterpret_cast<const serialization::internal::tXMLNodeFromDefaultImplementation&>(node); 
     388} 
     389 
     390template <typename T> 
     391typename std::enable_if < serialization::IsSerializableContainer<T>::value && (!serialization::IsSerializableMap<T>::value) && 
    391392(!std::is_same<T, std::string>::value) && 
    392 serialization::ContainerSerialization<typename serialization::IsSerializableContainer<T>::tValue>::cXML_SERIALIZABLE, tNode >::type& 
     393serialization::ContainerSerialization<typename serialization::IsSerializableContainer<T>::tValue>::cXML_SERIALIZABLE, serialization::internal::tXMLNodeFromDefaultImplementation >::type& 
    393394operator<< (tNode& node, const T& t) 
    394395{ 
    395396  static_assert(!std::is_same<std::string, T>::value, "This is not supposed to be used for std::string"); 
    396397  serialization::ContainerSerialization<typename serialization::IsSerializableContainer<T>::tValue>::Serialize(node, t); 
    397   return node; 
    398 } 
    399  
    400 template <typename T> 
    401 inline const typename std::enable_if < serialization::IsSerializableContainer<T>::value && (!serialization::IsSerializableMap<T>::value) && 
     398  return reinterpret_cast<serialization::internal::tXMLNodeFromDefaultImplementation&>(node); 
     399} 
     400 
     401template <typename T> 
     402const typename std::enable_if < serialization::IsSerializableContainer<T>::value && (!serialization::IsSerializableMap<T>::value) && 
    402403(!std::is_same<T, std::string>::value) && 
    403 serialization::ContainerSerialization<typename serialization::IsSerializableContainer<T>::tValue>::cXML_SERIALIZABLE, tNode >::type& 
     404serialization::ContainerSerialization<typename serialization::IsSerializableContainer<T>::tValue>::cXML_SERIALIZABLE, serialization::internal::tXMLNodeFromDefaultImplementation >::type& 
    404405operator>> (const tNode& node, T& t) 
    405406{ 
    406407  static_assert(!std::is_same<std::string, T>::value, "This is not supposed to be used for std::string"); 
    407408  serialization::ContainerSerialization<typename serialization::IsSerializableContainer<T>::tValue>::Deserialize(node, t); 
    408   return node; 
    409 } 
    410  
    411 template <typename T> 
    412 inline typename std::enable_if < serialization::IsSerializableMap<T>::value && 
    413 serialization::ContainerSerialization<typename serialization::IsSerializableMap<T>::tMapped>::cXML_SERIALIZABLE, tNode >::type& 
     409  return reinterpret_cast<const serialization::internal::tXMLNodeFromDefaultImplementation&>(node); 
     410} 
     411 
     412template <typename T> 
     413typename std::enable_if < serialization::IsSerializableMap<T>::value && 
     414serialization::ContainerSerialization<typename serialization::IsSerializableMap<T>::tMapped>::cXML_SERIALIZABLE, serialization::internal::tXMLNodeFromDefaultImplementation >::type& 
    414415operator<< (tNode &node, const T& map) 
    415416{ 
    416417  serialization::ContainerSerialization<typename serialization::IsSerializableMap<T>::tMapped>::SerializeMap(node, map); 
    417   return node; 
    418 } 
    419  
    420 template <typename T> 
    421 inline const typename std::enable_if < serialization::IsSerializableMap<T>::value && 
    422 serialization::ContainerSerialization<typename serialization::IsSerializableMap<T>::tMapped>::cXML_SERIALIZABLE, tNode >::type& 
     418  return reinterpret_cast<serialization::internal::tXMLNodeFromDefaultImplementation&>(node); 
     419} 
     420 
     421template <typename T> 
     422const typename std::enable_if < serialization::IsSerializableMap<T>::value && 
     423serialization::ContainerSerialization<typename serialization::IsSerializableMap<T>::tMapped>::cXML_SERIALIZABLE, serialization::internal::tXMLNodeFromDefaultImplementation >::type& 
    423424operator>> (const tNode &node, T& map) 
    424425{ 
    425426  serialization::ContainerSerialization<typename serialization::IsSerializableMap<T>::tMapped>::DeserializeMap(node, map); 
    426   return node; 
     427  return reinterpret_cast<const serialization::internal::tXMLNodeFromDefaultImplementation&>(node); 
    427428} 
    428429 
    429430template < typename TFirst, typename TSecond, bool Tenable = serialization::IsXMLSerializable<typename std::remove_cv<typename std::remove_reference<TFirst>::type>::type>::value && serialization::IsXMLSerializable<typename std::remove_cv<typename std::remove_reference<TSecond>::type>::type>::value > 
    430 inline typename std::enable_if <Tenable, xml::tNode>::type& operator<< (xml::tNode &node, const std::pair<TFirst, TSecond>& pair) 
     431typename std::enable_if <Tenable, serialization::internal::tXMLNodeFromDefaultImplementation>::type& operator<< (xml::tNode &node, const std::pair<TFirst, TSecond>& pair) 
    431432{ 
    432433  node.AddChildNode("first") << pair.first; 
    433434  node.AddChildNode("second") << pair.second; 
    434   return node; 
     435  return reinterpret_cast<serialization::internal::tXMLNodeFromDefaultImplementation&>(node); 
    435436} 
    436437 
    437438template < typename TFirst, typename TSecond, bool Tenable = serialization::IsXMLSerializable<TFirst>::value && serialization::IsXMLSerializable<TSecond>::value > 
    438 inline const typename std::enable_if <Tenable, xml::tNode>::type& operator>> (const xml::tNode &node, std::pair<TFirst, TSecond>& pair) 
     439const typename std::enable_if <Tenable, serialization::internal::tXMLNodeFromDefaultImplementation>::type& operator>> (const xml::tNode &node, std::pair<TFirst, TSecond>& pair) 
    439440{ 
    440441  bool first = false, second = false; 
     
    454455  if (first && second) 
    455456  { 
    456     return node; 
     457    return reinterpret_cast<const serialization::internal::tXMLNodeFromDefaultImplementation&>(node); 
    457458  } 
    458459  throw std::runtime_error("Node 'first' and/or 'second' missing"); 
  • type_traits.h

    r192 r196  
    5353//---------------------------------------------------------------------- 
    5454 
     55namespace internal 
     56{ 
     57#ifdef _LIB_RRLIB_XML_PRESENT_ 
     58class tXMLNodeFromDefaultImplementation : public xml::tNode 
     59{}; 
     60#endif 
     61} 
     62 
    5563//---------------------------------------------------------------------- 
    5664// Function declarations 
     
    101109{ 
    102110#ifdef _LIB_RRLIB_XML_PRESENT_ 
    103   static xml::tNode &MakeXMLNode(); 
     111  static internal::tXMLNodeFromDefaultImplementation &MakeXMLNode(); 
    104112 
    105113  template <typename U> 
     
    294302}; 
    295303 
     304/*! Whether XML serialization for type T is a default template implementation from rrlib_serialization */ 
     305template <typename T, bool Txml_serializable = IsXMLSerializable<T>::value> 
     306struct IsXMLSerializationDefaultImplementation 
     307{ 
     308  enum { value = 0 }; 
     309}; 
     310 
     311#ifdef _LIB_RRLIB_XML_PRESENT_ 
     312template <typename T> 
     313struct IsXMLSerializationDefaultImplementation<T, true> 
     314{ 
     315  static_assert(IsXMLSerializable<T>::value, "Invalid"); 
     316  static xml::tNode &MakeXMLNode(); 
     317 
     318  static T &Make(); 
     319 
     320  enum { value = std::is_same < serialization::internal::tXMLNodeFromDefaultImplementation&, decltype(MakeXMLNode() << Make()) >::value && std::is_same < const serialization::internal::tXMLNodeFromDefaultImplementation&, decltype(MakeXMLNode() >> Make()) >::value}; 
     321}; 
     322#endif 
     323 
    296324//---------------------------------------------------------------------- 
    297325// End of namespace declaration 
Note: See TracChangeset for help on using the changeset viewer.