CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
mayown_ptr< T, N > Class Template Reference

#include <mayown_ptr.h>

Public Member Functions

bool empty () const
 
T const * get () const
 
bool isOwn () const
 
 mayown_ptr (mayown_ptr &&rh)
 
 mayown_ptr (mayown_ptr &)=delete
 
 mayown_ptr (T *ip=nullptr)
 
 mayown_ptr (T const &ip)
 
T const & operator* () const
 
T const * operator-> () const
 
mayown_ptroperator= (mayown_ptr &&rh)
 
mayown_ptroperator= (mayown_ptr &)=delete
 
T const * raw () const
 
T const * release ()
 
void reset ()
 
void reset (T *ip)
 
void reset (T const &ip)
 
 ~mayown_ptr ()
 

Private Member Functions

void destroy ()
 
void markOwn ()
 
T const * pointer () const
 

Private Attributes

T const * p = nullptr
 

Detailed Description

template<typename T, int N = sizeof(T*)>
class mayown_ptr< T, N >

Definition at line 13 of file mayown_ptr.h.

Constructor & Destructor Documentation

◆ mayown_ptr() [1/4]

template<typename T, int N = sizeof(T*)>
mayown_ptr< T, N >::mayown_ptr ( T ip = nullptr)
inlineexplicit

Definition at line 51 of file mayown_ptr.h.

51 : p(ip) { markOwn(); }

References mayown_ptr< T, N >::markOwn().

◆ mayown_ptr() [2/4]

template<typename T, int N = sizeof(T*)>
mayown_ptr< T, N >::mayown_ptr ( T const &  ip)
inlineexplicit

Definition at line 52 of file mayown_ptr.h.

52 : p(&ip) {}

◆ ~mayown_ptr()

template<typename T, int N = sizeof(T*)>
mayown_ptr< T, N >::~mayown_ptr ( )
inline

Definition at line 53 of file mayown_ptr.h.

53 { destroy(); }

References mayown_ptr< T, N >::destroy().

◆ mayown_ptr() [3/4]

template<typename T, int N = sizeof(T*)>
mayown_ptr< T, N >::mayown_ptr ( mayown_ptr< T, N > &  )
delete

◆ mayown_ptr() [4/4]

template<typename T, int N = sizeof(T*)>
mayown_ptr< T, N >::mayown_ptr ( mayown_ptr< T, N > &&  rh)
inline

Definition at line 55 of file mayown_ptr.h.

55 : p(rh.p) { rh.p = nullptr; }

Member Function Documentation

◆ destroy()

template<typename T, int N = sizeof(T*)>
void mayown_ptr< T, N >::destroy ( )
inlineprivate

Definition at line 45 of file mayown_ptr.h.

45  {
46  if (isOwn())
47  delete const_cast<T*>(pointer());
48  }

References mayown_ptr< T, N >::isOwn(), and mayown_ptr< T, N >::pointer().

Referenced by mayown_ptr< T, N >::operator=(), mayown_ptr< T, N >::reset(), and mayown_ptr< T, N >::~mayown_ptr().

◆ empty()

template<typename T, int N = sizeof(T*)>
bool mayown_ptr< T, N >::empty ( ) const
inline

Definition at line 85 of file mayown_ptr.h.

85 { return nullptr == p; }

References mayown_ptr< T, N >::p.

Referenced by MultiHitGeneratorFromChi2::hitSets().

◆ get()

template<typename T, int N = sizeof(T*)>
T const* mayown_ptr< T, N >::get ( ) const
inline

◆ isOwn()

template<typename T, int N = sizeof(T*)>
bool mayown_ptr< T, N >::isOwn ( ) const
inline

Definition at line 28 of file mayown_ptr.h.

28  {
29  unsigned char buff[N];
30  memcpy(buff, &p, N);
31  return 1 == (buff[N - 1] & 1);
32  }

References N, and mayown_ptr< T, N >::p.

Referenced by mayown_ptr< T, N >::destroy(), and MultiHitGeneratorFromChi2::hitSets().

◆ markOwn()

template<typename T, int N = sizeof(T*)>
void mayown_ptr< T, N >::markOwn ( )
inlineprivate

Definition at line 17 of file mayown_ptr.h.

17  {
18  if (nullptr == p)
19  return;
20  unsigned char buff[N];
21  memcpy(buff, &p, N);
22  assert((buff[N - 1] & 1) == 0);
23  ++buff[N - 1];
24  memcpy(&p, buff, N);
25  }

References cms::cuda::assert(), N, and mayown_ptr< T, N >::p.

Referenced by mayown_ptr< T, N >::mayown_ptr(), and mayown_ptr< T, N >::reset().

