SourceXtractorPlusPlus
0.12
Please provide a description of the project.
SEFramework
SEFramework
Property
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
66
std::type_index
getTypeId
()
const
{
67
return
m_type_id
;
68
}
69
70
unsigned
int
getIndex
()
const
{
71
return
m_index
;
72
}
73
74
std::string
getString
()
const
{
75
std::stringstream
property_name;
76
property_name <<
m_type_id
.
name
() <<
" [ "
<<
m_index
<<
" ] "
;
77
return
property_name.
str
();
78
}
79
80
private
:
81
PropertyId
(
std::type_index
type_id,
unsigned
int
index) :
m_type_id
(type_id),
m_index
(index) {}
82
83
std::type_index
m_type_id
;
84
unsigned
int
m_index
;
85
86
87
friend
struct
std::hash
<
SourceXtractor
::
PropertyId
>;
88
};
89
90
}
91
92
namespace
std
{
93
94
// defines a hash for PropertyId, this is to be able to use PropertyId as a key in a std::unordered_map
95
96
template
<>
97
struct
hash
<
SourceXtractor
::
PropertyId
>
98
{
99
std::size_t
operator()
(
const
SourceXtractor::PropertyId
&
id
)
const
{
100
std::size_t
hash
= 0;
101
boost::hash_combine(
hash
,
id
.
m_type_id
);
102
boost::hash_combine(
hash
,
id
.
m_index
);
103
return
hash
;
104
}
105
};
106
107
}
108
109
#endif
SourceXtractor::PropertyId::m_index
unsigned int m_index
Definition:
PropertyId.h:84
SourceXtractor::PropertyId::getIndex
unsigned int getIndex() const
Definition:
PropertyId.h:70
std
STL namespace.
std::hash< SourceXtractor::PropertyId >::operator()
std::size_t operator()(const SourceXtractor::PropertyId &id) const
Definition:
PropertyId.h:99
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
std::size_t
std::stringstream
STL class.
SourceXtractor::PropertyId::create
static PropertyId create(unsigned int index=0)
Definition:
PropertyId.h:45
SourceXtractor::PropertyId::getString
std::string getString() const
Definition:
PropertyId.h:74
std::string
STL class.
SourceXtractor
Definition:
Aperture.h:30
std::hash
std::type_index
std::stringstream::str
T str(T... args)
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::type_index::name
T name(T... args)
SourceXtractor::PropertyId
Identifier used to set and retrieve properties.
Definition:
PropertyId.h:40
SourceXtractor::PropertyId::PropertyId
PropertyId(std::type_index type_id, unsigned int index)
Definition:
PropertyId.h:81
SourceXtractor::PropertyId::m_type_id
std::type_index m_type_id
Definition:
PropertyId.h:83
SourceXtractor::PropertyId::getTypeId
std::type_index getTypeId() const
Definition:
PropertyId.h:66
Generated by
1.8.14