|
13 | 13 | #include <ios>
|
14 | 14 | #include <limits>
|
15 | 15 | #include <map>
|
| 16 | +#include <memory> |
16 | 17 | #include <set>
|
17 | 18 | #include <stdint.h>
|
18 | 19 | #include <string>
|
|
24 | 25 |
|
25 | 26 | static const unsigned int MAX_SIZE = 0x02000000;
|
26 | 27 |
|
| 28 | +/** |
| 29 | + * Dummy data type to identify deserializing constructors. |
| 30 | + * |
| 31 | + * By convention, a constructor of a type T with signature |
| 32 | + * |
| 33 | + * template <typename Stream> T::T(deserialize_type, Stream& s) |
| 34 | + * |
| 35 | + * is a deserializing constructor, which builds the type by |
| 36 | + * deserializing it from s. If T contains const fields, this |
| 37 | + * is likely the only way to do so. |
| 38 | + */ |
| 39 | +struct deserialize_type {}; |
| 40 | +constexpr deserialize_type deserialize {}; |
| 41 | + |
27 | 42 | /**
|
28 | 43 | * Used to bypass the rule against non-const reference to temporary
|
29 | 44 | * where it makes sense with wrappers such as CFlatData or CTxDB
|
@@ -521,7 +536,17 @@ template<typename Stream, typename K, typename T, typename Pred, typename A> voi
|
521 | 536 | template<typename Stream, typename K, typename Pred, typename A> void Serialize(Stream& os, const std::set<K, Pred, A>& m);
|
522 | 537 | template<typename Stream, typename K, typename Pred, typename A> void Unserialize(Stream& is, std::set<K, Pred, A>& m);
|
523 | 538 |
|
| 539 | +/** |
| 540 | + * shared_ptr |
| 541 | + */ |
| 542 | +template<typename Stream, typename T> void Serialize(Stream& os, const std::shared_ptr<const T>& p); |
| 543 | +template<typename Stream, typename T> void Unserialize(Stream& os, std::shared_ptr<const T>& p); |
524 | 544 |
|
| 545 | +/** |
| 546 | + * unique_ptr |
| 547 | + */ |
| 548 | +template<typename Stream, typename T> void Serialize(Stream& os, const std::unique_ptr<const T>& p); |
| 549 | +template<typename Stream, typename T> void Unserialize(Stream& os, std::unique_ptr<const T>& p); |
525 | 550 |
|
526 | 551 |
|
527 | 552 |
|
@@ -775,6 +800,40 @@ void Unserialize(Stream& is, std::set<K, Pred, A>& m)
|
775 | 800 |
|
776 | 801 |
|
777 | 802 |
|
| 803 | +/** |
| 804 | + * unique_ptr |
| 805 | + */ |
| 806 | +template<typename Stream, typename T> void |
| 807 | +Serialize(Stream& os, const std::unique_ptr<const T>& p) |
| 808 | +{ |
| 809 | + Serialize(os, *p); |
| 810 | +} |
| 811 | + |
| 812 | +template<typename Stream, typename T> |
| 813 | +void Unserialize(Stream& is, std::unique_ptr<const T>& p) |
| 814 | +{ |
| 815 | + p.reset(new T(deserialize, is)); |
| 816 | +} |
| 817 | + |
| 818 | + |
| 819 | + |
| 820 | +/** |
| 821 | + * shared_ptr |
| 822 | + */ |
| 823 | +template<typename Stream, typename T> void |
| 824 | +Serialize(Stream& os, const std::shared_ptr<const T>& p) |
| 825 | +{ |
| 826 | + Serialize(os, *p); |
| 827 | +} |
| 828 | + |
| 829 | +template<typename Stream, typename T> |
| 830 | +void Unserialize(Stream& is, std::shared_ptr<const T>& p) |
| 831 | +{ |
| 832 | + p = std::make_shared<const T>(deserialize, is); |
| 833 | +} |
| 834 | + |
| 835 | + |
| 836 | + |
778 | 837 | /**
|
779 | 838 | * Support for ADD_SERIALIZE_METHODS and READWRITE macro
|
780 | 839 | */
|
|
0 commit comments