vdj_pipe
pipeline for processing DNA sequence data
file.hpp
Go to the documentation of this file.
1 
7 #ifndef FILE_HPP_
8 #define FILE_HPP_
9 #include <iosfwd>
10 #include <string>
11 #include <utility>
12 #include "vdj_pipe/config.hpp"
14 #include "vdj_pipe/exception.hpp"
16 
17 namespace vdj_pipe{
18 
22 guess_compression_ext(std::string const& path);
23 
27 guess_compression_magic(std::string const& path);
28 
31 VDJ_PIPE_DECL std::pair<compression::Compression, format::Format>
32 guess_compression_format(std::string const& path);
33 
37 guess_format(std::string const& path, const compression::Compression c);
38 
41 VDJ_PIPE_DECL std::string ensure_path_writable(std::string const& path);
42 
47  std::string const& path,
48  std::string const& header
49 );
50 
53 VDJ_PIPE_DECL bool is_path_readable(std::string const& path);
54 
58 VDJ_PIPE_DECL std::string ensure_path_readable(std::string const& path);
59 
62 class File {
63 public:
64  struct Err : public base_exception {};
65 
66  explicit File(
67  std::string const& path,
70  )
71  : path_(path), compr_(compr), fmt_(fmt)
72  {}
73 
74  std::string const& path() const {return path_;}
75  format::Format format() const {return fmt_;}
77  bool operator==(File const& f2) const {return path_ == f2.path_;}
78  bool operator<(File const& f2) const {return path_ < f2.path_;}
80 
81 protected:
82  std::string path_;
85 };
86 
89 VDJ_PIPE_DECL std::size_t hash_value(File const& f);
90 
93 class File_input : public File {
94 public:
95  explicit File_input(std::string const& path)
96  : File(ensure_path_readable(path))
97  {
100  }
101 };
102 
105 class File_output : public File {
106 public:
107 
109  : File("", compression::unknown, fmt)
110  {}
111 
112  explicit File_output(
113  std::string const& path,
115  const format::Format fmt = format::unknown
116  )
117  : File(
118  ensure_path_writable(path),
119  compr == compression::unknown ? guess_compression_ext(path) : compr,
120  fmt == format::unknown ? guess_compression_format(path).second : fmt
121  )
122  {}
123 };
124 
125 }//namespace vdj_pipe
126 #endif /* FILE_HPP_ */
#define VDJ_PIPE_COMPARISON_OPERATOR_MEMBERS(name)
Definition: comparison_operators_macro.hpp:10
bool operator==(File const &f2) const
Definition: file.hpp:77
format::Format format() const
Definition: file.hpp:75
Definition: file.hpp:62
File_output(const format::Format fmt)
Definition: file.hpp:108
compression::Compression guess_compression_ext(bfs::path const &p)
Definition: file.cpp:36
Compression
File compression types.
Definition: file_properties.hpp:19
File_output(std::string const &path, const compression::Compression compr=compression::unknown, const format::Format fmt=format::unknown)
Definition: file.hpp:112
Definition: file.hpp:64
Main namespace of vdj_pipe library.
Definition: keywords_variable.hpp:11
File target is supposed to exist at construction time.
Definition: file.hpp:93
std::string const & path() const
Definition: file.hpp:74
bool operator<(File const &f2) const
Definition: file.hpp:78
#define VDJ_PIPE_DECL
Definition: config.hpp:23
std::string ensure_path_writable(std::string const &path)
create file if does not exist along with parent directories if needed
Definition: file.cpp:104
compression::Compression guess_compression_magic(std::string const &path)
Definition: file.cpp:23
std::string path_
Definition: file.hpp:82
Definition: file_properties.hpp:43
Format
File format types.
Definition: file_properties.hpp:42
bool is_path_readable(std::string const &path)
Definition: file.cpp:132
compression::Compression compr_
Definition: file.hpp:83
std::size_t hash_value(File const &f)
Definition: file.cpp:158
std::string ensure_path_readable(std::string const &path)
Definition: file.cpp:139
std::pair< compression::Compression, format::Format > guess_compression_format(std::string const &path)
Definition: file.cpp:64
Definition: exception.hpp:23
format::Format guess_format(std::string const &path, const compression::Compression c)
Definition: file.cpp:51
File(std::string const &path, const compression::Compression compr=compression::unknown, const format::Format fmt=format::unknown)
Definition: file.hpp:66
File target is created if needed at construction time.
Definition: file.hpp:105
File_input(std::string const &path)
Definition: file.hpp:95
compression::Compression compression() const
Definition: file.hpp:76
format::Format fmt_
Definition: file.hpp:84
Definition: file_properties.hpp:20