SeqAn3
3.4.0
The Modern C++ library for sequence analysis.
Toggle main menu visibility
Loading...
Searching...
No Matches
load.hpp
1
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
2
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
3
// SPDX-License-Identifier: CC0-1.0
4
5
#include <
fstream
>
6
#include <
vector
>
7
8
#include <
seqan3/core/debug_stream.hpp
>
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.
17
void
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.
25
void
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
32
int
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.
42
std::vector<int16_t>
vec2;
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
}
std::ifstream
std::ofstream
debug_stream.hpp
Provides seqan3::debug_stream and related types.
fstream
seqan3::debug_stream
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition
debug_stream.hpp:38
std::filesystem::path
vector
Hide me
Version:
doc
howto
use_cereal
load.hpp
Generated on
for SeqAn3 by
1.17.0