SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
load.hpp
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: CC0-1.0
4
5#include <fstream>
6#include <vector>
7
9#include <seqan3/test/tmp_directory.hpp>
10
12#include <cereal/archives/binary.hpp> // includes the cereal::BinaryInputArchive and cereal::BinaryOutputArchive
14#include <cereal/types/vector.hpp> // includes cerealisation support for std::vector
15
16// Written for std::vector, other types also work.
17void load(std::vector<int16_t> & data, std::filesystem::path const & tmp_file)
18{
19 std::ifstream is(tmp_file, std::ios::binary); // Where input can be found.
20 cereal::BinaryInputArchive archive(is); // Create an input archive from the input stream.
21 archive(data); // Load data.
22}
23
24// Written for std::vector, other types also work.
25void store(std::vector<int16_t> const & data, std::filesystem::path const & tmp_file)
26{
27 std::ofstream os(tmp_file, std::ios::binary); // Where output should be stored.
28 cereal::BinaryOutputArchive archive(os); // Create an output archive from the output stream.
29 archive(data); // Store data.
30}
31
32int main()
33{
34 // The following example is for a std::vector but any seqan3 data structure that is documented as serialisable
35 // could be used, e.g. seqan3::fm_index.
36 seqan3::test::tmp_directory tmp{};
37 auto tmp_file = tmp.path() / "data.out"; // This is a temporary file name, use any other filename.
38
39 std::vector<int16_t> vec{1, 2, 3, 4};
40 store(vec, tmp_file); // Calls store on a std::vector.
41 // This vector is needed to load the information into it.
43 load(vec2, tmp_file); // Calls load on a std::vector.
44
45 seqan3::debug_stream << vec2 << '\n'; // Prints [1,2,3,4].
46
47 return 0;
48}
Provides seqan3::debug_stream and related types.
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition debug_stream.hpp:37
constexpr void store(void *mem_addr, simd_t const &simd_vec)
Store simd_t size bits of integral data into memory.
Definition algorithm.hpp:374
constexpr simd_t load(void const *mem_addr)
Load simd_t size bits of integral data from memory.
Definition algorithm.hpp:333
Hide me