13 #include "../core/core-data.hpp"
14 #include "data_view.hpp"
22 #include <helics/external/cereal/archives/portable_binary.hpp>
23 #include <helics/external/cereal/cereal.hpp>
24 #include <helics/external/cereal/types/complex.hpp>
25 #include <helics/external/cereal/types/utility.hpp>
26 #include <helics/external/cereal/types/vector.hpp>
30 #include <type_traits>
34 #include <helics/external/cereal/types/string.hpp>
36 using archiver = cereal::PortableBinaryOutputArchive;
38 using retriever = cereal::PortableBinaryInputArchive;
41 template<
class Archive>
42 void save(Archive& ar,
const data_block& db)
47 template<
class Archive>
48 void load(Archive& ar, data_block& db)
55 template<
class Archive>
56 void save(Archive& ar,
const data_view& db)
61 template<
class Archive>
62 void load(Archive& ar, data_view& db)
66 db = data_view{std::move(val)};
69 template<
class Archive>
70 void serialize(Archive& archive, NamedPoint& m)
72 archive(m.name, m.value);
77 class membuf:
public std::streambuf {
79 membuf(
const char* buf,
size_t size): begin_(buf), end_(buf + size), current_(buf) {}
84 if (current_ == end_) {
85 return traits_type::eof();
88 return traits_type::to_int_type(*current_);
92 if (current_ == end_) {
93 return traits_type::eof();
96 return traits_type::to_int_type(*current_++);
98 int_type pbackfail(int_type ch)
100 if (current_ == begin_ || (ch != traits_type::eof() && ch != current_[-1])) {
101 return traits_type::eof();
104 return traits_type::to_int_type(*--current_);
106 std::streamsize showmanyc() {
return end_ - current_; }
115 const char*
const begin_;
116 const char*
const end_;
117 const char* current_;
122 membuf(buf, size), std::istream(
static_cast<std::streambuf*
>(
this))
132 char* base = abuf_.data();
133 setp(base, base + bufsize - 1);
136 void reserve(
size_t size) { sbuf_.reserve(size); }
140 std::string retString(std::move(sbuf_));
146 void move_to_string_and_flush()
148 sbuf_.append(pbase(), pptr());
149 std::ptrdiff_t n = pptr() - pbase();
150 pbump(
static_cast<int>(-n));
154 int_type overflow(int_type ch)
156 if (ch != traits_type::eof()) {
157 *pptr() =
static_cast<char>(ch);
159 move_to_string_and_flush();
163 return traits_type::eof();
167 move_to_string_and_flush();
173 ostringbuf(
const ostringbuf&) =
delete;
174 ostringbuf& operator=(
const ostringbuf&) =
delete;
177 static constexpr
size_t bufsize = 64;
178 std::array<char, bufsize> abuf_;
187 ostreambuf(
char* buf,
size_t size) { this->setg(buf, buf, buf + size); }
209 oa(cereal::make_size_tag(
static_cast<cereal::size_type
>(size)));
210 for (
size_t ii = 0; ii < size; ++ii) {
220 template<
typename T,
typename _ =
void>
222 static constexpr
bool value =
false;
227 typename std::enable_if_t<
228 std::is_same<T, std::vector<typename T::value_type, typename T::allocator_type>>::value>> {
229 static constexpr
bool value =
true;
233 template<
typename T,
typename _ =
void>
235 static constexpr
bool value =
false;
240 typename std::enable_if_t<std::is_same<
241 decltype(std::begin(T()) != std::end(T()),
244 void(*std::begin(T())),
246 std::true_type>::value>> {
247 static constexpr
bool value =
true;
252 constexpr std::enable_if_t<!is_iterable<X>::value && !std::is_convertible<X, std::string>::value,
256 return sizeof(X) + 1;
261 constexpr std::enable_if_t<is_iterable<X>::value && !std::is_convertible<X, std::string>::value,
269 constexpr std::enable_if_t<std::is_convertible<X, std::string>::value,
size_t>
getMinSize()
285 convert(vals, size, dv);
301 if (block.
size() < getMinSize<X>()) {
302 std::string arg = std::string(
"invalid data size: expected ") +
303 std::to_string(getMinSize<X>()) +
", received " + std::to_string(block.
size());
304 throw std::invalid_argument(arg);
311 catch (
const cereal::Exception& ce) {
312 throw std::invalid_argument(ce.what());
320 interpret(block, val);