thepeg
is hosted by
Hepforge
,
IPPP Durham
ThePEG
2.3.0
Utilities
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
12
#include "
ThePEG/Config/ThePEG.h
"
13
#include "Rebinder.fh"
14
#include <stdexcept>
15
16
namespace
ThePEG
{
17
26
template
<
typename
T>
27
class
Rebinder
{
28
29
public
:
30
32
Rebinder
() {}
33
34
public
:
35
36
ThePEG_DECLARE_TEMPLATE_POINTERS
(T,
TPtr
);
37
39
typedef
std::map<cTPtr,TPtr>
MapType
;
40
42
typedef
typename
MapType::const_iterator
const_iterator
;
43
44
public
:
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
107
private
:
108
109
113
MapType
theMap
;
114
115
private
:
116
118
Rebinder
(
const
Rebinder
&);
119
121
Rebinder
&
operator=
(
const
Rebinder
&) =
delete
;
122
123
};
124
125
126
}
127
128
#endif
/* ThePEG_Rebinder_H */
ThePEG_DECLARE_TEMPLATE_POINTERS
#define ThePEG_DECLARE_TEMPLATE_POINTERS(full, abbrev)
This macro helps us to declare pointers and stuff to standard classes.
Definition:
Pointers.h:36
ThePEG.h
This is the main config header file for ThePEG.
ThePEG::Pointer::RCPtr
RCPtr is a reference counted (smart) pointer.
Definition:
RCPtr.h:60
ThePEG::Pointer::TransientConstRCPtr
TransientConstRCPtr is a simple wrapper around a bare const pointer which can be assigned to and from...
Definition:
RCPtr.h:696
ThePEG::Rebinder
Rebinder is a class associating pairs of pointers to objects.
Definition:
Rebinder.h:27
ThePEG::Rebinder::translate
R translate(const R &r) const
Return a pointer to the object associated with the argument.
Definition:
Rebinder.h:58
ThePEG::Rebinder::alwaysTranslate
R alwaysTranslate(const R &r) const
Return a pointer to the object associated with the argument.
Definition:
Rebinder.h:81
ThePEG::Rebinder::alwaysTranslate
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
ThePEG::Rebinder::theMap
MapType theMap
The underlying map representation.
Definition:
Rebinder.h:113
ThePEG::Rebinder::operator=
Rebinder & operator=(const Rebinder &)=delete
The assignment operator is private and not implemented.
ThePEG::Rebinder::Rebinder
Rebinder(const Rebinder &)
The copy constructor is private and not implemented.
ThePEG::Rebinder::MapType
std::map< cTPtr, TPtr > MapType
Map associating pairs of objects.
Definition:
Rebinder.h:39
ThePEG::Rebinder::Rebinder
Rebinder()
Default constructor.
Definition:
Rebinder.h:32
ThePEG::Rebinder::operator[]
TPtr & operator[](tcTPtr t)
Return a pointer to the object associated with the argument.
Definition:
Rebinder.h:49
ThePEG::Rebinder::map
const MapType & map() const
Acces the underlying map representation.
Definition:
Rebinder.h:105
ThePEG::Rebinder::const_iterator
MapType::const_iterator const_iterator
The iterator of the underlying map.
Definition:
Rebinder.h:42
ThePEG::Rebinder::translate
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
ThePEG
This is the main namespace within which all identifiers in ThePEG are declared.
Definition:
FactoryBase.h:28
Generated on Thu Jun 20 2024 14:47:02 for ThePEG by
1.9.6