ATLAS Offline Software
Loading...
Searching...
No Matches
SimpleUpdater.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 * Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration.
4 */
11
12
13#ifndef CXXUTILS_SIMPLEUPDATER_H
14#define CXXUTILS_SIMPLEUPDATER_H
15
16
17#include <atomic>
18#include <vector>
19#include <memory>
20#include <algorithm>
21
22
23namespace CxxUtils {
24
25
35template <class T>
37{
38public:
41 struct Context_t {};
42
44 SimpleUpdater() = default;
45
46
51
52
56 const T& get() const;
57
58
67 void update (std::unique_ptr<T> p, const Context_t&);
68
69
78 void discard (std::unique_ptr<T> p);
79
80
86 void quiescent (const Context_t&);
87
88
95 void clean();
96
97
105 void swap (SimpleUpdater& other);
106
107
111 static const Context_t defaultContext();
112
113
114private:
116 std::atomic<const T*> m_obj = 0;
117
119 std::vector<std::unique_ptr<T> > m_objs;
120};
121
122
123} // namespace CxxUtils
124
125
127
128
129#endif // not CXXUTILS_SIMPLEUPDATER_H
void clean()
Delete all objects we're managing except for the current one.
std::vector< std::unique_ptr< T > > m_objs
List of all allocated objects.
void update(std::unique_ptr< T > p, const Context_t &)
Install a new object.
void swap(SimpleUpdater &other)
Swap this object with another.
void quiescent(const Context_t &)
Mark that an event slot is not referencing this object.
const T & get() const
Return a reference to the current object.
SimpleUpdater(SimpleUpdater &&other)
Move constructor.
static const Context_t defaultContext()
Return the current event context.
SimpleUpdater()=default
We need a default constructor.
std::atomic< const T * > m_obj
Pointer to the current object.
void discard(std::unique_ptr< T > p)
Queue an object for later deletion.