SeqAn3 3.3.0
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
load.hpp
1#include <fstream>
2#include <vector>
3
5#include <seqan3/test/tmp_directory.hpp>
6
8#include <cereal/archives/binary.hpp> // includes the cereal::BinaryInputArchive and cereal::BinaryOutputArchive
10#include <cereal/types/vector.hpp> // includes cerealisation support for std::vector
11
12// Written for std::vector, other types also work.
13void load(std::vector<int16_t> & data, std::filesystem::path const & tmp_file)
14{
15 std::ifstream is(tmp_file, std::ios::binary); // Where input can be found.
16 cereal::BinaryInputArchive archive(is); // Create an input archive from the input stream.
17 archive(data); // Load data.
18}
19
20// Written for std::vector, other types also work.
21void store(std::vector<int16_t> const & data, std::filesystem::path const & tmp_file)
22{
23 std::ofstream os(tmp_file, std::ios::binary); // Where output should be stored.
24 cereal::BinaryOutputArchive archive(os); // Create an output archive from the output stream.
25 archive(data); // Store data.
26}
27
28int main()
29{
30 // The following example is for a std::vector but any seqan3 data structure that is documented as serialisable
31 // could be used, e.g. seqan3::fm_index.
32 seqan3::test::tmp_directory tmp{};
33 auto tmp_file = tmp.path() / "data.out"; // This is a temporary file name, use any other filename.
34
35 std::vector<int16_t> vec{1, 2, 3, 4};
36 store(vec, tmp_file); // Calls store on a std::vector.
37 // This vector is needed to load the information into it.
39 load(vec2, tmp_file); // Calls load on a std::vector.
40
41 seqan3::debug_stream << vec2 << '\n'; // Prints [1,2,3,4].
42
43 return 0;
44}
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