BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
store.hpp
1#include <fstream>
2#include <vector>
3
5#include <cereal/archives/binary.hpp> // includes the cereal::BinaryOutputArchive
8#include <cereal/types/vector.hpp> // includes cerealisation support for std::vector
10
11#include <bio/test/tmp_filename.hpp>
12
13// Written for std::vector, other types also work.
14void store(std::vector<int16_t> const & data, bio::test::tmp_filename & tmp_file)
15{
16 std::ofstream os(tmp_file.get_path(), std::ios::binary); // Where output should be stored.
17 cereal::BinaryOutputArchive archive(os); // Create an ouput archive from the output stream.
18 archive(data); // Store data.
19}
20
21int main()
22{
23 // The following example is for an std::vector but any bio data structure that is documented as serialisable
24 // could be used, e.g. bio::alphabet::fm_index.
25 bio::test::tmp_filename tmp_file{"data.out"}; // This is a temporary file, use any other filename.
26
27 std::vector<int16_t> vec{1,2,3,4};
28 store(vec, tmp_file); // Calls store on a std::vector.
29
30 return 0;
31}