-
Notifications
You must be signed in to change notification settings - Fork 1
/
proc_containerfwd.H
127 lines (88 loc) · 2.42 KB
/
proc_containerfwd.H
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
** Copyright 2022 Double Precision, Inc.
** See COPYING for distribution information.
*/
#ifndef proc_containerfwd_h
#define proc_containerfwd_h
#include <memory>
class proc_containerObj;
/*! A process container
Once constructed, the container object is immutable.
*/
typedef std::shared_ptr<const proc_containerObj> proc_container;
/*! Helper class used by proc_container_set
Implements a transparent hash function and equality comparison.
Allows proc_container_set to be looked up by a string
*/
template<typename T, typename=void>
struct get_name_for_comparator {
template<typename V>
static auto & name(V &&v)
{
return v;
}
};
/*! Helper class used by proc_container_set
Implements a transparent hash function and equality comparison.
Allows proc_container_set to be looked up by a proc_container.
*/
template<typename T>
struct get_name_for_comparator<T, std::void_t<decltype(std::declval<std::remove_cvref_t<T> &&>()->name)>> {
template<typename V>
static auto &name(V &&v)
{
return v->name;
}
};
/*! Helper class used by proc_new_container_set
Implements a transparent hash function and equality comparison.
Allows proc_new_container_set to be looked up by a proc_new_container.
*/
template<typename T>
struct get_name_for_comparator<T, std::void_t<decltype(std::declval<std::remove_cvref_t<T> &&>()->new_container->name)>> {
template<typename V>
static auto &name(V &&v)
{
return v->new_container->name;
}
};
//! Transparent comparator for proc_container objects.
struct proc_container_equal {
typedef void is_transparent;
template<typename T, typename U>
bool operator()(T &&t, U &&u) const noexcept
{
return get_name_for_comparator<T>::name(
std::forward<T>(t)
) == get_name_for_comparator<U>::name(
std::forward<U>(u)
);
}
};
//! Transparent comparator for proc_container objects.
struct proc_container_less_than {
typedef void is_transparent;
template<typename T, typename U>
bool operator()(T &&t, U &&u) const noexcept
{
return get_name_for_comparator<T>::name(
std::forward<T>(t)
) < get_name_for_comparator<U>::name(
std::forward<U>(u)
);
}
};
//! Transparent hash function for for proc_container objects.
struct proc_container_hash {
typedef void is_transparent;
template<typename T, typename defer=void>
auto operator()(T &&t) const noexcept
{
return std::hash<std::string>{}(
get_name_for_comparator<T>::name(
std::forward<T>(t)
)
);
}
};
#endif