SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
PropertyId.h
Go to the documentation of this file.
1
22
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
32namespace SourceXtractor {
33
39
41public:
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
76private:
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
88namespace 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
92template <>
93struct hash<SourceXtractor::PropertyId>
94{
96 std::size_t h = 0;
97 boost::hash_combine(h, id.m_type_id);
98 boost::hash_combine(h, id.m_index);
99 return h;
100 }
101};
102
103}
104
105#endif
Identifier used to set and retrieve properties.
Definition PropertyId.h:40
PropertyId(std::type_index type_id, unsigned int index)
Definition PropertyId.h:77
static PropertyId create(unsigned int index=0)
Definition PropertyId.h:45
bool operator<(PropertyId other) const
Less than operator needed to use PropertyId as key in a std::map.
Definition PropertyId.h:56
std::string getString() const
unsigned int getIndex() const
Definition PropertyId.h:70
std::type_index m_type_id
Definition PropertyId.h:79
std::type_index getTypeId() const
Definition PropertyId.h:66
bool operator==(PropertyId other) const
Equality operator is needed to be use PropertyId as key in unordered_map.
Definition PropertyId.h:50
STL namespace.
std::size_t operator()(const SourceXtractor::PropertyId &id) const
Definition PropertyId.h:95