vdj_pipe
pipeline for processing DNA sequence data
file_stream.hpp
Go to the documentation of this file.
1 
7 #ifndef FILE_STREAM_HPP_
8 #define FILE_STREAM_HPP_
9 #include <string>
10 #include <fstream>
11 #include "boost/iostreams/filtering_streambuf.hpp"
12 #include "boost/scoped_ptr.hpp"
13 #include "boost/utility/string_ref.hpp"
14 #include "vdj_pipe/config.hpp"
15 #include "vdj_pipe/exception.hpp"
16 #include "vdj_pipe/file.hpp"
18 
19 namespace vdj_pipe{
20 class File_output;
21 
24 class VDJ_PIPE_DECL File_ostream : public File_output {
25  typedef boost::scoped_ptr<std::ofstream> ofs_ptr;
26  typedef boost::scoped_ptr<std::ostream> os_ptr;
27  typedef boost::iostreams::filtering_ostreambuf fosb_t;
28  typedef boost::scoped_ptr<fosb_t> fosb_ptr;
29 
30  static fosb_t* make_fosb(
31  std::ostream& os,
32  const compression::Compression compr
33  );
34 
35  static std::ios_base::openmode guess_mode(
36  const std::ios_base::openmode mode,
37  const compression::Compression compr
38  );
39 
40 public:
41  struct Err : public base_exception {};
42 
43  File_ostream(const format::Format fmt);
44 
45  explicit File_ostream(
46  File_output const& fout,
47  const std::ios_base::openmode mode = (std::ios_base::openmode)0
48  );
49 
50  std::ostream& ostream() {return os_;}
51 
52  void write(
53  std::string const& descr,
54  Seq_record::sequence const& seq
55  );
56 
57  void write(
58  std::string const& descr,
59  const boost::string_ref seq
60  );
61 
62  void write(
63  std::string const& descr,
64  Qual_record::quality const& qual
65  );
66 
67  void write(
68  std::string const& descr,
69  Seq_record::sequence const& seq,
70  Qual_record::quality const& qual
71  );
72 
73 private:
74  ofs_ptr ofs_;
75  fosb_ptr fosb_;
76  os_ptr fosb_os_;
77  std::ostream& os_;
78 };
79 
82 class VDJ_PIPE_DECL File_istream {
83  typedef boost::scoped_ptr<std::istream> is_ptr;
84  typedef boost::scoped_ptr<std::ifstream> ifs_ptr;
85  typedef boost::iostreams::filtering_istreambuf fisb_t;
86  typedef boost::scoped_ptr<fisb_t> fisb_ptr;
87 
88  static fisb_t* make_fisb(
89  std::istream& is,
90  const compression::Compression compr
91  );
92 
93 public:
94  struct Err : public base_exception {};
95  explicit File_istream(File_input const& fin);
96 
97  explicit File_istream(
98  std::istream& is,
99  const compression::Compression compr = compression::none
100  );
101 
102  std::istream& istream() {return is_;}
103  bool good() const {return is_;}
104 
105 private:
106  ifs_ptr ifs_;
107  fisb_ptr fisb_;
108  is_ptr fisb_is_;
109  std::istream& is_;
110 };
111 
112 }//namespace vdj_pipe
113 #endif /* FILE_STREAM_HPP_ */
Format
File format types.
Definition: file_properties.hpp:42
Definition: file_stream.hpp:82
Definition: sequence_record.hpp:35
Definition: file_stream.hpp:94
Compression
File compression types.
Definition: file_properties.hpp:19
Main namespace of vdj_pipe library.
Definition: sequence_file.hpp:14
File target is supposed to exist at construction time.
Definition: file.hpp:93
Definition: file_stream.hpp:41
Definition: exception.hpp:23
Definition: file_stream.hpp:24
File target is created if needed at construction time.
Definition: file.hpp:105