thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
Rebinder.h
1// -*- C++ -*-
2//
3// Rebinder.h is a part of ThePEG - Toolkit for HEP Event Generation
4// Copyright (C) 1999-2019 Leif Lonnblad
5//
6// ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8//
9#ifndef ThePEG_Rebinder_H
10#define ThePEG_Rebinder_H
11
13#include "Rebinder.fh"
14#include <stdexcept>
15
16namespace ThePEG {
17
26template <typename T>
27class Rebinder {
28
29public:
30
33
34public:
35
37
39 typedef std::map<cTPtr,TPtr> MapType;
40
42 typedef typename MapType::const_iterator const_iterator;
43
44public:
45
49 TPtr & operator[](tcTPtr t) { return theMap[t]; }
50
57 template <typename R>
58 R translate(const R & r) const {
59 const_iterator it = theMap.find(r);
60 return it == theMap.end()? R(): dynamic_ptr_cast<R>(it->second);
61 }
62
69 template <typename OutputIterator, typename InputIterator>
70 void translate(OutputIterator r,
71 InputIterator first, InputIterator last) const {
72 while ( first != last ) *r++ = translate(*first++);
73 }
74
80 template <typename R>
81 R alwaysTranslate(const R & r) const {
82 R ret;
83 if ( !r ) return ret;
84 const_iterator it = theMap.find(r);
85 ret = (it == theMap.end()? R(): dynamic_ptr_cast<R>(it->second));
86 if ( !ret ) throw std::runtime_error("Rebinder exception");
87 return ret;
88 }
89
96 template <typename OutputIterator, typename InputIterator>
97 void alwaysTranslate(OutputIterator r, InputIterator first, InputIterator last)
98 const {
99 while ( first != last ) *r++ = alwaysTranslate(*first++);
100 }
101
105 const MapType & map() const { return theMap; }
106
107private:
108
109
114
115private:
116
119
121 Rebinder & operator=(const Rebinder &) = delete;
122
123};
124
125
126}
127
128#endif /* ThePEG_Rebinder_H */
#define ThePEG_DECLARE_TEMPLATE_POINTERS(full, abbrev)
This macro helps us to declare pointers and stuff to standard classes.
Definition: Pointers.h:36
This is the main config header file for ThePEG.
RCPtr is a reference counted (smart) pointer.
Definition: RCPtr.h:60
TransientConstRCPtr is a simple wrapper around a bare const pointer which can be assigned to and from...
Definition: RCPtr.h:696
Rebinder is a class associating pairs of pointers to objects.
Definition: Rebinder.h:27
R translate(const R &r) const
Return a pointer to the object associated with the argument.
Definition: Rebinder.h:58
R alwaysTranslate(const R &r) const
Return a pointer to the object associated with the argument.
Definition: Rebinder.h:81
void alwaysTranslate(OutputIterator r, InputIterator first, InputIterator last) const
Insert pointers to objects into the output iterator, pointers to objects corresponding to the ones gi...
Definition: Rebinder.h:97
MapType theMap
The underlying map representation.
Definition: Rebinder.h:113
Rebinder & operator=(const Rebinder &)=delete
The assignment operator is private and not implemented.
Rebinder(const Rebinder &)
The copy constructor is private and not implemented.
std::map< cTPtr, TPtr > MapType
Map associating pairs of objects.
Definition: Rebinder.h:39
Rebinder()
Default constructor.
Definition: Rebinder.h:32
TPtr & operator[](tcTPtr t)
Return a pointer to the object associated with the argument.
Definition: Rebinder.h:49
const MapType & map() const
Acces the underlying map representation.
Definition: Rebinder.h:105
MapType::const_iterator const_iterator
The iterator of the underlying map.
Definition: Rebinder.h:42
void translate(OutputIterator r, InputIterator first, InputIterator last) const
Insert pointers to objects into the output iterator, pointers to objects corresponding to the ones gi...
Definition: Rebinder.h:70
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28