thepeg
is hosted by
Hepforge
,
IPPP Durham
ThePEG
2.3.0
Pointer
PtrTraits.h
1
// -*- C++ -*-
2
//
3
// PtrTraits.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_PtrTraits_H
10
#define ThePEG_PtrTraits_H
11
// This is the declaration of the PtrTraits class.
12
13
namespace
ThePEG
{
14
namespace
Pointer {
15
20
struct
PtrTraitsType
{};
21
38
template
<
class
T>
39
struct
PtrTraits
:
public
PtrTraitsType
{};
40
44
template
<
class
T>
45
struct
PtrTraits
<T *>:
public
PtrTraitsType
{
46
48
typedef
T
value_type
;
50
typedef
T &
reference
;
52
typedef
const
T &
const_reference
;
54
typedef
T *
pointer
;
56
typedef
T *
const_pointer
;
57
61
static
T *
barePointer
(T * p) {
return
p; }
62
66
static
pointer
create
() {
return
new
T; }
67
71
static
pointer
create
(
const_reference
t) {
return
new
T(t); }
72
76
static
void
destroy
(
pointer
tp) {
delete
tp; }
77
81
template
<
class
R>
82
static
pointer
DynamicCast
(R * r) {
return
dynamic_cast<
pointer
>
(r); }
83
87
static
pointer
ConstCast
(
const
T * t) {
return
const_cast<
pointer
>
(t); }
88
92
static
pointer
PtrCast
(T * t) {
return
t; }
93
97
static
const
bool
reference_counted =
false
;
98
99
};
100
105
template
<
class
T>
106
struct
PtrTraits
<const T *>:
public
PtrTraitsType
{
107
109
typedef
T
value_type
;
111
typedef
T &
reference
;
113
typedef
const
T &
const_reference
;
115
typedef
T *
pointer
;
117
typedef
T *
const_pointer
;
118
122
static
const
T *
barePointer
(
const
T * p) {
return
p; }
123
127
static
pointer
create
() {
return
new
T; }
128
132
static
pointer
create
(
const_reference
t) {
return
new
T(t); }
133
137
static
void
destroy
(
pointer
tp) {
delete
tp; }
138
142
template
<
class
R>
143
static
const_pointer
DynamicCast
(
const
R * r) {
144
return
dynamic_cast<
const_pointer
>
(r);
145
}
146
150
static
const_pointer
ConstCast
(
const
T * r) {
return
r; }
151
155
static
const_pointer
PtrCast
(
const
T * t) {
return
t; }
156
160
static
const
bool
reference_counted =
false
;
161
162
};
163
167
template
<
class
T1,
class
T2>
168
T1
dynamic_ptr_cast
(
const
T2 & t2) {
return
PtrTraits<T1>::DynamicCast
(t2); }
169
170
174
template
<
class
T1,
class
T2>
175
T1
const_ptr_cast
(
const
T2 & t2) {
return
PtrTraits<T1>::ConstCast
(t2); }
176
180
template
<
typename
Ptr>
181
inline
Ptr
ptr_new
() {
return
PtrTraits<Ptr>::create
(); }
182
186
template
<
typename
Ptr>
187
inline
Ptr
ptr_new
(
typename
PtrTraits<Ptr>::const_reference
t) {
188
return
PtrTraits<Ptr>::create
(t);
189
}
190
194
template
<
typename
T>
195
inline
typename
Ptr<T>::pointer
new_ptr
() {
196
return
PtrTraits< typename Ptr<T>::pointer
>::create();
197
}
198
202
template
<
typename
T>
203
inline
typename
Ptr<T>::pointer
new_ptr
(
const
T & t) {
204
return
PtrTraits< typename Ptr<T>::pointer
>::create(t);
205
}
206
210
template
<
typename
TPtr,
typename
T>
211
inline
TPtr
ptr_cast
(T * t) {
212
return
PtrTraits<TPtr>::PtrCast
(t);
213
}
214
218
template
<
typename
TPtr,
typename
T>
219
inline
TPtr
ptr_cast_const
(
const
T * t) {
220
return
PtrTraits<TPtr>::PtrCast
(
const_cast<
T*
>
(t));
221
}
222
223
224
}
225
}
226
227
#endif
/* ThePEG_PtrTraitsH */
ThePEG::Pointer::RCPtr
RCPtr is a reference counted (smart) pointer.
Definition:
RCPtr.h:60
ThePEG::Pointer::ptr_cast_const
TPtr ptr_cast_const(const T *t)
Simple interface to the PtrTraits<Ptr>::PtrCast()
Definition:
PtrTraits.h:219
ThePEG::Pointer::dynamic_ptr_cast
T1 dynamic_ptr_cast(const T2 &t2)
Replacement for the standard dynamic_cast.
Definition:
PtrTraits.h:168
ThePEG::Pointer::ptr_cast
TPtr ptr_cast(T *t)
Simple interface to the PtrTraits<Ptr>::PtrCast()
Definition:
PtrTraits.h:211
ThePEG::Pointer::const_ptr_cast
T1 const_ptr_cast(const T2 &t2)
Replacement for the standard const_cast.
Definition:
PtrTraits.h:175
ThePEG::Pointer::new_ptr
Ptr< T >::pointer new_ptr()
Simple interface to the PtrTraits<Ptr>::create()
Definition:
PtrTraits.h:195
ThePEG::Pointer::ptr_new
Ptr ptr_new()
Simple interface to the PtrTraits<Ptr>::create()
Definition:
PtrTraits.h:181
ThePEG
This is the main namespace within which all identifiers in ThePEG are declared.
Definition:
FactoryBase.h:28
ThePEG::Pointer::PtrTraitsType
PtrTraitsType is an empty non-polymorphic base class for all PtrTraits classes.
Definition:
PtrTraits.h:20
ThePEG::Pointer::PtrTraits< T * >::destroy
static void destroy(pointer tp)
Destroy the object pointed to.
Definition:
PtrTraits.h:76
ThePEG::Pointer::PtrTraits< T * >::reference
T & reference
Template argument typedef.
Definition:
PtrTraits.h:50
ThePEG::Pointer::PtrTraits< T * >::PtrCast
static pointer PtrCast(T *t)
Cast from a basic pointer.
Definition:
PtrTraits.h:92
ThePEG::Pointer::PtrTraits< T * >::create
static pointer create(const_reference t)
Create an copy of an object and return a pointer to it.
Definition:
PtrTraits.h:71
ThePEG::Pointer::PtrTraits< T * >::const_reference
const T & const_reference
Template argument typedef.
Definition:
PtrTraits.h:52
ThePEG::Pointer::PtrTraits< T * >::value_type
T value_type
Template argument typedef.
Definition:
PtrTraits.h:48
ThePEG::Pointer::PtrTraits< T * >::ConstCast
static pointer ConstCast(const T *t)
Cast away constness.
Definition:
PtrTraits.h:87
ThePEG::Pointer::PtrTraits< T * >::pointer
T * pointer
Template argument typedef.
Definition:
PtrTraits.h:54
ThePEG::Pointer::PtrTraits< T * >::const_pointer
T * const_pointer
Template argument typedef.
Definition:
PtrTraits.h:56
ThePEG::Pointer::PtrTraits< T * >::DynamicCast
static pointer DynamicCast(R *r)
Cast dynamically.
Definition:
PtrTraits.h:82
ThePEG::Pointer::PtrTraits< T * >::barePointer
static T * barePointer(T *p)
Return the bare pointer of the given pointer object.
Definition:
PtrTraits.h:61
ThePEG::Pointer::PtrTraits< T * >::create
static pointer create()
Create an object and return a pointer to it.
Definition:
PtrTraits.h:66
ThePEG::Pointer::PtrTraits< const T * >::reference
T & reference
Template argument typedef.
Definition:
PtrTraits.h:111
ThePEG::Pointer::PtrTraits< const T * >::create
static pointer create()
Create an object and return a pointer to it.
Definition:
PtrTraits.h:127
ThePEG::Pointer::PtrTraits< const T * >::value_type
T value_type
Template argument typedef.
Definition:
PtrTraits.h:109
ThePEG::Pointer::PtrTraits< const T * >::ConstCast
static const_pointer ConstCast(const T *r)
Do not cast away constness.
Definition:
PtrTraits.h:150
ThePEG::Pointer::PtrTraits< const T * >::pointer
T * pointer
Template argument typedef.
Definition:
PtrTraits.h:115
ThePEG::Pointer::PtrTraits< const T * >::destroy
static void destroy(pointer tp)
Destroy the object pointed to.
Definition:
PtrTraits.h:137
ThePEG::Pointer::PtrTraits< const T * >::const_pointer
T * const_pointer
Template argument typedef.
Definition:
PtrTraits.h:117
ThePEG::Pointer::PtrTraits< const T * >::barePointer
static const T * barePointer(const T *p)
Return the bare pointer of the given pointer object.
Definition:
PtrTraits.h:122
ThePEG::Pointer::PtrTraits< const T * >::PtrCast
static const_pointer PtrCast(const T *t)
Cast from a basic pointer.
Definition:
PtrTraits.h:155
ThePEG::Pointer::PtrTraits< const T * >::create
static pointer create(const_reference t)
Create an copy of an object and return a pointer to it.
Definition:
PtrTraits.h:132
ThePEG::Pointer::PtrTraits< const T * >::DynamicCast
static const_pointer DynamicCast(const R *r)
Cast dynamically.
Definition:
PtrTraits.h:143
ThePEG::Pointer::PtrTraits< const T * >::const_reference
const T & const_reference
Template argument typedef.
Definition:
PtrTraits.h:113
ThePEG::Pointer::PtrTraits
The PtrTraits class is used everywhere in ThePEG to interface to the pointers which are handled.
Definition:
PtrTraits.h:39
ThePEG::Pointer::Ptr
Ptr is a templated class to provide typedefs for pointers types ThePEG should use for a given type.
Definition:
Ptr.h:35
Generated on Thu Jun 20 2024 14:47:00 for ThePEG by
1.9.6