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,
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()(
61  ) const {
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
bool empty() const
Definition: variable_path.hpp:71
std::size_t size() const
Definition: variable_path.hpp:72
std::vector< Val_id > ids_
Definition: variable_path.hpp:75
std::vector< std::string > pt_
Definition: variable_path.hpp:76
std::string operator()() const
Definition: variable_path.hpp:70
std::string operator()(detail::Queable_ofstream_types::val_vector const &vals) const
Definition: variable_path.hpp:59
Main namespace of vdj_pipe library.
Definition: keywords_variable.hpp:11
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: variable_path.cpp:18
void init(std::string const &path, std::vector< std::string > &nv0)
Definition: variable_path.hpp:42
#define VDJ_PIPE_DECL
Definition: config.hpp:23
std::vector< value_type > val_vector
Definition: queable_ofstream_types.hpp:20
boost::error_info< struct errinfo_str1_, std::string > str1_t
Definition: exception.hpp:25
Definition: exception.hpp:23
boost::error_info< struct errinfo_message_, std::string > msg_t
Definition: exception.hpp:24
Definition: variable_path.hpp:38
std::vector< boost::reference_wrapper< value_type const > > val_ref_vector
Definition: queable_ofstream_types.hpp:23
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
Definition: variable_path.cpp:69