My Project
PERefPtr.h
1 #pragma once
2 
3 #define asset_ptr ref_ptr
4 
5 namespace ParaEngine
6 {
13  template<class T> struct ref_ptr
14  {
15  protected:
16  // contained pointer
17  T * px;
18  public:
19  typedef T element_type;
20  typedef T value_type;
21  typedef T * pointer;
22 
23  ref_ptr() : px(0)
24  {
25  }
26 
27  ~ref_ptr()
28  {
29  if (px != 0)
30  px->Release();
31  }
32 
33  template<class Y>
34  explicit ref_ptr(Y * p) : px(p) // Y must be complete
35  {
36  if (px != 0)
37  px->addref();
38  }
39 
40  ref_ptr(const ref_ptr & r) : px(r.px) // never throws
41  {
42  if (px != 0)
43  px->addref();
44  }
45 
46  ref_ptr & operator=(const ref_ptr & r) // never throws
47  {
48  if (px != r.px)
49  {
50  if (px != 0)
51  px->Release();
52  px = r.px;
53  if (px != 0)
54  px->addref();
55  }
56  return *this;
57  }
58 
59  template<class Y>
60  ref_ptr & operator=(Y* r) // never throws
61  {
62  if (px != r)
63  {
64  if (px != 0)
65  px->Release();
66  px = r;
67  if (px != 0)
68  px->addref();
69  }
70  return *this;
71  }
72 
73 
74  T& operator* () const // never throws
75  {
76  PE_ASSERT(px != 0);
77  return *px;
78  }
79 
80  T * operator-> () const // never throws
81  {
82  PE_ASSERT(px != 0);
83  return px;
84  }
85 
86  T * get() const // never throws
87  {
88  return px;
89  }
90 
91  operator bool() const
92  {
93  return px != 0;
94  }
95 
96  bool operator! () const // never throws
97  {
98  return px == 0;
99  }
100 
101  int use_count() const // never throws
102  {
103  return (px != 0) ? px->GetRefCount() : 0;
104  }
105 
106  bool unique() const // nothrow
107  {
108  return use_count() == 1;
109  }
110 
111  void reset(T* r = 0)
112  {
113  if (px != r)
114  {
115  if (px != 0)
116  px->Release();
117  px = r;
118  if (px != 0)
119  px->addref();
120  }
121  }
122  };
123 
124  template<class T, class U> inline bool operator==(ref_ptr<T> const & a, ref_ptr<U> const & b)
125  {
126  return a.get() == b.get();
127  }
128 
129  template<class T, class U> inline bool operator!=(ref_ptr<T> const & a, ref_ptr<U> const & b)
130  {
131  return a.get() != b.get();
132  }
133 
134  template<class T, class U> inline bool operator==(ref_ptr<T> const & a, U const * b)
135  {
136  return a.get() == b;
137  }
138 
139  template<class T, class U> inline bool operator!=(ref_ptr<T> const & a, U const * b)
140  {
141  return a.get() != b;
142  }
143 }
different physics engine has different winding order.
Definition: EventBinding.h:32
The ref_ptr class template stores a pointer to a dynamically allocated (AssetEntity|CRefCounted|BaseA...
Definition: PERefPtr.h:13