SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
load.hpp
1 #include <fstream>
2 #include <vector>
3 
5 #include <cereal/archives/binary.hpp> // includes the cereal::BinaryInputArchive and cereal::BinaryOutputArchive
7 #include <cereal/types/vector.hpp> // includes cerealisation support for std::vector
8 
10 #include <seqan3/test/tmp_filename.hpp>
11 
12 // Written for std::vector, other types also work.
13 void load(std::vector<int16_t> & data, seqan3::test::tmp_filename & tmp_file)
14 {
15  std::ifstream is(tmp_file.get_path(), 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.
21 void store(std::vector<int16_t> const & data, seqan3::test::tmp_filename & tmp_file)
22 {
23  std::ofstream os(tmp_file.get_path(), std::ios::binary); // Where output should be stored.
24  cereal::BinaryOutputArchive archive(os); // Create an ouput archive from the output stream.
25  archive(data); // Store data.
26 }
27 
28 int main()
29 {
30  // The following example is for an 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_filename tmp_file{"data.out"}; // This is a temporary file, use any other filename.
33 
34  std::vector<int16_t> vec{1,2,3,4};
35  store(vec, tmp_file); // Calls store on a std::vector.
36  // This vector is needed to load the information into it.
38  load(vec2, tmp_file); // Calls load on a std::vector.
39 
40  seqan3::debug_stream << vec2 << '\n'; // Prints [1,2,3,4].
41 
42  return 0;
43 }
debug_stream.hpp
Provides seqan3::debug_stream and related types.
fstream
vector
std::ofstream
seqan3::debug_stream
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition: debug_stream.hpp:42
std::ifstream