View | Details | Raw Unified | Return to bug 16
Collapse All | Expand All

(-)a/src/core/ptr.h (-23 / +32 lines)
 Lines 130-168   Ptr<T>::DeallocCount (uint32_t *count) Link Here 
130
130
131
template <typename T>
131
template <typename T>
132
Ptr<T>::Ptr ()
132
Ptr<T>::Ptr ()
133
  : m_ptr (0),
133
  : m_ptr (0)
134
    m_count (Ptr::AllocCount ())
135
{}
134
{}
136
135
137
template <typename T>
136
template <typename T>
138
Ptr<T>::Ptr (T *ptr) 
137
Ptr<T>::Ptr (T *ptr) 
139
  : m_ptr (ptr),
138
  : m_ptr (ptr)
140
    m_count (Ptr::AllocCount ())
141
{
139
{
142
  if (m_ptr != 0)
140
  if (m_ptr != 0)
143
    {
141
    {
142
      m_count = Ptr::AllocCount ();
144
      *m_count = 1;
143
      *m_count = 1;
145
    }
144
    }
146
}
145
}
147
146
148
template <typename T>
147
template <typename T>
149
Ptr<T>::Ptr (Ptr const&o) 
148
Ptr<T>::Ptr (Ptr const&o) 
150
  : m_ptr (o.m_ptr),
149
  : m_ptr (o.m_ptr)
151
    m_count (o.m_count)
150
{
152
{
151
  if (m_ptr != 0) 
153
  if (m_ptr != 0) 
152
    {
154
    {
153
      m_count = o.m_count;
155
      (*m_count)++;
154
      (*m_count)++;
156
    }
155
    }
157
}
156
}
158
template <typename T>
157
template <typename T>
159
template <typename U>
158
template <typename U>
160
Ptr<T>::Ptr (Ptr<U> const &o)
159
Ptr<T>::Ptr (Ptr<U> const &o)
161
  : m_ptr (o.m_ptr),
160
  : m_ptr (o.m_ptr)
162
    m_count (o.m_count)
161
{
163
{
162
  if (m_ptr != 0) 
164
  if (m_ptr != 0) 
163
    {
165
    {
164
      m_count = o.m_count;
166
      (*m_count)++;
165
      (*m_count)++;
167
    }
166
    }
168
}
167
}
 Lines 185-194   Ptr<T> & Link Here 
185
Ptr<T> &
184
Ptr<T> &
186
Ptr<T>::operator = (Ptr const& o) 
185
Ptr<T>::operator = (Ptr const& o) 
187
{
186
{
188
  if (o.m_ptr != 0) 
187
  if (&o == this)
189
    {
188
    return *this;
190
      (*(o.m_count))++;
191
    }
192
  if (m_ptr != 0) 
189
  if (m_ptr != 0) 
193
    {
190
    {
194
      (*m_count)--;
191
      (*m_count)--;
 Lines 199-205   Ptr<T>::operator = (Ptr const& o) Link Here 
199
        }
196
        }
200
    }
197
    }
201
  m_ptr = o.m_ptr;
198
  m_ptr = o.m_ptr;
202
  m_count = o.m_count;
199
  if (m_ptr != 0) 
200
    {
201
      m_count = o.m_count;
202
      (*m_count)++;
203
    }
203
  return *this;
204
  return *this;
204
}
205
}
205
206
 Lines 246-255   T * Link Here 
246
T *
247
T *
247
Ptr<T>::Remove (void) 
248
Ptr<T>::Remove (void) 
248
{
249
{
249
  NS_ASSERT ((*m_count) == 1);
250
  if (m_ptr == 0)
250
  T *retval = m_ptr;
251
    {
251
  m_ptr = 0;
252
      return (T *) 0;
252
  return retval;
253
    }
254
  else
255
    {
256
      NS_ASSERT ((*m_count) == 1);
257
      Ptr::DeallocCount (m_count);
258
      T *retval = m_ptr;
259
      m_ptr = 0;
260
      return retval;
261
    }
253
}
262
}
254
263
255
// non-member friend functions.
264
// non-member friend functions.

Return to bug 16