|
32 | 32 | * @code
|
33 | 33 | * #include "platform/SharedPtr.h"
|
34 | 34 | *
|
35 |
| - * struct MyStruct { int a; }; |
| 35 | + * void test() { |
| 36 | + * struct MyStruct { int a; }; |
36 | 37 | *
|
37 |
| - * // Create shared pointer |
38 |
| - * SharedPtr<MyStruct> ptr( new MyStruct ); |
| 38 | + * // Create shared pointer |
| 39 | + * SharedPtr<MyStruct> ptr( new MyStruct ); |
39 | 40 | *
|
40 |
| - * // Increase reference count |
41 |
| - * SharedPtr<MyStruct> ptr2( ptr ); |
| 41 | + * // Increase reference count |
| 42 | + * SharedPtr<MyStruct> ptr2( ptr ); |
42 | 43 | *
|
43 |
| - * ptr = NULL; // Reference to the struct instance is still held by ptr2 |
| 44 | + * ptr = NULL; // Reference to the struct instance is still held by ptr2 |
44 | 45 | *
|
45 |
| - * ptr2 = NULL; // The raw pointer is freed |
| 46 | + * ptr2 = NULL; // The raw pointer is freed |
| 47 | + * } |
46 | 48 | * @endcode
|
47 | 49 | *
|
48 | 50 | *
|
49 | 51 | * It is similar to the std::shared_ptr class introduced in C++11,
|
50 | 52 | * however this is not a compatible implementation (no weak pointer, no make_shared, no custom deleters, etc.)
|
51 | 53 | *
|
52 |
| - * Usage: SharedPtr<class> POINTER(new class()) |
| 54 | + * Usage: SharedPtr<Class> ptr(new Class()) |
53 | 55 | *
|
54 |
| - * When POINTER is passed around by value the copy constructor and |
55 |
| - * destructor counts the number of references to the original object. |
56 |
| - * If the counter reaches zero, delete is called on the object pointed to. |
| 56 | + * When ptr is passed around by value the copy constructor and |
| 57 | + * destructor manages the reference count of the raw pointer. |
| 58 | + * If the counter reaches zero, delete is called on the raw pointer. |
57 | 59 | *
|
58 | 60 | * To avoid loops, "weak" references should be used by calling the original
|
59 |
| - * pointer directly through POINTER.get(). |
| 61 | + * pointer directly through ptr.get(). |
60 | 62 | */
|
61 | 63 |
|
62 | 64 | template <class T>
|
|
0 commit comments