vdj_pipe
pipeline for processing DNA sequence data
file_ostream_queue.hpp
Go to the documentation of this file.
1 
7 #ifndef FILE_OSTREAM_QUEUE_HPP_
8 #define FILE_OSTREAM_QUEUE_HPP_
9 #include <iosfwd>
10 #include "boost/multi_index_container.hpp"
11 #include "boost/multi_index/hashed_index.hpp"
12 #include "boost/multi_index/member.hpp"
13 #include "boost/multi_index/sequenced_index.hpp"
14 #include "boost/range.hpp"
15 #include "boost/shared_ptr.hpp"
16 #include "vdj_pipe/config.hpp"
18 #include "vdj_pipe/exception.hpp"
19 #include "vdj_pipe/file_stream.hpp"
20 
21 namespace vdj_pipe{
22 
25 struct VDJ_PIPE_DECL Queable_ofstream {
26  typedef detail::Queable_ofstream_types::value_type value_type;
27  typedef detail::Queable_ofstream_types::val_vector val_vector;
28  typedef detail::Queable_ofstream_types::val_ref_vector val_ref_vector;
29  typedef detail::Queable_ofstream_types::path_template path_template;
30 
31  struct Err : public base_exception {};
32 
33  static std::string make_path(
34  path_template const& templ,
35  val_ref_vector const& vals,
36  std::string const& header
37  );
38 
40  path_template const& templ,
41  val_ref_vector const& vals,
42  const format::Format fmt,
43  std::string const& header
44  );
45 
46  val_vector sv_;
47  mutable File_ostream fos_;
48 };
49 
50 
53 class VDJ_PIPE_DECL File_ostream_queue {
54  typedef detail::Queable_ofstream_types::val_vector val_vector;
55  typedef detail::Queable_ofstream_types::path_template path_template;
56 
57  typedef boost::multi_index_container<
59  boost::multi_index::indexed_by<
60  boost::multi_index::sequenced<>,
61  boost::multi_index::hashed_unique<
62  boost::multi_index::member<
63  Queable_ofstream, val_vector, &Queable_ofstream::sv_
64  >
65  >
66  >
67  > map_t;
68  typedef map_t::iterator seq_iterator;
69  typedef map_t::nth_index<1>::type index;
70  typedef index::iterator hash_iterator;
71  typedef index::const_iterator hash_citerator;
72 
73 public:
74  typedef detail::Queable_ofstream_types::val_ref_vector val_ref_vector;
75  typedef detail::Queable_ofstream_types::value_type value_type;
76 
77  struct Err : public base_exception {};
78 
79  template<class Range> explicit File_ostream_queue(
80  Range const& r,
81  std::string const& header = "",
82  const format::Format fmt = format::unknown,
83  const std::size_t sz = 100
84  )
85  : pt_(boost::begin(r), boost::end(r)),
86  header_(header),
87  vm_(),
88  fmt_(
89  fmt == format::unknown ?
90  guess_compression_format(pt_.back()).second :
91  fmt
92  ),
93  sz_(sz)
94  {}
95 
96  File_ostream& ostream(val_ref_vector const& v);
97  std::size_t size() const {return vm_.size();}
98 
99 private:
100  path_template pt_;
101  std::string header_;
102  map_t vm_;
103  format::Format fmt_;
104  std::size_t sz_;
105 };
106 
107 }//namespace vdj_pipe
108 #endif /* FILE_OSTREAM_QUEUE_HPP_ */
Format
File format types.
Definition: file_properties.hpp:42
Definition: file_ostream_queue.hpp:31
Main namespace of vdj_pipe library.
Definition: sequence_file.hpp:14
VDJ_PIPE_DECL std::pair< compression::Compression, format::Format > guess_compression_format(std::string const &path)
Definition: file_ostream_queue.hpp:25
Definition: file_ostream_queue.hpp:77
stack of recently used output file streams
Definition: file_ostream_queue.hpp:53
Definition: exception.hpp:23
Definition: file_stream.hpp:24