thepeg
is hosted by
Hepforge
,
IPPP Durham
ThePEG
2.3.0
Utilities
ObjectIndexer.h
1
// -*- C++ -*-
2
//
3
// ObjectIndexer.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_ObjectIndexer_H
10
#define THEPEG_ObjectIndexer_H
11
// This is the declaration of the ObjectIndexer class.
12
13
#include "
ThePEG/Config/ThePEG.h
"
14
#include <limits>
15
16
namespace
ThePEG
{
17
24
template <typename IntT, typename ObjT, IntT NoIndex = static_cast<IntT>(-1)>
25
class
ObjectIndexer
{
26
27
public
:
28
29
ThePEG_DECLARE_TEMPLATE_POINTERS
(ObjT,
TPtr
);
30
32
typedef
map<IntT,tTPtr>
IndexObjectMap
;
33
35
typedef
map<TPtr,IntT>
ObjectIndexMap
;
36
37
public
:
38
42
ObjectIndexer
():
next
(0) {}
43
48
IntT
operator()
(
tTPtr
o) {
49
typename
ObjectIndexMap::iterator it =
objectIndex
.find(o);
50
if
( it ==
objectIndex
.end() ) {
51
IntT i =
next
++;
52
objectIndex
[o] = i;
53
indexObject
[i] = o;
54
return
i;
55
}
else
56
return
it->second;
57
}
58
63
IntT
operator()
(
tTPtr
o)
const
{
64
return
find
(o);
65
}
66
71
IntT
find
(
tTPtr
o)
const
{
72
typename
ObjectIndexMap::const_iterator it =
objectIndex
.find(o);
73
return
it ==
objectIndex
.end()? NoIndex: it->second;
74
}
75
80
tTPtr
operator()
(IntT i) {
81
if
( i == NoIndex )
return
tTPtr
();
82
typename
IndexObjectMap::iterator it =
indexObject
.find(i);
83
if
( it ==
indexObject
.end() ) {
84
TPtr
o = new_ptr<ObjT>();
85
objectIndex
[o] = i;
86
indexObject
[i] = o;
87
next
= max(
next
, i + 1);
88
return
o;
89
}
90
else
91
return
it->second;
92
}
93
98
tTPtr
operator()
(IntT i)
const
{
99
return
find
(i);
100
}
101
106
tTPtr
find
(IntT i)
const
{
107
typename
IndexObjectMap::const_iterator it =
indexObject
.find(i);
108
return
it ==
indexObject
.end()?
tTPtr
(): it->second;
109
}
110
116
void
operator()
(IntT i,
tTPtr
o) {
117
if
( i == NoIndex )
return
;
118
typename
IndexObjectMap::iterator iit =
indexObject
.find(i);
119
if
( iit !=
indexObject
.end() )
objectIndex
.erase(iit->second);
120
typename
ObjectIndexMap::iterator oit =
objectIndex
.find(o);
121
if
( oit !=
objectIndex
.end() )
indexObject
.erase(oit->second);
122
objectIndex
[o] = i;
123
indexObject
[i] = o;
124
next
= max(
next
, i + 1);
125
}
126
130
bool
included
(
tTPtr
o)
const
{
131
return
objectIndex
.find(o) !=
objectIndex
.end();
132
}
133
137
bool
included
(IntT i)
const
{
138
return
indexObject
.find(i) !=
indexObject
.end();
139
}
140
144
void
clear
() {
145
indexObject
.clear();
146
objectIndex
.clear();
147
}
148
152
bool
empty
()
const
{
153
return
indexObject
.empty() &&
objectIndex
.empty();
154
}
155
156
private
:
157
161
IndexObjectMap
indexObject
;
162
166
ObjectIndexMap
objectIndex
;
167
171
IntT
next
;
172
173
private
:
174
178
ObjectIndexer
&
operator=
(
const
ObjectIndexer
&) =
delete
;
179
180
};
181
182
}
183
184
#endif
/* THEPEG_ObjectIndexer_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::ObjectIndexer
This is a templated class which dynamically associates (reference counted) objects to integer indices...
Definition:
ObjectIndexer.h:25
ThePEG::ObjectIndexer::operator()
void operator()(IntT i, tTPtr o)
Associate the given object with the given index.
Definition:
ObjectIndexer.h:116
ThePEG::ObjectIndexer::clear
void clear()
Remove all associations.
Definition:
ObjectIndexer.h:144
ThePEG::ObjectIndexer::IndexObjectMap
map< IntT, tTPtr > IndexObjectMap
Map of objects to indices.
Definition:
ObjectIndexer.h:32
ThePEG::ObjectIndexer::ObjectIndexMap
map< TPtr, IntT > ObjectIndexMap
Map of indices to objects.
Definition:
ObjectIndexer.h:35
ThePEG::ObjectIndexer::operator=
ObjectIndexer & operator=(const ObjectIndexer &)=delete
Private and non-existent assignment operator.
ThePEG::ObjectIndexer::operator()
tTPtr operator()(IntT i)
Return the object for the given index.
Definition:
ObjectIndexer.h:80
ThePEG::ObjectIndexer::empty
bool empty() const
Return true if no associations has been made.
Definition:
ObjectIndexer.h:152
ThePEG::ObjectIndexer::next
IntT next
The next index to be used.
Definition:
ObjectIndexer.h:171
ThePEG::ObjectIndexer::objectIndex
ObjectIndexMap objectIndex
All known indices keyed by the corresponding objects.
Definition:
ObjectIndexer.h:166
ThePEG::ObjectIndexer::indexObject
IndexObjectMap indexObject
All known objects keyed by their indices.
Definition:
ObjectIndexer.h:161
ThePEG::ObjectIndexer::included
bool included(IntT i) const
Return true if the given index is known.
Definition:
ObjectIndexer.h:137
ThePEG::ObjectIndexer::operator()
tTPtr operator()(IntT i) const
Return the object for the given index.
Definition:
ObjectIndexer.h:98
ThePEG::ObjectIndexer::tTPtr
ThePEG::Ptr< ObjT >::transient_pointer tTPtr
Alias for a transient pointer to ObjT .
Definition:
ObjectIndexer.h:29
ThePEG::ObjectIndexer::included
bool included(tTPtr o) const
Return true if the given object is known.
Definition:
ObjectIndexer.h:130
ThePEG::ObjectIndexer::operator()
IntT operator()(tTPtr o) const
Return the index for the given object.
Definition:
ObjectIndexer.h:63
ThePEG::ObjectIndexer::operator()
IntT operator()(tTPtr o)
Return the index for the given object.
Definition:
ObjectIndexer.h:48
ThePEG::ObjectIndexer::ObjectIndexer
ObjectIndexer()
Empty constructor.
Definition:
ObjectIndexer.h:42
ThePEG::ObjectIndexer::find
IntT find(tTPtr o) const
Return the index for the given object.
Definition:
ObjectIndexer.h:71
ThePEG::ObjectIndexer::find
tTPtr find(IntT i) const
Return the object for the given index.
Definition:
ObjectIndexer.h:106
ThePEG::Pointer::RCPtr
RCPtr is a reference counted (smart) pointer.
Definition:
RCPtr.h:60
ThePEG::Pointer::TransientRCPtr
TransientRCPtr is a simple wrapper around a bare pointer which can be assigned to and from an RCPtr a...
Definition:
RCPtr.h:519
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