@@ -167,9 +167,9 @@ const Out& AsBase(const In& x)
167
167
return x;
168
168
}
169
169
170
- #define READWRITE (...) (:: SerReadWriteMany(s, ser_action , __VA_ARGS__))
171
- #define SER_READ (obj, code ) :: SerRead(s, ser_action , obj, [&](Stream& s, typename std::remove_const<Type>::type& obj) { code; })
172
- #define SER_WRITE (obj, code ) :: SerWrite(s, ser_action , obj, [&](Stream& s, const Type& obj) { code; })
170
+ #define READWRITE (...) (ser_action. SerReadWriteMany(s, __VA_ARGS__))
171
+ #define SER_READ (obj, code ) ser_action. SerRead(s, obj, [&](Stream& s, typename std::remove_const<Type>::type& obj) { code; })
172
+ #define SER_WRITE (obj, code ) ser_action. SerWrite(s, obj, [&](Stream& s, const Type& obj) { code; })
173
173
174
174
/* *
175
175
* Implement the Ser and Unser methods needed for implementing a formatter (see Using below).
@@ -1006,17 +1006,65 @@ void Unserialize(Stream& is, std::shared_ptr<const T>& p)
1006
1006
p = std::make_shared<const T>(deserialize, is);
1007
1007
}
1008
1008
1009
+ /* *
1010
+ * Support for (un)serializing many things at once
1011
+ */
1012
+
1013
+ template <typename Stream, typename ... Args>
1014
+ void SerializeMany (Stream& s, const Args&... args)
1015
+ {
1016
+ (::Serialize (s, args), ...);
1017
+ }
1018
+
1019
+ template <typename Stream, typename ... Args>
1020
+ inline void UnserializeMany (Stream& s, Args&&... args)
1021
+ {
1022
+ (::Unserialize (s, args), ...);
1023
+ }
1009
1024
1010
1025
/* *
1011
1026
* Support for all macros providing or using the ser_action parameter of the SerializationOps method.
1012
1027
*/
1013
1028
struct ActionSerialize {
1014
- constexpr bool ForRead () const { return false ; }
1029
+ static constexpr bool ForRead () { return false ; }
1030
+
1031
+ template <typename Stream, typename ... Args>
1032
+ static void SerReadWriteMany (Stream& s, const Args&... args)
1033
+ {
1034
+ ::SerializeMany (s, args...);
1035
+ }
1036
+
1037
+ template <typename Stream, typename Type, typename Fn>
1038
+ static void SerRead (Stream& s, Type&&, Fn&&)
1039
+ {
1040
+ }
1041
+
1042
+ template <typename Stream, typename Type, typename Fn>
1043
+ static void SerWrite (Stream& s, Type&& obj, Fn&& fn)
1044
+ {
1045
+ fn (s, std::forward<Type>(obj));
1046
+ }
1015
1047
};
1016
1048
struct ActionUnserialize {
1017
- constexpr bool ForRead () const { return true ; }
1018
- };
1049
+ static constexpr bool ForRead () { return true ; }
1019
1050
1051
+ template <typename Stream, typename ... Args>
1052
+ static void SerReadWriteMany (Stream& s, Args&&... args)
1053
+ {
1054
+ ::UnserializeMany (s, args...);
1055
+ }
1056
+
1057
+ template <typename Stream, typename Type, typename Fn>
1058
+ static void SerRead (Stream& s, Type&& obj, Fn&& fn)
1059
+ {
1060
+ fn (s, std::forward<Type>(obj));
1061
+ }
1062
+
1063
+ template <typename Stream, typename Type, typename Fn>
1064
+ static void SerWrite (Stream& s, Type&&, Fn&&)
1065
+ {
1066
+ }
1067
+ };
1020
1068
1021
1069
/* ::GetSerializeSize implementations
1022
1070
*
@@ -1063,52 +1111,6 @@ class CSizeComputer
1063
1111
int GetVersion () const { return nVersion; }
1064
1112
};
1065
1113
1066
- template <typename Stream, typename ... Args>
1067
- void SerializeMany (Stream& s, const Args&... args)
1068
- {
1069
- (::Serialize (s, args), ...);
1070
- }
1071
-
1072
- template <typename Stream, typename ... Args>
1073
- inline void UnserializeMany (Stream& s, Args&&... args)
1074
- {
1075
- (::Unserialize (s, args), ...);
1076
- }
1077
-
1078
- template <typename Stream, typename ... Args>
1079
- inline void SerReadWriteMany (Stream& s, ActionSerialize ser_action, const Args&... args)
1080
- {
1081
- ::SerializeMany (s, args...);
1082
- }
1083
-
1084
- template <typename Stream, typename ... Args>
1085
- inline void SerReadWriteMany (Stream& s, ActionUnserialize ser_action, Args&&... args)
1086
- {
1087
- ::UnserializeMany (s, args...);
1088
- }
1089
-
1090
- template <typename Stream, typename Type, typename Fn>
1091
- inline void SerRead (Stream& s, ActionSerialize ser_action, Type&&, Fn&&)
1092
- {
1093
- }
1094
-
1095
- template <typename Stream, typename Type, typename Fn>
1096
- inline void SerRead (Stream& s, ActionUnserialize ser_action, Type&& obj, Fn&& fn)
1097
- {
1098
- fn (s, std::forward<Type>(obj));
1099
- }
1100
-
1101
- template <typename Stream, typename Type, typename Fn>
1102
- inline void SerWrite (Stream& s, ActionSerialize ser_action, Type&& obj, Fn&& fn)
1103
- {
1104
- fn (s, std::forward<Type>(obj));
1105
- }
1106
-
1107
- template <typename Stream, typename Type, typename Fn>
1108
- inline void SerWrite (Stream& s, ActionUnserialize ser_action, Type&&, Fn&&)
1109
- {
1110
- }
1111
-
1112
1114
template <typename I>
1113
1115
inline void WriteVarInt (CSizeComputer &s, I n)
1114
1116
{
0 commit comments