Belle II Software development
SetMergeable.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <framework/pcore/Mergeable.h>
12
13namespace Belle2 {
35 template <class T> class SetMergeable : public Mergeable {
36 public:
37 SetMergeable() : m_wrapped() { }
38
39 virtual ~SetMergeable() { }
41 template<class ...Args> explicit SetMergeable(Args&& ... params) : m_wrapped(std::forward<Args>(params)...) { }
42
44 T& get() { return m_wrapped; }
45
47 const T& get() const { return m_wrapped; }
48
56 virtual void merge(const Mergeable* other) override
57 {
58 auto* otherMergeable = static_cast<const SetMergeable*>(other);
59 for (const auto& element : otherMergeable->get()) {
60 auto it = m_wrapped.find(element);
61 if (it == m_wrapped.end()) {
62 m_wrapped.insert(element);
63 }
64 }
65 }
66
72 virtual void clear() override
73 {
74 m_wrapped.clear();
75 }
76
77 private:
80
82 };
84}
Abstract base class for objects that can be merged.
Definition: Mergeable.h:31
Wrap an STL set to make it mergeable.
Definition: SetMergeable.h:35
SetMergeable(Args &&... params)
Constructor, forwards all arguments to T constructor.
Definition: SetMergeable.h:41
virtual void merge(const Mergeable *other) override
Merge object 'other' into this one.
Definition: SetMergeable.h:56
T m_wrapped
Wrapped object.
Definition: SetMergeable.h:79
virtual void clear() override
Clear content of this object (e.g.
Definition: SetMergeable.h:72
const T & get() const
Get the wrapped standard object.
Definition: SetMergeable.h:47
ClassDefOverride(SetMergeable, 1)
Wrap an STL set to make it mergeable.
T & get()
Get the wrapped standard object.
Definition: SetMergeable.h:44
Abstract base class for different kinds of events.
STL namespace.