ALib C++ Library
by
Library Version:
2510 R0
Documentation generated by
Loading...
Searching...
No Matches
home
dev
A-Worx
ALib
src
alib
containers
valuedescriptor.inl
Go to the documentation of this file.
1
//==================================================================================================
2
/// \file
3
/// This header-file is part of module \alib_containers of the \aliblong.
4
///
5
/// \emoji :copyright: 2013-2025 A-Worx GmbH, Germany.
6
/// Published under \ref mainpage_license "Boost Software License".
7
//==================================================================================================
8
ALIB_EXPORT
namespace
alib::containers
{
9
10
/// Implements template type \p{TValueDescriptor}, which is, for example, offered by types
11
/// \alib{containers;HashTable} and \alib{containers;LRUCacheTable}.
12
///
13
/// Specifically, this implementation is used when the custom type to be stored with a container
14
/// should be associated to a \p{TKkey}-type, which is not included in the stored type itself.
15
/// Consequently, to associate custom type \p{TMapped} with the key, the #StoredType
16
/// results in <c>std::pair<TKey,TMapped</c>.
17
///
18
/// Type definitions \alib{containers;HashMap} and \alib{containers;LRUCacheMap}
19
/// establish a shortcut to their corresponding base type, which incorporates this helper.
20
/// @tparam TKey The key type.
21
/// @tparam TMapped The type of the mapped objects.
22
template
<
typename
TKey,
typename
TMapped>
23
struct
TPairDescriptor
24
{
25
/// The type stored in the container.<br>
26
/// Container types typically publish an alias to this type.
27
/// For example, see \alib{containers::LRUCacheTable;StoredType}, or
28
/// see \alib{containers::HashTable;StoredType}.
29
using
StoredType
= std::pair<TKey, TMapped>;
30
31
/// The key type. (Exposes template parameter \p{TKey}).<br>
32
/// Container types typically publish an alias to this type.
33
/// For example, see \alib{containers::LRUCacheTable;KeyType}, or
34
/// see \alib{containers::HashTable;KeyType}.
35
using
KeyType
= TKey;
36
37
/// The type associated to a key. (Exposes template parameter \p{TMapped}).
38
/// The type of the mapped portion of the data.<br>
39
/// Container types typically publish an alias to this type.
40
/// For example, see \alib{containers::LRUCacheTable;MappedType}, or
41
/// see \alib{containers::HashTable;MappedType}.
42
using
MappedType
= TMapped;
43
44
/// Returns the first element of the given <c>std::pair</c>.
45
/// @param src The value to extract from.
46
/// @return The key-portion of the given value.
47
TKey&
Key
(std::pair<TKey, TMapped>& src)
const
{
return
src.first; }
48
49
/// Returns the second element of the given <c>std::pair</c>.
50
/// @param src The value to extract from.
51
/// @return The mapped-portion of the given value.
52
TMapped&
Mapped
(std::pair<TKey, TMapped>& src)
const
{
return
src.second; }
53
};
54
55
/// Implements template type \p{TValueDescriptor}, which is, for example, offered by types
56
/// \alib{containers;HashTable} and \alib{containers;LRUCacheTable}.
57
///
58
/// Specifically, this implementation is used with "sets", hence cases where the full portion
59
/// of a type that is to be stored in a container should serve as the key to itself.
60
///
61
/// Type definitions \alib{containers;HashSet} and \alib{containers;LRUCacheSet}
62
/// establish a shortcut to their corresponding base type, which incorporates this helper.
63
///
64
/// @tparam T The type stored in the container, serving likewise as the key-type.
65
template
<
typename
T>
66
struct
TIdentDescriptor
67
{
68
/// The type stored in the container.<br>
69
/// Container types typically publish an alias to this type.
70
/// For example, see \alib{containers::LRUCacheTable;StoredType}, or
71
/// see \alib{containers::HashTable;StoredType}.
72
using
StoredType
= T;
73
74
/// Exposes template parameter \p{T} and thus equals #StoredType and
75
/// #MappedType.<br>
76
/// Container types typically publish an alias to this type.
77
/// For example, see \alib{containers::LRUCacheTable;KeyType}, or
78
/// see \alib{containers::HashTable;KeyType}.
79
using
KeyType
= T;
80
81
/// Exposes template parameter \p{T} and thus equals #StoredType and
82
/// #KeyType.<br>
83
/// Container types typically publish an alias to this type.
84
/// For example, see \alib{containers::LRUCacheTable;MappedType}, or
85
/// see \alib{containers::HashTable;MappedType}.
86
using
MappedType
= T;
87
88
/// Returns the given \p{src} as is.
89
/// @param src The value to extract from.
90
/// @return The given reference.
91
KeyType
&
Key
(T& src)
const
{
return
src; }
92
93
/// Returns the given \p{src} as is.
94
/// @param src The value to extract from.
95
/// @return The given reference.
96
MappedType
&
Mapped
(T& src)
const
{
return
src; }
97
};
98
99
100
/// Implements template type \p{TValueDescriptor}, which is, for example, offered by types
101
/// \alib{containers;HashTable} and \alib{containers;LRUCacheTable}.
102
///
103
/// Specifically, this implementation causes a container neither to add a specific key-type to
104
/// every stored custom object nor to expect instances of a custom object as the key-type itself.
105
/// Instead, only a subset of the custom type is used as the key-type.
106
/// @tparam T The type stored in the container.
107
/// @tparam TKey The key type which is to be extracted out of \p{T} by method #Key.
108
template
<
typename
T,
typename
TKey>
109
struct
TSubsetKeyDescriptor
110
{
111
/// Exposes template parameter \p{T}.<br>
112
/// Container types typically publish an alias to this type.
113
/// For example, see \alib{containers::LRUCacheTable;StoredType}, or
114
/// see \alib{containers::HashTable;StoredType}.
115
using
StoredType
= T;
116
117
/// Exposes template parameter \p{TKey}.<br>
118
/// Container types typically publish an alias to this type.
119
/// For example, see \alib{containers::LRUCacheTable;KeyType}, or
120
/// see \alib{containers::HashTable;KeyType}.
121
using
KeyType
= TKey;
122
123
/// Exposes template parameter \p{T} and thus equals #StoredType.<br>
124
/// Container types typically publish an alias to this type.
125
/// For example, see \alib{containers::LRUCacheTable;MappedType}, or
126
/// see \alib{containers::HashTable;MappedType}.
127
using
MappedType
= T;
128
129
/// A custom implementation has to return the key-portion of given \p{src}.
130
/// \attention This method is just declared. A type-specific implementation has to be
131
/// provided by the using code!
132
/// @param src The stored value to extract the key from.
133
/// @return The given reference.
134
KeyType
&
Key
(T& src);
135
136
/// Returns the given \p{src} as is.
137
/// @param src The stored value to extract the mapped portion from.
138
/// @return The given reference.
139
MappedType
&
Mapped
(T& src)
const
{
return
src; }
140
};
141
142
}
// namespace [alib::containers]
143
ALIB_EXPORT
#define ALIB_EXPORT
Definition
alib.inl:488
alib::containers
Definition
hashtablebase.cpp:25
alib::containers::TIdentDescriptor
Definition
valuedescriptor.inl:67
alib::containers::TIdentDescriptor::StoredType
T StoredType
Definition
valuedescriptor.inl:72
alib::containers::TIdentDescriptor::KeyType
T KeyType
Definition
valuedescriptor.inl:79
alib::containers::TIdentDescriptor::Key
KeyType & Key(T &src) const
Definition
valuedescriptor.inl:91
alib::containers::TIdentDescriptor::MappedType
T MappedType
Definition
valuedescriptor.inl:86
alib::containers::TIdentDescriptor::Mapped
MappedType & Mapped(T &src) const
Definition
valuedescriptor.inl:96
alib::containers::TPairDescriptor
Definition
valuedescriptor.inl:24
alib::containers::TPairDescriptor::StoredType
std::pair< TKey, TMapped > StoredType
Definition
valuedescriptor.inl:29
alib::containers::TPairDescriptor::MappedType
TMapped MappedType
Definition
valuedescriptor.inl:42
alib::containers::TPairDescriptor::Key
TKey & Key(std::pair< TKey, TMapped > &src) const
Definition
valuedescriptor.inl:47
alib::containers::TPairDescriptor::Mapped
TMapped & Mapped(std::pair< TKey, TMapped > &src) const
Definition
valuedescriptor.inl:52
alib::containers::TPairDescriptor::KeyType
TKey KeyType
Definition
valuedescriptor.inl:35
alib::containers::TSubsetKeyDescriptor
Definition
valuedescriptor.inl:110
alib::containers::TSubsetKeyDescriptor::MappedType
T MappedType
Definition
valuedescriptor.inl:127
alib::containers::TSubsetKeyDescriptor::StoredType
T StoredType
Definition
valuedescriptor.inl:115
alib::containers::TSubsetKeyDescriptor::KeyType
TKey KeyType
Definition
valuedescriptor.inl:121
alib::containers::TSubsetKeyDescriptor::Key
KeyType & Key(T &src)
alib::containers::TSubsetKeyDescriptor::Mapped
MappedType & Mapped(T &src) const
Definition
valuedescriptor.inl:139