Belle II Software development
Relation.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#pragma once
9
10#include <utility>
11
12namespace Belle2 {
17 namespace TrackFindingCDC {
18
20 template <class AFrom, class ATo = AFrom>
21 class Relation : public std::pair<AFrom*, ATo*> {
22
23 private:
25 using Super = std::pair<AFrom*, ATo*>;
26
27 public:
29 using From = AFrom;
30
32 using To = ATo;
33
34 public:
36 using Super::Super;
37
39 bool operator<(const Relation<From, To>& rhs) const
40 {
41 return (getFrom() < rhs.getFrom() or
42 (not(rhs.getFrom() < getFrom()) and
43 (getTo() < rhs.getTo())));
44 }
45
47 friend bool operator<(const From* ptrFrom, const Relation<From, To>& relation)
48 {
49 return ptrFrom < relation.getFrom();
50 }
51
53 friend bool operator<(const Relation<From, To>& relation, const From* ptrFrom)
54 {
55 return relation.getFrom() < ptrFrom;
56 }
57
59 From* getFrom() const
60 {
61 return this->first;
62 }
63
65 To* getTo() const
66 {
67 return this->second;
68 }
69
72 {
73 return Relation<To, From>(getTo(), getFrom());
74 }
75 };
76 }
78}
Type for two related objects.
Definition: Relation.h:21
bool operator<(const Relation< From, To > &rhs) const
Operator for ordering of relations.
Definition: Relation.h:39
std::pair< AFrom *, ATo * > Super
Type of the base class.
Definition: Relation.h:25
From * getFrom() const
Getter for the pointer to the from side object.
Definition: Relation.h:59
AFrom From
Type of from which the relation originates.
Definition: Relation.h:29
friend bool operator<(const From *ptrFrom, const Relation< From, To > &relation)
Operator to compare key type item to the relations for assoziative lookups.
Definition: Relation.h:47
ATo To
Type of to which the relation points.
Definition: Relation.h:32
To * getTo() const
Getter for the pointer to the to side object.
Definition: Relation.h:65
friend bool operator<(const Relation< From, To > &relation, const From *ptrFrom)
Operator to compare key type item to the relations for assoziative lookups.
Definition: Relation.h:53
Relation< To, From > reversed() const
Make a relation in the opposite direciton with the same weight.
Definition: Relation.h:71
Abstract base class for different kinds of events.