CatapultServer
v0.5.0.1 (Elephant)
|
Go to the documentation of this file.
32 namespace catapult {
namespace cache {
35 template<
typename TSet>
53 template<
typename TSet,
typename TCacheDescriptor>
56 using KeyType =
typename TCacheDescriptor::KeyType;
66 return m_set.contains(key);
74 template<
typename TSet>
117 template<
typename TCacheDescriptor,
typename T>
120 std::ostringstream out;
121 out <<
"value with key '" << key <<
"' is " << keyState <<
" in cache (" <<
TCacheDescriptor::Name <<
")";
125 template<
typename TCacheDescriptor,
size_t N>
131 template<
typename TValue>
135 static TValue&
Adapt(TValue& value) {
141 template<
typename TCacheDescriptor,
typename TValueAdapter,
typename TBaseSetIterator,
typename TValue>
144 using KeyType =
typename TCacheDescriptor::KeyType;
162 detail::ThrowInvalidKeyError<TCacheDescriptor>(
"not",
m_key);
169 auto pValue =
m_iter.get();
170 return pValue ? &TValueAdapter::Adapt(*pValue) :
nullptr;
175 auto pValue =
m_iter.get();
188 typename TCacheDescriptor,
192 using KeyType =
typename TCacheDescriptor::KeyType;
193 using ValueType =
typename TValueAdapter::AdaptedValueType;
208 auto setIter =
m_set.find(key);
220 typename TCacheDescriptor,
224 using KeyType =
typename TCacheDescriptor::KeyType;
225 using ValueType =
typename TValueAdapter::AdaptedValueType;
240 auto setIter =
m_set.find(key);
241 return iterator(std::move(setIter), key);
249 template<
typename TSet,
typename TCacheDescriptor>
252 using KeyType =
typename TCacheDescriptor::KeyType;
262 auto iter =
m_set.find(key);
263 const auto* pValue = iter.get();
264 return pValue && pValue->isActive(height);
272 template<
typename TSet,
typename TCacheDescriptor>
275 using KeyType =
typename TCacheDescriptor::KeyType;
286 auto result =
m_set.insert(value);
291 detail::ThrowInvalidKeyError<TCacheDescriptor>(
"already", TCacheDescriptor::GetKeyFromValue(value));
296 auto result =
m_set.remove(key);
301 detail::ThrowInvalidKeyError<TCacheDescriptor>(
"not", key);
309 template<
typename TSet,
typename THeightGroupedSet>
320 typename THeightGroupedSet::ElementType::Identifiers
touch(
Height height) {
334 template<
typename TSet,
typename THeightGroupedSet>
typename TCacheDescriptor::KeyType KeyType
Definition: CacheMixins.h:56
CacheFindIterator()=default
Creates an uninitialized iterator.
TIdentifiers FindDeactivatingIdentifiersAtHeight(const TSet &set, const TGroupedSet &groupedSet, Height height)
Finds identifiers of all values in set (with grouped view groupedSet) that are deactivating at height...
Definition: IdentifierGroupCacheUtils.h:84
static TValue & Adapt(TValue &value)
Definition: CacheMixins.h:135
void remove(const KeyType &key)
Removes the value identified by key from the cache.
Definition: CacheMixins.h:295
A mixin for adding iteration support to a cache.
Definition: CacheMixins.h:75
ConstAccessorMixin(const TSet &set)
Creates a mixin around set.
Definition: CacheMixins.h:202
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
Insert failed because the element already exists (immutable elements only).
typename TValueAdapter::AdaptedValueType ValueType
Definition: CacheMixins.h:193
Definition: CacheMixins.h:132
TSet & m_set
Definition: CacheMixins.h:305
typename TCacheDescriptor::ValueType ValueType
Definition: CacheMixins.h:276
A mixin for adding active querying support to a cache.
Definition: CacheMixins.h:250
constexpr void HexFormat(const ByteArray< N, TTag > &)
void insert(const ValueType &value)
Inserts value into the cache.
Definition: CacheMixins.h:285
void ThrowInvalidKeyError(const char *keyState, const T &key)
Definition: CacheMixins.h:119
const TSet & m_set
Definition: CacheMixins.h:70
void RemoveAllIdentifiersWithGroup(TSet &set, TGroupedSet &groupedSet, const TGroupingKey &key)
Removes all values in set with grouping key according to groupedSet.
Definition: IdentifierGroupCacheUtils.h:70
THeightGroupedSet & m_heightGroupedSet
Definition: CacheMixins.h:330
BasicInsertRemoveMixin(TSet &set)
Creates a mixin around set.
Definition: CacheMixins.h:280
typename TCacheDescriptor::KeyType KeyType
Definition: CacheMixins.h:144
void prune(Height height)
Prunes the cache at height.
Definition: CacheMixins.h:345
typename TSet::FindIterator SetIteratorType
Definition: CacheMixins.h:226
auto tryMakeIterableView() const
Definition: CacheMixins.h:107
typename TCacheDescriptor::KeyType KeyType
Definition: CacheMixins.h:192
bool IsBaseSetIterable(const BaseSet< TElementTraits, TSetTraits, TCommitPolicy > &set)
Returns true if set is iterable.
Definition: BaseSetIterationView.h:73
TSet & m_set
Definition: CacheMixins.h:350
A mixin for adding basic insert and remove support to a cache.
Definition: CacheMixins.h:273
typename TCacheDescriptor::KeyType KeyType
Definition: CacheMixins.h:252
IterableView(const TSet &set)
Creates a view around set.
Definition: CacheMixins.h:81
constexpr std::underlying_type_t< TEnum > to_underlying_type(TEnum value)
Converts a strongly typed enumeration value to its underlying integral value.
Definition: Casting.h:37
void ForEachIdentifierWithGroup(TSet &set, const TGroupedSet &groupedSet, const TGroupingKey &key, TAction action)
Calls action for each value in set with grouping key according to groupedSet.
Definition: IdentifierGroupCacheUtils.h:41
An iterable view of the cache.
Definition: CacheMixins.h:78
ContainsMixin(const TSet &set)
Creates a mixin around set.
Definition: CacheMixins.h:60
SizeMixin(const TSet &set)
Creates a mixin around set.
Definition: CacheMixins.h:39
KeyType m_key
Definition: CacheMixins.h:181
A mixin for adding const access support to a cache.
Definition: CacheMixins.h:190
typename TCacheDescriptor::KeyType KeyType
Definition: CacheMixins.h:275
HeightBasedTouchMixin(TSet &set, THeightGroupedSet &heightGroupedSet)
Creates a mixin around set and heightGroupedSet.
Definition: CacheMixins.h:313
TValue AdaptedValueType
Definition: CacheMixins.h:133
An iterator that is returned by cache find functions.
Definition: CacheMixins.h:142
size_t size() const
Gets the number of elements in the cache.
Definition: CacheMixins.h:44
CacheFindIterator(TBaseSetIterator &&iter, const KeyType &key)
Creates an iterator around a set iterator (iter) for the specified key.
Definition: CacheMixins.h:151
bool isActive(const KeyType &key, Height height) const
Returns true if the value specified by identifier key is active at height.
Definition: CacheMixins.h:261
A mixin for adding contains support to a cache.
Definition: CacheMixins.h:54
const TSet & m_set
Definition: CacheMixins.h:113
TSet & m_set
Definition: CacheMixins.h:329
ActivePredicateMixin(const TSet &set)
Creates a mixin around set.
Definition: CacheMixins.h:256
TSet & m_set
Definition: CacheMixins.h:245
IterationMixin(const TSet &set)
Creates a mixin around set.
Definition: CacheMixins.h:101
const_iterator find(const KeyType &key) const
Finds the cache value identified by key.
Definition: CacheMixins.h:207
typename TSet::FindConstIterator SetIteratorType
Definition: CacheMixins.h:194
iterator find(const KeyType &key)
Finds the cache value identified by key.
Definition: CacheMixins.h:239
typename TValueAdapter::AdaptedValueType ValueType
Definition: CacheMixins.h:225
const TSet & m_set
Definition: CacheMixins.h:49
static constexpr auto Name
Definition: PtSynchronizer.cpp:31
HeightBasedPruningMixin(TSet &set, THeightGroupedSet &heightGroupedSet)
Creates a mixin around set and heightGroupedSet.
Definition: CacheMixins.h:338
TBaseSetIterator m_iter
Definition: CacheMixins.h:180
const TSet & m_set
Definition: CacheMixins.h:96
An element pending removal was reverted.
TValue * tryGet() const
Tries to get a const value.
Definition: CacheMixins.h:168
const TSet & m_set
Definition: CacheMixins.h:213
THeightGroupedSet::ElementType::Identifiers touch(Height height)
Touches the cache at height and returns identifiers of all deactivating elements.
Definition: CacheMixins.h:320
No matching element was found.
MutableAccessorMixin(TSet &set)
Creates a mixin around set.
Definition: CacheMixins.h:234
typename TCacheDescriptor::KeyType KeyType
Definition: CacheMixins.h:224
bool contains(const KeyType &key) const
Gets a value indicating whether or not the cache contains an element with key.
Definition: CacheMixins.h:65
A mixin for height-based touching.
Definition: CacheMixins.h:310
#define CATAPULT_THROW_INVALID_ARGUMENT(MESSAGE)
Macro used to throw a catapult invalid argument.
Definition: exceptions.h:179
Definition: AddressExtractionExtension.cpp:28
A mixin for adding size support to a cache.
Definition: CacheMixins.h:36
detail::CacheFindIterator< TCacheDescriptor, TValueAdapter, SetIteratorType, const ValueType > const_iterator
Find (const) iterator.
Definition: CacheMixins.h:198
A new element was inserted.
auto end() const
Returns a const iterator to the element following the last element of the underlying set.
Definition: CacheMixins.h:91
BaseSetDeltaIterationView< TSetTraits > MakeIterableView(const BaseSetDelta< TElementTraits, TSetTraits > &delta)
Definition: BaseSetDeltaIterationView.h:200
const auto * tryGetUnadapted() const
Tries to get a const (unadapted) value.
Definition: CacheMixins.h:174
TValue & get() const
Definition: CacheMixins.h:159
detail::CacheFindIterator< TCacheDescriptor, TValueAdapter, SetIteratorType, ValueType > iterator
Find (mutable) iterator.
Definition: CacheMixins.h:230
THeightGroupedSet & m_heightGroupedSet
Definition: CacheMixins.h:351
Definition: CacheMixins.h:222
auto begin() const
Returns a const iterator to the first element of the underlying set.
Definition: CacheMixins.h:86
const TSet & m_set
Definition: CacheMixins.h:268
A mixin for height-based pruning.
Definition: CacheMixins.h:335