vdj_pipe
pipeline for processing DNA sequence data
variable_path.hpp
Go to the documentation of this file.
1 
7 #ifndef VDJ_PIPE_VARIABLE_PATH_HPP_
8 #define VDJ_PIPE_VARIABLE_PATH_HPP_
9 #include <algorithm>
10 #include "boost/foreach.hpp"
11 #include "vdj_pipe/config.hpp"
13 #include "vdj_pipe/exception.hpp"
14 #include "vdj_pipe/object_ids.hpp"
15 
16 namespace vdj_pipe{
17 
21 VDJ_PIPE_DECL void
23  std::string const& path,
24  std::vector<std::string>& tv,
25  std::vector<std::string>& nv
26 );
27 
31 VDJ_PIPE_DECL std::string path_assemble(
32  std::vector<std::string> const& templ,
33  detail::Queable_ofstream_types::val_ref_vector const& vals
34 );
35 
39 public:
40  struct Err : public base_exception {};
41 
42  void init(std::string const& path, std::vector<std::string>& nv0) {
43  std::vector<std::string> nv;
44  path_decompose(path, pt_, nv);
45  if( nv0.empty() ) nv0 = nv;
46  ids_.reserve(nv.size());
47  BOOST_FOREACH(std::string s, nv) {
48  std::vector<std::string>::const_iterator i =
49  std::find(nv0.begin(), nv0.end(), s);
50  if( i == nv0.end() ) BOOST_THROW_EXCEPTION(
51  Err()
52  << Err::msg_t("unknown variable")
53  << Err::str1_t(s)
54  );
55  ids_.push_back(Val_id(i - nv0.begin()));
56  }
57  }
58 
59  std::string operator()(
60  detail::Queable_ofstream_types::val_vector const& vals
61  ) const {
62  detail::Queable_ofstream_types::val_ref_vector vr;
63  vr.reserve(ids_.size());
64  BOOST_FOREACH(const Val_id id, ids_) {
65  vr.push_back(boost::cref(vals[id()]));
66  }
67  return path_assemble(pt_, vr);
68  }
69 
70  std::string operator()() const {return pt_.front();}
71  bool empty() const {return pt_.empty();}
72  std::size_t size() const {return pt_.size();}
73 
74 private:
75  std::vector<Val_id> ids_;
76  std::vector<std::string> pt_;
77 };
78 
79 }//namespace vdj_pipe
80 #endif /* VDJ_PIPE_VARIABLE_PATH_HPP_ */
Definition: variable_path.hpp:40
Main namespace of vdj_pipe library.
Definition: sequence_file.hpp:14
VDJ_PIPE_DECL void path_decompose(std::string const &path, std::vector< std::string > &tv, std::vector< std::string > &nv)
separate path into non-name and name areas
Definition: exception.hpp:23
Definition: variable_path.hpp:38
VDJ_PIPE_DECL std::string path_assemble(std::vector< std::string > const &templ, detail::Queable_ofstream_types::val_ref_vector const &vals)
assemble path from template and values