ATLAS Offline Software
Loading...
Searching...
No Matches
IdentifiableCache.h
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2
3/*
4 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
5*/
6
7// $Id: IdentifiableCache.h 791541 2017-01-09 10:43:53Z smh $
14
15
16#ifndef EVENTCONTAINERS_IDENTIFIABLECACHE_H
17#define EVENTCONTAINERS_IDENTIFIABLECACHE_H
18
19
21#include <bit>
22
23namespace EventContainers {
24
25
26template <class T>
29{
30public:
31
32
33 class Maker
34 : public IMaker
35 {
36 public:
37 virtual std::unique_ptr<T> make (IdentifierHash hash) const = 0;
38 private:
40 { return void_unique_ptr (make (hash)); }
41 };
42
43 IdentifiableCache (IdentifierHash maxHash, const Maker* maker)
44 : IdentifiableCacheBase (maxHash, maker)
45 {
46 }
47
48 IdentifiableCache (IdentifierHash maxHash, const Maker* maker, size_t lockBucketSize)
49 : IdentifiableCacheBase (maxHash, maker, lockBucketSize)
50 {
51 }
52
57
58 // Return payload if there, null if not there.
59 const T* find (IdentifierHash hash)
60 {
61 return std::bit_cast<const T*> (IdentifiableCacheBase::find (hash));
62 }
63
64 const T* findWait (IdentifierHash hash)
65 {
66 return std::bit_cast<const T*> (IdentifiableCacheBase::findWait (hash));
67 }
68
69 const T* get (IdentifierHash hash)
70 {
71 return std::bit_cast<const T*> (IdentifiableCacheBase::get (hash));
72 }
73
74 std::pair<bool, const void*> add (IdentifierHash hash, const T* p)
75 {
76 return IdentifiableCacheBase::add (hash, p);
77 }
78
79 std::pair<bool, const void*> add (IdentifierHash hash, std::unique_ptr<T> p)
80 {
81 return IdentifiableCacheBase::add (hash, void_unique_ptr(std::move(p)));
82 }
83
87};
88
89
90} // namespace EventContainers
91
92
93#endif // not EVENTCONTAINERS_IDENTIFIABLECACHE_H
const void * get(IdentifierHash hash)
Try to make payload if not there.
IdentifiableCacheBase(IdentifierHash maxHash, const IMaker *maker)
std::pair< bool, const void * > add(IdentifierHash hash, const void *p) noexcept
const void * findWait(IdentifierHash hash)
Retrieve ptr, will wait if there is something in progress.
const void * find(IdentifierHash hash) noexcept
Return payload if there, null if not there.
virtual std::unique_ptr< T > make(IdentifierHash hash) const =0
virtual void_unique_ptr typelessMake(IdentifierHash hash) const
std::pair< bool, const void * > add(IdentifierHash hash, std::unique_ptr< T > p)
std::pair< bool, const void * > add(IdentifierHash hash, const T *p)
IdentifiableCache(IdentifierHash maxHash, const Maker *maker)
IdentifiableCache(IdentifierHash maxHash, const Maker *maker, size_t lockBucketSize)
const T * findWait(IdentifierHash hash)
const T * get(IdentifierHash hash)
const T * find(IdentifierHash hash)
This is a "hash" representation of an Identifier.
static void deleter(const void *p)
Definition deleter.h:24