gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
type_index.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
16 
17 #ifndef TYPE_INDEX_HPP
18 #define TYPE_INDEX_HPP
19 
20 #include <typeinfo>
21 #include <functional>
22 #include <string>
23 
24 namespace Gambit
25 {
26  struct type_index
27  {
28  public:
29  friend struct type_equal_to;
30  friend struct std::equal_to<Gambit::type_index>;
31 
32  type_index(const std::type_info& __rhs)
33  : _M_target(&__rhs) { }
34 
36 
37  const std::type_info &operator=(const std::type_info& __rhs)
38  {return *(_M_target = &__rhs);}
39 
40  bool operator==(const Gambit::type_index& __rhs) const
41  { return *_M_target == *__rhs._M_target; }
42 
43  bool operator!=(const Gambit::type_index& __rhs) const
44  { return *_M_target != *__rhs._M_target; }
45 
46  bool operator<(const Gambit::type_index& __rhs) const
47  { return _M_target->before(*__rhs._M_target); }
48 
49  bool operator<=(const Gambit::type_index& __rhs) const
50  { return !__rhs._M_target->before(*_M_target); }
51 
52  bool operator>(const Gambit::type_index& __rhs) const
53  { return __rhs._M_target->before(*_M_target); }
54 
55  bool operator>=(const Gambit::type_index& __rhs) const
56  { return !_M_target->before(*__rhs._M_target); }
57 
58  size_t hash_code() const
59  //{ return _M_target->hash_code(); }
60  { return std::hash<std::string>().operator()(_M_target->name()); }
61 
62  const char* name() const
63  { return _M_target->name(); }
64 
65  private:
66  const std::type_info* _M_target;
67  };
68 
69  struct type_hasher
70  {
71  std::size_t operator()(const Gambit::type_index& code) const
72  {
73  return code.hash_code();
74  }
75  };
76 
77  struct type_equal_to
78  {
79  bool operator()(const Gambit::type_index& lhs, const Gambit::type_index& rhs) const
80  {
81  return *lhs._M_target == *rhs._M_target;
82  }
83  };
84 }
85 
86 namespace std
87 {
88  template<>
89  struct hash<Gambit::type_index>
90  {
91  size_t operator()(const Gambit::type_index& __ti) const
92  { return __ti.hash_code(); }
93  };
94 
95  template<>
96  struct equal_to<Gambit::type_index>
97  {
98  size_t operator()(const Gambit::type_index& lhs, const Gambit::type_index& rhs) const
99  { return *lhs._M_target == *rhs._M_target; }
100  };
101 }
102 
103 #endif
bool operator<=(const Gambit::type_index &__rhs) const
Definition: type_index.hpp:49
bool operator>(const Gambit::type_index &__rhs) const
Definition: type_index.hpp:52
const std::type_info * _M_target
Definition: type_index.hpp:66
STL namespace.
bool operator==(const Gambit::type_index &__rhs) const
Definition: type_index.hpp:40
bool operator>=(const Gambit::type_index &__rhs) const
Definition: type_index.hpp:55
size_t hash_code() const
Definition: type_index.hpp:58
size_t operator()(const Gambit::type_index &lhs, const Gambit::type_index &rhs) const
Definition: type_index.hpp:98
size_t operator()(const Gambit::type_index &__ti) const
Definition: type_index.hpp:91
bool operator()(const Gambit::type_index &lhs, const Gambit::type_index &rhs) const
Definition: type_index.hpp:79
bool operator<(const Gambit::type_index &__rhs) const
Definition: type_index.hpp:46
const std::type_info & operator=(const std::type_info &__rhs)
Definition: type_index.hpp:37
bool operator!=(const Gambit::type_index &__rhs) const
Definition: type_index.hpp:43
std::size_t operator()(const Gambit::type_index &code) const
Definition: type_index.hpp:71
TODO: see if we can use this one:
Definition: Analysis.hpp:33
const char * name() const
Definition: type_index.hpp:62