SourceXtractorPlusPlus  0.15
Please provide a description of the project.
PropertyId.h
Go to the documentation of this file.
1 
23 #ifndef _SEFRAMEWORK_PROPERTY_PROPERTYID_H
24 #define _SEFRAMEWORK_PROPERTY_PROPERTYID_H
25 
26 #include <typeindex>
27 #include <string>
28 #include <functional>
29 
30 #include <boost/functional/hash.hpp>
31 
32 namespace SourceXtractor {
33 
40 class PropertyId {
41 public:
44  template<typename T>
45  static PropertyId create(unsigned int index = 0) {
46  return PropertyId(typeid(T), index);
47  }
48 
50  bool operator==(PropertyId other) const {
51  // A PropertyId is equal to another if both their type_id and index are the same
52  return m_type_id == other.m_type_id && m_index == other.m_index;
53  }
54 
56  bool operator<(PropertyId other) const {
57  // if both type_ids are equal, use index as the tie breaker
58  if (m_type_id == other.m_type_id) {
59  return m_index < other.m_index;
60  }
61 
62  // order PropertyIds by their type_ids
63  return m_type_id < other.m_type_id;
64  }
65 
67  return m_type_id;
68  }
69 
70  unsigned int getIndex() const {
71  return m_index;
72  }
73 
74  std::string getString() const;
75 
76 private:
77  PropertyId(std::type_index type_id, unsigned int index) : m_type_id(type_id), m_index(index) {}
78 
80  unsigned int m_index;
81 
82 
83  friend struct std::hash<SourceXtractor::PropertyId>;
84 };
85 
86 }
87 
88 namespace std {
89 
90 // defines a hash for PropertyId, this is to be able to use PropertyId as a key in a std::unordered_map
91 
92 template <>
94 {
96  std::size_t hash = 0;
97  boost::hash_combine(hash, id.m_type_id);
98  boost::hash_combine(hash, id.m_index);
99  return hash;
100  }
101 };
102 
103 }
104 
105 #endif
SourceXtractor::PropertyId::operator<
bool operator<(PropertyId other) const
Less than operator needed to use PropertyId as key in a std::map.
Definition: PropertyId.h:56
std::string
STL class.
std::type_index
SourceXtractor::PropertyId::PropertyId
PropertyId(std::type_index type_id, unsigned int index)
Definition: PropertyId.h:77
SourceXtractor::PropertyId::m_type_id
std::type_index m_type_id
Definition: PropertyId.h:79
SourceXtractor::PropertyId::getTypeId
std::type_index getTypeId() const
Definition: PropertyId.h:66
SourceXtractor::PropertyId
Identifier used to set and retrieve properties.
Definition: PropertyId.h:40
SourceXtractor
Definition: Aperture.h:30
SourceXtractor::PropertyId::m_index
unsigned int m_index
Definition: PropertyId.h:80
SourceXtractor::PropertyId::getIndex
unsigned int getIndex() const
Definition: PropertyId.h:70
std
STL namespace.
SourceXtractor::PropertyId::operator==
bool operator==(PropertyId other) const
Equality operator is needed to be use PropertyId as key in unordered_map.
Definition: PropertyId.h:50
SourceXtractor::PropertyId::create
static PropertyId create(unsigned int index=0)
Definition: PropertyId.h:45
std::size_t
SourceXtractor::PropertyId::getString
std::string getString() const
Definition: PropertyId.cpp:36
std::hash< SourceXtractor::PropertyId >::operator()
std::size_t operator()(const SourceXtractor::PropertyId &id) const
Definition: PropertyId.h:95
std::hash