fastq_to_fasta
A template for creation of SeqAn3 apps, with a FASTQ to FASTA example app.
sync_out.hpp
Go to the documentation of this file.
1 // --------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2022, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/raptor/blob/main/LICENSE.md
6 // --------------------------------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <filesystem>
11 #include <fstream>
12 #include <mutex>
13 
14 namespace raptor
15 {
16 
17 class sync_out
18 {
19 public:
20  sync_out() = default;
21  sync_out(sync_out const &) = default;
22  sync_out & operator=(sync_out const &) = default;
23  sync_out(sync_out &&) = default;
24  sync_out & operator=(sync_out &&) = default;
25  ~sync_out() = default;
26 
27  sync_out(std::filesystem::path const & path) : file{path}
28  {}
29 
30  template <typename t>
31  void write(t && data)
32  {
33  std::lock_guard<std::mutex> lock(write_mutex);
34  file << std::forward<t>(data);
35  }
36 
37  template <typename t>
38  void operator<<(t && data) // Cannot return a reference to itself since multiple threads write in the meantime.
39  {
40  std::lock_guard<std::mutex> lock(write_mutex);
41  file << std::forward<t>(data);
42  }
43 
44 private:
45  std::ofstream file;
46  std::mutex write_mutex;
47 };
48 
49 } // namespace raptor
Definition: sync_out.hpp:18
sync_out()=default
sync_out(sync_out &&)=default
sync_out & operator=(sync_out const &)=default
sync_out(sync_out const &)=default
void operator<<(t &&data)
Definition: sync_out.hpp:38
~sync_out()=default
void write(t &&data)
Definition: sync_out.hpp:31
sync_out(std::filesystem::path const &path)
Definition: sync_out.hpp:27
sync_out & operator=(sync_out &&)=default
Definition: adjust_seed.hpp:13