aboutsummaryrefslogtreecommitdiff
path: root/src/serialization/vector.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/serialization/vector.h82
1 files changed, 10 insertions, 72 deletions
diff --git a/src/serialization/vector.h b/src/serialization/vector.h
index 12fd59558..9cf3d8272 100644
--- a/src/serialization/vector.h
+++ b/src/serialization/vector.h
@@ -30,6 +30,7 @@
#pragma once
+#include <vector>
#include "serialization.h"
template <template <bool> class Archive, class T>
@@ -37,91 +38,28 @@ bool do_serialize(Archive<false> &ar, std::vector<T> &v);
template <template <bool> class Archive, class T>
bool do_serialize(Archive<true> &ar, std::vector<T> &v);
-template <template <bool> class Archive, class T>
-bool do_serialize(Archive<false> &ar, std::deque<T> &v);
-template <template <bool> class Archive, class T>
-bool do_serialize(Archive<true> &ar, std::deque<T> &v);
-
namespace serialization
{
namespace detail
{
- template <typename Archive, class T>
- bool serialize_vector_element(Archive& ar, T& e)
- {
- return ::do_serialize(ar, e);
- }
-
- template <typename Archive>
- bool serialize_vector_element(Archive& ar, uint32_t& e)
+ template <typename T>
+ void do_reserve(std::vector<T> &c, size_t N)
{
- ar.serialize_varint(e);
- return true;
+ c.reserve(N);
}
- template <typename Archive>
- bool serialize_vector_element(Archive& ar, uint64_t& e)
+ template <typename T>
+ void do_add(std::vector<T> &c, T &&e)
{
- ar.serialize_varint(e);
- return true;
+ c.emplace_back(std::move(e));
}
}
}
-template <template <bool> class Archive, class T>
-bool do_serialize_vd(Archive<false> &ar, T &v)
-{
- size_t cnt;
- ar.begin_array(cnt);
- if (!ar.stream().good())
- return false;
- v.clear();
-
- // very basic sanity check
- if (ar.remaining_bytes() < cnt) {
- ar.stream().setstate(std::ios::failbit);
- return false;
- }
-
- v.reserve(cnt);
- for (size_t i = 0; i < cnt; i++) {
- if (i > 0)
- ar.delimit_array();
- v.resize(i+1);
- if (!::serialization::detail::serialize_vector_element(ar, v[i]))
- return false;
- if (!ar.stream().good())
- return false;
- }
- ar.end_array();
- return true;
-}
-
-template <template <bool> class Archive, class T>
-bool do_serialize_vd(Archive<true> &ar, T &v)
-{
- size_t cnt = v.size();
- ar.begin_array(cnt);
- for (size_t i = 0; i < cnt; i++) {
- if (!ar.stream().good())
- return false;
- if (i > 0)
- ar.delimit_array();
- if(!::serialization::detail::serialize_vector_element(ar, v[i]))
- return false;
- if (!ar.stream().good())
- return false;
- }
- ar.end_array();
- return true;
-}
+#include "container.h"
template <template <bool> class Archive, class T>
-bool do_serialize(Archive<false> &ar, std::vector<T> &v) { return do_serialize_vd(ar, v); }
+bool do_serialize(Archive<false> &ar, std::vector<T> &v) { return do_serialize_container(ar, v); }
template <template <bool> class Archive, class T>
-bool do_serialize(Archive<true> &ar, std::vector<T> &v) { return do_serialize_vd(ar, v); }
+bool do_serialize(Archive<true> &ar, std::vector<T> &v) { return do_serialize_container(ar, v); }
-template <template <bool> class Archive, class T>
-bool do_serialize(Archive<false> &ar, std::deque<T> &v) { return do_serialize_vd(ar, v); }
-template <template <bool> class Archive, class T>
-bool do_serialize(Archive<true> &ar, std::deque<T> &v) { return do_serialize_vd(ar, v); }