vdj_pipe
pipeline for processing DNA sequence data
object_id_base.hpp
Go to the documentation of this file.
1 
7 #ifndef OBJECT_ID_BASE_HPP_
8 #define OBJECT_ID_BASE_HPP_
9 #include <iosfwd>
10 #include "boost/cstdint.hpp"
11 
12 namespace vdj_pipe{
13 template<class Id> class Id_iterator;
14 namespace detail{
15 
18 template<class Super, class Val = boost::uint_least32_t> class Base_id {
19  friend class Id_iterator<Super>;
20  typedef Base_id self_type;
21 protected:
22  typedef Base_id base;
23 public:
24  typedef Val value_type;
25  explicit Base_id(const value_type val) : val_(val) {}
26  Base_id(Super const& s) : val_(s.val_) {}
27  bool operator==(const Super& t) const {return val_ == t.val_;}
28  bool operator<(const Super& t) const {return val_< t.val_;}
29  bool operator<=(const Super& t) const {return val_<= t.val_;}
30  bool operator>(const Super& t) const {return val_ > t.val_;}
31  bool operator>=(const Super& t) const {return val_ >= t.val_;}
32  bool operator!=(const Super& t) const {return val_ != t.val_;}
33  value_type operator()() const {return val_;}
34 private:
35  typedef value_type self_type::*unspecified_bool_type; //ptr to member
36 public:
37  //"safe bool idiom"
38  operator unspecified_bool_type() const {return val_ == 0 ? 0 : &self_type::val_;}
39 protected:
40  value_type val_;
41 };
42 
45 template<class ChT, class Tr, class S, class V> inline
46 std::basic_ostream<ChT,Tr>& operator<<(
47  std::basic_ostream<ChT,Tr>& os,
48  Base_id<S,V> const& id
49 ) {
50  return os << id();
51 }
52 
55 template<class S,class V> inline std::size_t hash_value(Base_id<S,V> const& id) {
56  return id();
57 }
58 
59 }//namespace detail
60 }//namespace vdj_pipe
61 
62 #define VDJ_PIPE_OBJECT_ID(name) \
63  struct name : public ::vdj_pipe::detail::Base_id<name> { \
64  explicit name(const value_type x) : base(x) {} \
65  name() : base(0) {} \
66  } \
67 /* */
68 
69 #endif /* OBJECT_ID_BASE_HPP_ */
Definition: object_id_base.hpp:18
Main namespace of vdj_pipe library.
Definition: sequence_file.hpp:14
Definition: id_iterator.hpp:16