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