vdj_pipe
pipeline for processing DNA sequence data
value_variant.hpp
Go to the documentation of this file.
1 
7 #ifndef VALUE_VARIANT_HPP_
8 #define VALUE_VARIANT_HPP_
9 #include <iosfwd>
10 #include "boost/array.hpp"
11 #include "boost/mpl/begin.hpp"
12 #include "boost/mpl/distance.hpp"
13 #include "boost/mpl/find.hpp"
14 #include "boost/mpl/size.hpp"
15 #include "boost/variant.hpp"
16 #include "vdj_pipe/config.hpp"
17 #include "vdj_pipe/object_ids.hpp"
20 
21 namespace vdj_pipe{
22 
25 struct Blank {
26  bool operator==(Blank const&) const {return true;}
27  bool operator<(Blank const&) const {return false;}
28 };
29 
32 inline std::size_t hash_value(Blank const&) {return 0xd5d6573673acc2a3;}
33 
36 template<class ChT, class Tr> inline
37 std::basic_ostream<ChT,Tr>& operator<<(
38  std::basic_ostream<ChT,Tr>& os,
39  Blank const&
40 ) {
41  return os << "Undetermined";
42 }
43 
46 typedef boost::variant<
47  Blank, bool, long, double, std::string,
48  sequence_interval, Qual_record::quality
49  >
50 value_variant;
51 
54 inline std::string const& variable_type_str(const int which) {
55  typedef boost::array<
56  std::string,
57  boost::mpl::size<value_variant::types>::value
58  > array;
59  static const array a =
60  {{
61  "blank", "bool", "integer", "float", "string",
62  "interval", "quality"
63  }};
64  return a[which];
65 }
66 
69 template<typename T> struct Type_index :
70  boost::mpl::distance<
71  typename boost::mpl::begin<value_variant::types>::type,
72  typename boost::mpl::find<value_variant::types,T>::type
73  >::type
74  {};
75 
78 inline bool is_blank(value_variant const& vv) {
79  return boost::get<Blank>(&vv);
80 }
81 
82 namespace detail{
83 
84 struct Type_name : public boost::static_visitor<std::string const&> {
85  template<typename T>
86  std::string const& operator()(T const&) const {
87  return variable_type_str(Type_index<T>::value);
88  }
89 };
90 
91 }//namespace detail
92 
95 inline std::string const& variable_type_str(value_variant const& vv) {
96  return boost::apply_visitor(detail::Type_name(), vv);
97 }
98 
101 VDJ_PIPE_DECL value_variant parse_variant(std::string const& s);
102 
103 }//namespace vdj_pipe
104 #endif /* VALUE_VARIANT_HPP_ */
Definition: value_variant.hpp:69
Definition: sequence_record.hpp:35
Main namespace of vdj_pipe library.
Definition: sequence_file.hpp:14
Definition: value_variant.hpp:84
Definition: value_variant.hpp:25