ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
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//==================================================================================================
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.
22template<typename TKey, typename TMapped>
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.
64template<typename T>
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".
106template<typename T, typename TKey>
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]
#define ALIB_EXPORT
MappedType & Mapped(T &src) const
std::pair< TKey, TMapped > StoredType
TKey & Key(std::pair< TKey, TMapped > &src) const
TMapped & Mapped(std::pair< TKey, TMapped > &src) const