| 1 |
#ifndef SERIALIZE_STL_HH |
| 2 |
#define SERIALIZE_STL_HH |
| 3 |
|
| 4 |
#include "serialize_core.hh" |
| 5 |
|
| 6 |
#include "circular_buffer.hh" |
| 7 |
#include "static_vector.hh" |
| 8 |
|
| 9 |
#include <deque> |
| 10 |
#include <iterator> |
| 11 |
#include <vector> |
| 12 |
|
| 13 |
namespace openmsx { |
| 14 |
|
| 15 |
template<typename T> struct serialize_as_stl_collection : std::true_type |
| 16 |
{ |
| 17 |
static constexpr int size = -1; |
| 18 |
using value_type = typename T::value_type; |
| 19 |
|
| 20 |
static auto begin(const T& t) { return t.begin(); } |
| 21 |
static auto end (const T& t) { return t.end(); } |
| 22 |
|
| 23 |
static constexpr bool loadInPlace = false; |
| 24 |
static void prepare(T& t, int ) { |
| 25 |
t.clear(); |
| 26 |
} |
| 27 |
static auto output(T& t) { |
| 28 |
return std::back_inserter(t); |
| 29 |
} |
| 30 |
}; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
template<typename T> struct serialize_as_collection<std::deque<T>> |
| 36 |
: serialize_as_stl_collection<std::deque<T>> {}; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
template<typename T> struct serialize_as_collection<std::vector<T>> |
| 42 |
: serialize_as_stl_collection<std::vector<T>> |
| 43 |
{ |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
static constexpr bool loadInPlace = false; |
| 50 |
static void prepare(std::vector<T>& v, int n) { |
| 51 |
v.clear(); v.reserve(n); |
| 52 |
} |
| 53 |
static auto output(std::vector<T>& v) { |
| 54 |
return std::back_inserter(v); |
| 55 |
} |
| 56 |
}; |
| 57 |
|
| 58 |
template<typename T> struct serialize_as_collection<cb_queue<T>> |
| 59 |
: serialize_as_stl_collection<cb_queue<T>> |
| 60 |
{ |
| 61 |
static void prepare(cb_queue<T>& q, int n) { |
| 62 |
q.clear(); q.getBuffer().set_capacity(n); |
| 63 |
} |
| 64 |
static auto output(cb_queue<T>& q) { |
| 65 |
return std::back_inserter(q.getBuffer()); |
| 66 |
} |
| 67 |
}; |
| 68 |
|
| 69 |
template<typename T, size_t N> struct serialize_as_collection<static_vector<T, N>> |
| 70 |
: serialize_as_stl_collection<static_vector<T, N>> {}; |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
#endif |