diff --git a/lager/extra/cereal/immer_table.hpp b/lager/extra/cereal/immer_table.hpp new file mode 100644 index 00000000..4161487e --- /dev/null +++ b/lager/extra/cereal/immer_table.hpp @@ -0,0 +1,71 @@ +// +// lager - library for functional interactive c++ programs +// Copyright (C) 2017 Juan Pedro Bolivar Puente +// +// This file is part of lager. +// +// lager is free software: you can redistribute it and/or modify +// it under the terms of the MIT License, as detailed in the LICENSE +// file located at the root of this source code distribution, +// or here: +// + +#pragma once + +#include + +#include + +#include +#include +#include + +namespace cereal { +// This code has mostly been adapted from +// We don't deal for now with data that could be potentially serialized +// directly in binary format. + +template +void CEREAL_SAVE_FUNCTION_NAME(Archive& ar, + const immer::table& table) +{ + ar(make_size_tag(static_cast(table.size()))); + for (auto&& v : table) + ar(v); +} + +template +void CEREAL_LOAD_FUNCTION_NAME(Archive& ar, + immer::table& table) +{ + size_type size{}; + ar(make_size_tag(size)); + + if (!size) + return; + + auto t = immer::table{}.transient(); + + for (auto i = size_type{}; i < size; ++i) { + T x; + ar(x); + t.insert(std::move(x)); + } + table = std::move(t).persistent(); + + assert(size == table.size()); +} + +} // namespace cereal diff --git a/nix/deps.nix b/nix/deps.nix index c0515aef..e2300420 100644 --- a/nix/deps.nix +++ b/nix/deps.nix @@ -27,12 +27,12 @@ rec { immer = stdenv.mkDerivation rec { name = "immer-${version}"; version = "git-${commit}"; - commit = "a1271fa712342f5c6dfad876820da17e10c28214"; + commit = "57a8c5ede6f36a8ef9c6e3c82ac6c81f1e5273fd"; src = fetchFromGitHub { owner = "arximboldi"; repo = "immer"; rev = commit; - sha256 = "1bqkinkbp1b1aprg7ydfrbfs7gi779nypwvh9fj129frq1c2rxw5"; + sha256 = "D6QiTeOoBUJScQQl/e1jq4n+ORTzYnKg7LKTP6xacM4"; }; dontUseCmakeBuildDir = true; nativeBuildInputs = [ cmake ]; diff --git a/test/cereal/immer_table.cpp b/test/cereal/immer_table.cpp new file mode 100644 index 00000000..bf76aa5d --- /dev/null +++ b/test/cereal/immer_table.cpp @@ -0,0 +1,29 @@ +// +// lager - library for functional interactive c++ programs +// Copyright (C) 2017 Juan Pedro Bolivar Puente +// +// This file is part of lager. +// +// lager is free software: you can redistribute it and/or modify +// it under the terms of the MIT License, as detailed in the LICENSE +// file located at the root of this source code distribution, +// or here: +// + +#include "cerealize.hpp" +#include +#include + +struct entry_t +{ + size_t id; + size_t value; +}; + +TEST_CASE("basic") +{ + auto x = immer::table{{.id = 1, .value = 2}, // + {.id = 3, .value = 4}}; + auto y = cerealize(x); + CHECK(x == y); +}