Sleeping Wombat Common Library  0.50.0
swCommonLibrary
SerializationContext.h
1 #pragma once
2 
9 #include "swCommonLib/Common/RTTR.h"
10 #include "swCommonLib/Common/Exceptions/Exception.h"
11 
12 #include "swCommonLib/Serialization/FilePosition.h"
14 #include "swCommonLib/Serialization/PropertySerialization/Core/Exceptions/SerializationException.h"
15 
16 #include <map>
17 #include <vector>
18 #include <type_traits>
19 
20 
21 namespace sw
22 {
23 
24 
31 {
32 private:
33 
34  typedef std::map< rttr::type, std::vector< rttr::property > > TypePropertyMap;
35  typedef std::vector< ExceptionPtr > Exceptions;
36 
37 public:
38 
39 
40  TypePropertyMap TypeProperties;
41 
42 private:
43 
44  Exceptions m_warnings;
45 
46 public:
47  virtual ~SerializationContext() = default;
48 
49 public:
50 
51  const Exceptions& GetWarnings ();
52  void AddWarning ( ExceptionPtr warning );
53 
54  template< typename WarningType >
55  void AddWarning ( const std::string & message, FilePosition filePos );
56 };
57 
58 DEFINE_PTR_TYPE( SerializationContext )
59 
60 
61 
62 
63 // ========================================================================= //
64 // Implmentation
65 // ========================================================================= //
66 
67 // ***********************
68 //
69 template< typename WarningType >
70 inline void SerializationContext::AddWarning ( const std::string& message, FilePosition filePos )
71 {
72  AddWarning( std::make_shared< WarningType >( message, filePos ) );
73 }
74 
75 // ***********************
76 //
77 template< typename WarningType >
78 inline void Warn ( const IDeserializer& deser, const std::string& message )
79 {
80  static_assert( std::is_base_of< SerializationException, WarningType >::value, "WariningType should be derived from SerializationException." );
81 
82  auto ctx = deser.GetContext< SerializationContext >();
83  if( ctx )
84  {
85  auto filePos = deser.CurrentLineNumber();
86 
87  ctx->AddWarning< WarningType >( message, filePos );
88  }
89 }
90 
91 
92 } // sw
93 
Serialization context for automatic serialization.
Definition: SerializationContext.h:30
Interface for deserializers.
Definition: Deserializer.h:39
Definition: Exception.h:11
Definition: FilePosition.h:11
ContextType * GetContext() const
Zwraca kontekst serializacji.
Definition: Deserializer.h:94
Interface for context used in serialization and deserialization.ISerializationContext is used to stor...
Definition: ISerializationContext.h:20
sw::FilePosition CurrentLineNumber() const
Definition: Deserializer.cpp:721
TypePropertyMap TypeProperties
Maps containing all serializable properties for type.
Definition: SerializationContext.h:40