◆ operator*()

template<typename T, int N = sizeof(T*)>
T const& mayown_ptr< T, N >::operator* ( void  ) const
inline

Definition at line 64 of file mayown_ptr.h.

64 { return *pointer(); }

References mayown_ptr< T, N >::pointer().

◆ operator->()

template<typename T, int N = sizeof(T*)>
T const* mayown_ptr< T, N >::operator-> ( ) const
inline

Definition at line 65 of file mayown_ptr.h.

65 { return pointer(); }

References mayown_ptr< T, N >::pointer().

◆ operator=() [1/2]

template<typename T, int N = sizeof(T*)>
mayown_ptr& mayown_ptr< T, N >::operator= ( mayown_ptr< T, N > &&  rh)
inline

Definition at line 57 of file mayown_ptr.h.

57  {
58  destroy();
59  p = rh.p;
60  rh.p = nullptr;
61  return *this;
62  }

References mayown_ptr< T, N >::destroy(), and mayown_ptr< T, N >::p.

◆ operator=() [2/2]

template<typename T, int N = sizeof(T*)>
mayown_ptr& mayown_ptr< T, N >::operator= ( mayown_ptr< T, N > &  )
delete

◆ pointer()

template<typename T, int N = sizeof(T*)>
T const* mayown_ptr< T, N >::pointer ( ) const
inlineprivate

Definition at line 35 of file mayown_ptr.h.

35  {
36  unsigned char buff[N];
37  memcpy(buff, &p, N);
38  buff[N - 1] &= 0xFE;
39  assert((buff[N - 1] & 1) == 0);
40  T const* np;
41  memcpy(&np, buff, N);
42  return np;
43  }

References cms::cuda::assert(), N, np, and mayown_ptr< T, N >::p.

Referenced by mayown_ptr< T, N >::destroy(), mayown_ptr< T, N >::get(), mayown_ptr< T, N >::operator*(), mayown_ptr< T, N >::operator->(), and mayown_ptr< T, N >::release().

◆ raw()

template<typename T, int N = sizeof(T*)>
T const* mayown_ptr< T, N >::raw ( ) const
inline

Definition at line 87 of file mayown_ptr.h.

87 { return p; }

References mayown_ptr< T, N >::p.

Referenced by operator<(), and operator==().

◆ release()

template<typename T, int N = sizeof(T*)>
T const* mayown_ptr< T, N >::release ( )
inline

Definition at line 67 of file mayown_ptr.h.

67  {
68  auto np = pointer();
69  p = nullptr;
70  return np;
71  }

References np, mayown_ptr< T, N >::p, and mayown_ptr< T, N >::pointer().

Referenced by MultiHitGeneratorFromChi2::hitSets().

◆ reset() [1/3]

template<typename T, int N = sizeof(T*)>
void mayown_ptr< T, N >::reset ( void  )
inline

Definition at line 72 of file mayown_ptr.h.

72  {
73  destroy();
74  p = nullptr;
75  }

References mayown_ptr< T, N >::destroy(), and mayown_ptr< T, N >::p.

Referenced by MultiHitGeneratorFromChi2::hitSets().

◆ reset() [2/3]

template<typename T, int N = sizeof(T*)>
void mayown_ptr< T, N >::reset ( T ip)
inline

Definition at line 76 of file mayown_ptr.h.

76  {
77  destroy();
78  p = ip;
79  markOwn();
80  }

References mayown_ptr< T, N >::destroy(), mayown_ptr< T, N >::markOwn(), and mayown_ptr< T, N >::p.

◆ reset() [3/3]

template<typename T, int N = sizeof(T*)>
void mayown_ptr< T, N >::reset ( T const &  ip)
inline

Definition at line 81 of file mayown_ptr.h.

81  {
82  destroy();
83  p = &ip;
84  }

References mayown_ptr< T, N >::destroy(), and mayown_ptr< T, N >::p.

Member Data Documentation

◆ p

template<typename T, int N = sizeof(T*)>
T const* mayown_ptr< T, N >::p = nullptr
private
mayown_ptr::pointer
T const * pointer() const
Definition: mayown_ptr.h:35
mayown_ptr::p
T const * p
Definition: mayown_ptr.h:15
np
int np
Definition: AMPTWrapper.h:43
cms::cuda::assert
assert(be >=bs)
N
#define N
Definition: blowfish.cc:9
mayown_ptr::isOwn
bool isOwn() const
Definition: mayown_ptr.h:28
mayown_ptr::markOwn
void markOwn()
Definition: mayown_ptr.h:17
mayown_ptr::destroy
void destroy()
Definition: mayown_ptr.h:45
T
long double T
Definition: Basic3DVectorLD.h:48