Belle II Software light-2406-ragdoll
MapMergeable.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 {
34 template <class T> class MapMergeable : public Mergeable {
35 public:
36 MapMergeable() : m_wrapped() { }
37
38 virtual ~MapMergeable() { }
40 template<class ...Args> explicit MapMergeable(Args&& ... params) : m_wrapped(std::forward<Args>(params)...) { }
41
43 T& get() { return m_wrapped; }
44
46 const T& get() const { return m_wrapped; }
47
55 virtual void merge(const Mergeable* other)
56 {
57 auto* otherMergeable = static_cast<const MapMergeable*>(other);
58 for (const auto& element : otherMergeable->get()) {
59 auto it = m_wrapped.find(element.first);
60 if (it != m_wrapped.end()) {
61 it->second += element.second;
62 } else {
63 m_wrapped.insert(element);
64 }
65 }
66 }
67
73 virtual void clear()
74 {
75 m_wrapped.clear();
76 }
77
78 private:
81
83 };
85}
Wrap an STL map to make it mergeable.
Definition: MapMergeable.h:34
ClassDef(MapMergeable, 1)
Wrap an STL map to make it mergeable.
MapMergeable(Args &&... params)
Constructor, forwards all arguments to T constructor.
Definition: MapMergeable.h:40
T m_wrapped
Wrapped object.
Definition: MapMergeable.h:80
const T & get() const
Get the wrapped standard object.
Definition: MapMergeable.h:46
virtual void merge(const Mergeable *other)
Merge object 'other' into this one.
Definition: MapMergeable.h:55
virtual void clear()
Clear content of this object (e.g.
Definition: MapMergeable.h:73
T & get()
Get the wrapped standard object.
Definition: MapMergeable.h:43
Abstract base class for objects that can be merged.
Definition: Mergeable.h:31
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
STL namespace.