author | Raj Bhattacharjea <raj.b@gatech.edu> |
Wed, 09 May 2007 13:26:21 -0400 | |
changeset 543 | a730800a31d5 |
parent 542 | 00722b9a01b3 |
child 544 | cbc4158d47c9 |
permissions | -rw-r--r-- |
223
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
2 |
/* |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
3 |
* Copyright (c) 2005,2006 INRIA |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
4 |
* All rights reserved. |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
5 |
* |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
6 |
* This program is free software; you can redistribute it and/or modify |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
7 |
* it under the terms of the GNU General Public License version 2 as |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
8 |
* published by the Free Software Foundation; |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
9 |
* |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
13 |
* GNU General Public License for more details. |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
14 |
* |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
16 |
* along with this program; if not, write to the Free Software |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
18 |
* |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
19 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
20 |
*/ |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
21 |
|
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
22 |
#ifndef PTR_H |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
23 |
#define PTR_H |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
24 |
|
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
25 |
#include <stdint.h> |
286
57e6a2006962
convert use of <cassert> to "ns3/assert.h"
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
227
diff
changeset
|
26 |
#include "assert.h" |
223
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
27 |
|
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
28 |
namespace ns3 { |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
29 |
|
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
30 |
/** |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
31 |
* \brief smart pointer class similar to boost::shared_ptr |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
32 |
* |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
33 |
* This smart-pointer class is supposed to be used to manage |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
34 |
* heap-allocated objects: when it decides it does not need |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
35 |
* the object it references, it invokes operator delete on it. |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
36 |
* This implementation allows you to manipulate the smart pointer |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
37 |
* as if it was a normal pointer: you can compare it with zero, |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
38 |
* compare it against other pointers, etc. However, the only |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
39 |
* operation we are careful to avoid is the conversion back to |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
40 |
* raw pointers: if you need to convert back, you need to invoke |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
41 |
* the Ptr<T>::Remove method which returns a raw pointer and |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
42 |
* makes the smart pointer forget about the raw pointer. |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
43 |
*/ |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
44 |
template <typename T> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
45 |
class Ptr |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
46 |
{ |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
47 |
private: |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
48 |
T *m_ptr; |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
49 |
class Tester { |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
50 |
private: |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
51 |
void operator delete (void *); |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
52 |
}; |
225
dad23ccd9e6c
more tests, fix bugs uncovered by tests
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
223
diff
changeset
|
53 |
friend class Ptr<const T>; |
223
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
54 |
public: |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
55 |
/** |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
56 |
* Create an empty smart pointer |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
57 |
*/ |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
58 |
Ptr (); |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
59 |
/** |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
60 |
* \param ptr raw pointer to manage |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
61 |
* |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
62 |
* Create a smart pointer which points to the |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
63 |
* input raw pointer. This method takes ownershipt |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
64 |
* of the input raw pointer. That is, the smart pointer |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
65 |
* becomes responsible for calling delete on the |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
66 |
* raw pointer when needed. |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
67 |
*/ |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
68 |
Ptr (T *ptr); |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
69 |
Ptr (Ptr const&o); |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
70 |
// allow conversions from T to T const. |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
71 |
template <typename U> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
72 |
Ptr (Ptr<U> const &o); |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
73 |
~Ptr () ; |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
74 |
Ptr<T> &operator = (Ptr const& o); |
543 | 75 |
T const& Peek () const; |
76 |
T * Get () const; |
|
223
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
77 |
T *operator -> () const; |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
78 |
T *operator -> (); |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
79 |
// allow if (!sp) |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
80 |
bool operator! (); |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
81 |
// allow if (sp) |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
82 |
operator Tester * () const; |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
83 |
// allow if (sp == 0) |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
84 |
template <typename T1, typename T2> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
85 |
inline friend bool operator == (Ptr<T1> const &lhs, T2 const *rhs); |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
86 |
// allow if (0 == sp) |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
87 |
template <typename T1, typename T2> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
88 |
inline friend bool operator == (T1 const *lhs, Ptr<T2> &rhs); |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
89 |
// allow if (sp != 0) |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
90 |
template <typename T1, typename T2> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
91 |
inline friend bool operator != (Ptr<T1> const &lhs, T2 const *rhs); |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
92 |
// allow if (0 != sp) |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
93 |
template <typename T1, typename T2> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
94 |
inline friend bool operator != (T1 const *lhs, Ptr<T2> &rhs); |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
95 |
|
225
dad23ccd9e6c
more tests, fix bugs uncovered by tests
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
223
diff
changeset
|
96 |
template <typename T1, typename T2> |
dad23ccd9e6c
more tests, fix bugs uncovered by tests
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
223
diff
changeset
|
97 |
inline friend Ptr<T1> const_pointer_cast (Ptr<T2> const&p); |
dad23ccd9e6c
more tests, fix bugs uncovered by tests
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
223
diff
changeset
|
98 |
|
dad23ccd9e6c
more tests, fix bugs uncovered by tests
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
223
diff
changeset
|
99 |
|
223
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
100 |
/** |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
101 |
* \returns raw pointer |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
102 |
* |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
103 |
* It is a programming error to invoke this method when |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
104 |
* the reference count of the smart pointer is not one. |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
105 |
* If you try to do it anyway, an assert will be triggered. |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
106 |
* If asserts are disabled, bad things will happen. |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
107 |
* Once you have successfully called Ptr<T>::Remove on |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
108 |
* a smart pointer, the smart pointer will forget |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
109 |
* about the raw pointer and will stop managing it. As such, |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
110 |
* you, as the caller, become responsible for invoking |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
111 |
* operator delete on the returned raw pointer. |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
112 |
*/ |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
113 |
T *Remove (void); |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
114 |
}; |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
115 |
|
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
116 |
template <typename T> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
117 |
Ptr<T>::Ptr () |
542
00722b9a01b3
Ptr changed to use Object's refcounts
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
432
diff
changeset
|
118 |
: m_ptr (0) |
223
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
119 |
{} |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
120 |
|
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
121 |
template <typename T> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
122 |
Ptr<T>::Ptr (T *ptr) |
542
00722b9a01b3
Ptr changed to use Object's refcounts
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
432
diff
changeset
|
123 |
: m_ptr (ptr) |
00722b9a01b3
Ptr changed to use Object's refcounts
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
432
diff
changeset
|
124 |
{} |
223
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
125 |
|
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
126 |
template <typename T> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
127 |
Ptr<T>::Ptr (Ptr const&o) |
542
00722b9a01b3
Ptr changed to use Object's refcounts
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
432
diff
changeset
|
128 |
: m_ptr (o.m_ptr) |
223
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
129 |
{ |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
130 |
if (m_ptr != 0) |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
131 |
{ |
542
00722b9a01b3
Ptr changed to use Object's refcounts
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
432
diff
changeset
|
132 |
m_ptr->Ref(); |
223
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
133 |
} |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
134 |
} |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
135 |
template <typename T> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
136 |
template <typename U> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
137 |
Ptr<T>::Ptr (Ptr<U> const &o) |
542
00722b9a01b3
Ptr changed to use Object's refcounts
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
432
diff
changeset
|
138 |
: m_ptr (o.m_ptr) |
223
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
139 |
{ |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
140 |
if (m_ptr != 0) |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
141 |
{ |
432
efb4a435205e
fix optimized build warning
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
426
diff
changeset
|
142 |
NS_ASSERT (o.m_ptr != 0); |
542
00722b9a01b3
Ptr changed to use Object's refcounts
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
432
diff
changeset
|
143 |
m_ptr->Ref(); |
223
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
144 |
} |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
145 |
} |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
146 |
|
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
147 |
template <typename T> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
148 |
Ptr<T>::~Ptr () |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
149 |
{ |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
150 |
if (m_ptr != 0) |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
151 |
{ |
542
00722b9a01b3
Ptr changed to use Object's refcounts
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
432
diff
changeset
|
152 |
m_ptr->Unref(); |
223
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
153 |
} |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
154 |
} |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
155 |
|
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
156 |
template <typename T> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
157 |
Ptr<T> & |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
158 |
Ptr<T>::operator = (Ptr const& o) |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
159 |
{ |
426
7d0bde915fd6
Fix Ptr<T>::m_count memory leak in some places.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
286
diff
changeset
|
160 |
if (&o == this) |
7d0bde915fd6
Fix Ptr<T>::m_count memory leak in some places.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
286
diff
changeset
|
161 |
return *this; |
223
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
162 |
if (m_ptr != 0) |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
163 |
{ |
542
00722b9a01b3
Ptr changed to use Object's refcounts
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
432
diff
changeset
|
164 |
m_ptr->Unref(); |
223
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
165 |
} |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
166 |
m_ptr = o.m_ptr; |
426
7d0bde915fd6
Fix Ptr<T>::m_count memory leak in some places.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
286
diff
changeset
|
167 |
if (m_ptr != 0) |
7d0bde915fd6
Fix Ptr<T>::m_count memory leak in some places.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
286
diff
changeset
|
168 |
{ |
542
00722b9a01b3
Ptr changed to use Object's refcounts
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
432
diff
changeset
|
169 |
m_ptr->Ref(); |
426
7d0bde915fd6
Fix Ptr<T>::m_count memory leak in some places.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
286
diff
changeset
|
170 |
} |
223
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
171 |
return *this; |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
172 |
} |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
173 |
|
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
174 |
template <typename T> |
227
482a61824ef4
add ns3::Ptr<T>::operator * with a few tests
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
225
diff
changeset
|
175 |
T const& |
543 | 176 |
Ptr<T>::Peek () const |
227
482a61824ef4
add ns3::Ptr<T>::operator * with a few tests
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
225
diff
changeset
|
177 |
{ |
482a61824ef4
add ns3::Ptr<T>::operator * with a few tests
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
225
diff
changeset
|
178 |
return *m_ptr; |
482a61824ef4
add ns3::Ptr<T>::operator * with a few tests
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
225
diff
changeset
|
179 |
} |
482a61824ef4
add ns3::Ptr<T>::operator * with a few tests
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
225
diff
changeset
|
180 |
|
482a61824ef4
add ns3::Ptr<T>::operator * with a few tests
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
225
diff
changeset
|
181 |
template <typename T> |
543 | 182 |
T * |
183 |
Ptr<T>::Get () const |
|
184 |
{ |
|
185 |
m_ptr->Ref(); |
|
186 |
return m_ptr; |
|
187 |
} |
|
188 |
||
189 |
template <typename T> |
|
223
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
190 |
T * |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
191 |
Ptr<T>::operator -> () |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
192 |
{ |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
193 |
return m_ptr; |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
194 |
} |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
195 |
|
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
196 |
template <typename T> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
197 |
T * |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
198 |
Ptr<T>::operator -> () const |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
199 |
{ |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
200 |
return m_ptr; |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
201 |
} |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
202 |
|
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
203 |
template <typename T> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
204 |
bool |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
205 |
Ptr<T>::operator! () |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
206 |
{ |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
207 |
return m_ptr == 0; |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
208 |
} |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
209 |
|
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
210 |
template <typename T> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
211 |
Ptr<T>::operator Tester * () const |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
212 |
{ |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
213 |
if (m_ptr == 0) |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
214 |
{ |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
215 |
return 0; |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
216 |
} |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
217 |
static Tester test; |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
218 |
return &test; |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
219 |
} |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
220 |
|
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
221 |
template <typename T> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
222 |
T * |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
223 |
Ptr<T>::Remove (void) |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
224 |
{ |
426
7d0bde915fd6
Fix Ptr<T>::m_count memory leak in some places.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
286
diff
changeset
|
225 |
if (m_ptr == 0) |
7d0bde915fd6
Fix Ptr<T>::m_count memory leak in some places.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
286
diff
changeset
|
226 |
{ |
7d0bde915fd6
Fix Ptr<T>::m_count memory leak in some places.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
286
diff
changeset
|
227 |
return (T *) 0; |
7d0bde915fd6
Fix Ptr<T>::m_count memory leak in some places.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
286
diff
changeset
|
228 |
} |
7d0bde915fd6
Fix Ptr<T>::m_count memory leak in some places.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
286
diff
changeset
|
229 |
else |
7d0bde915fd6
Fix Ptr<T>::m_count memory leak in some places.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
286
diff
changeset
|
230 |
{ |
543 | 231 |
//NS_ASSERT (m_ptr->IsSingle()); |
426
7d0bde915fd6
Fix Ptr<T>::m_count memory leak in some places.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
286
diff
changeset
|
232 |
T *retval = m_ptr; |
7d0bde915fd6
Fix Ptr<T>::m_count memory leak in some places.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
286
diff
changeset
|
233 |
m_ptr = 0; |
7d0bde915fd6
Fix Ptr<T>::m_count memory leak in some places.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
286
diff
changeset
|
234 |
return retval; |
7d0bde915fd6
Fix Ptr<T>::m_count memory leak in some places.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
286
diff
changeset
|
235 |
} |
223
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
236 |
} |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
237 |
|
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
238 |
// non-member friend functions. |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
239 |
template <typename T1, typename T2> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
240 |
bool |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
241 |
operator == (Ptr<T1> const &lhs, T2 const *rhs) |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
242 |
{ |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
243 |
return lhs.m_ptr == rhs; |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
244 |
} |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
245 |
template <typename T1, typename T2> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
246 |
bool |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
247 |
operator == (T1 const *lhs, Ptr<T2> &rhs) |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
248 |
{ |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
249 |
return lhs == rhs.m_ptr; |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
250 |
} |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
251 |
template <typename T1, typename T2> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
252 |
bool |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
253 |
operator != (Ptr<T1> const &lhs, T2 const *rhs) |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
254 |
{ |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
255 |
return lhs.m_ptr != rhs; |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
256 |
} |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
257 |
template <typename T1, typename T2> |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
258 |
bool |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
259 |
operator != (T1 const *lhs, Ptr<T2> &rhs) |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
260 |
{ |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
261 |
return lhs != rhs.m_ptr; |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
262 |
} |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
263 |
|
225
dad23ccd9e6c
more tests, fix bugs uncovered by tests
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
223
diff
changeset
|
264 |
template <typename T1, typename T2> |
dad23ccd9e6c
more tests, fix bugs uncovered by tests
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
223
diff
changeset
|
265 |
Ptr<T1> |
dad23ccd9e6c
more tests, fix bugs uncovered by tests
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
223
diff
changeset
|
266 |
const_pointer_cast (Ptr<T2> const&p) |
dad23ccd9e6c
more tests, fix bugs uncovered by tests
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
223
diff
changeset
|
267 |
{ |
dad23ccd9e6c
more tests, fix bugs uncovered by tests
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
223
diff
changeset
|
268 |
return Ptr<T1> (const_cast<T1 *> (p.m_ptr)); |
dad23ccd9e6c
more tests, fix bugs uncovered by tests
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
223
diff
changeset
|
269 |
} |
dad23ccd9e6c
more tests, fix bugs uncovered by tests
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
223
diff
changeset
|
270 |
|
dad23ccd9e6c
more tests, fix bugs uncovered by tests
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
223
diff
changeset
|
271 |
|
223
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
272 |
}; // namespace ns3 |
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
273 |
|
80f1c6b76999
initial go at smart pointer implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
274 |
#endif /* PTR_H */ |