/usr/include/ThePEG/Pointer/PtrTraits.h is in libthepeg-dev 1.8.0-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | // -*- C++ -*-
//
// PtrTraits.h is a part of ThePEG - Toolkit for HEP Event Generation
// Copyright (C) 1999-2011 Leif Lonnblad
//
// ThePEG is licenced under version 2 of the GPL, see COPYING for details.
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
//
#ifndef ThePEG_PtrTraits_H
#define ThePEG_PtrTraits_H
// This is the declaration of the PtrTraits class.
namespace ThePEG {
namespace Pointer {
/**
* PtrTraitsType is an empty non-polymorphic base class for all
* PtrTraits classes.
*/
struct PtrTraitsType {};
/**
* The PtrTraits class is used everywhere in ThePEG to
* interface to the pointers which are handled. In particular, ThePEG
* never uses new or delete but always
* PtrTraits<P>::create and
* PtrTraits<P>::destroy (to be precise the destroy method
* is never used since all pointers are assumed to be reference
* counted or in another way garbage collected). Also ThePEG
* always uses dynamic_ptr_cast (rather than the standard
* dynamic_cast) which in turn calls the
* PtrTraits<P>::DynamicCast.
*
* In this file is also defined the specialized std::iterator_traits
* for the reference counted pointers.
*
*/
template <class T>
struct PtrTraits: public PtrTraitsType {};
/**
* Specialization of the PtrTraits class for standard bare pointers.
*/
template <class T>
struct PtrTraits<T *>: public PtrTraitsType {
/** Template argument typedef. */
typedef T value_type;
/** Template argument typedef. */
typedef T & reference;
/** Template argument typedef. */
typedef const T & const_reference;
/** Template argument typedef. */
typedef T * pointer;
/** Template argument typedef. */
typedef T * const_pointer;
/**
* Return the bare pointer of the given pointer object.
*/
static T * barePointer(T * p) { return p; }
/**
* Create an object and return a pointer to it.
*/
static pointer create() { return new T; }
/**
* Create an copy of an object and return a pointer to it.
*/
static pointer create(const_reference t) { return new T(t); }
/**
* Destroy the object pointed to.
*/
static void destroy(pointer tp) { delete tp; }
/**
* Cast dynamically.
*/
template <class R>
static pointer DynamicCast(R * r) { return dynamic_cast<pointer>(r); }
/**
* Cast away constness.
*/
static pointer ConstCast(const T * t) { return const_cast<pointer>(t); }
/**
* Cast from a basic pointer.
*/
static pointer PtrCast(T * t) { return t; }
/**
* The bare pointer is not reference counted.
*/
static const bool reference_counted = false;
};
/**
* Specialization of the PtrTraits class for standard bare
* const pointers.
*/
template <class T>
struct PtrTraits<const T *>: public PtrTraitsType {
/** Template argument typedef. */
typedef T value_type;
/** Template argument typedef. */
typedef T & reference;
/** Template argument typedef. */
typedef const T & const_reference;
/** Template argument typedef. */
typedef T * pointer;
/** Template argument typedef. */
typedef T * const_pointer;
/**
* Return the bare pointer of the given pointer object.
*/
static const T * barePointer(const T * p) { return p; }
/**
* Create an object and return a pointer to it.
*/
static pointer create() { return new T; }
/**
* Create an copy of an object and return a pointer to it.
*/
static pointer create(const_reference t) { return new T(t); }
/**
* Destroy the object pointed to.
*/
static void destroy(pointer tp) { delete tp; }
/**
* Cast dynamically.
*/
template <class R>
static const_pointer DynamicCast(const R * r) {
return dynamic_cast<const_pointer>(r);
}
/**
* Do not cast away constness.
*/
static const_pointer ConstCast(const T * r) { return r; }
/**
* Cast from a basic pointer.
*/
static const_pointer PtrCast(const T * t) { return t; }
/**
* The bare pointer is not reference counted.
*/
static const bool reference_counted = false;
};
/**
* Replacement for the standard dynamic_cast
*/
template <class T1, class T2>
T1 dynamic_ptr_cast(const T2 & t2) { return PtrTraits<T1>::DynamicCast(t2); }
/**
* Replacement for the standard const_cast
*/
template <class T1, class T2>
T1 const_ptr_cast(const T2 & t2) { return PtrTraits<T1>::ConstCast(t2); }
/**
* Simple interface to the PtrTraits<Ptr>::create()
*/
template <typename Ptr>
inline Ptr ptr_new() { return PtrTraits<Ptr>::create(); }
/**
* Simple interface to the PtrTraits<Ptr>::create()
*/
template <typename Ptr>
inline Ptr ptr_new(typename PtrTraits<Ptr>::const_reference t) {
return PtrTraits<Ptr>::create(t);
}
/**
* Simple interface to the PtrTraits<Ptr>::create()
*/
template <typename T>
inline typename Ptr<T>::pointer new_ptr() {
return PtrTraits< typename Ptr<T>::pointer >::create();
}
/**
* Simple interface to the PtrTraits<Ptr>::create()
*/
template <typename T>
inline typename Ptr<T>::pointer new_ptr(const T & t) {
return PtrTraits< typename Ptr<T>::pointer >::create(t);
}
/**
* Simple interface to the PtrTraits<Ptr>::PtrCast()
*/
template <typename TPtr, typename T>
inline TPtr ptr_cast(T * t) {
return PtrTraits<TPtr>::PtrCast(t);
}
/**
* Simple interface to the PtrTraits<Ptr>::PtrCast()
*/
template <typename TPtr, typename T>
inline TPtr ptr_cast_const(const T * t) {
return PtrTraits<TPtr>::PtrCast(const_cast<T*>(t));
}
}
}
#endif /* ThePEG_PtrTraitsH */
|