LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2006 INRIA | 3 * Copyright (c) 2006 INRIA |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 static void | 87 static void |
88 ClearPtr (void) | 88 ClearPtr (void) |
89 { | 89 { |
90 g_ptr = 0; | 90 g_ptr = 0; |
91 } | 91 } |
92 | 92 |
93 | 93 |
94 | 94 |
95 int main (int argc, char *argv[]) | 95 int main (int argc, char *argv[]) |
96 { | 96 { |
| 97 CommandLine cmd; |
| 98 cmd.Parse(argc, argv); |
| 99 |
97 { | 100 { |
98 // Create a new object of type PtrExample, store it in global· | 101 // Create a new object of type PtrExample, store it in global· |
99 // variable g_ptr | 102 // variable g_ptr |
100 Ptr<PtrExample> p = CreateObject<PtrExample> (); | 103 Ptr<PtrExample> p = CreateObject<PtrExample> (); |
101 p->Method (); | 104 p->Method (); |
102 Ptr<PtrExample> prev = StorePtr (p); | 105 Ptr<PtrExample> prev = StorePtr (p); |
103 NS_ASSERT (prev == 0); | 106 NS_ASSERT (prev == 0); |
104 } | 107 } |
105 | 108 |
106 { | 109 { |
107 // Create a new object of type PtrExample, store it in global· | 110 // Create a new object of type PtrExample, store it in global· |
108 // variable g_ptr, get a hold on the previous PtrExample object. | 111 // variable g_ptr, get a hold on the previous PtrExample object. |
109 Ptr<PtrExample> p = CreateObject<PtrExample> (); | 112 Ptr<PtrExample> p = CreateObject<PtrExample> (); |
110 Ptr<PtrExample> prev = StorePtr (p); | 113 Ptr<PtrExample> prev = StorePtr (p); |
111 // call method on object | 114 // call method on object |
112 prev->Method (); | 115 prev->Method (); |
113 // Clear the currently-stored object | 116 // Clear the currently-stored object |
114 ClearPtr (); | 117 ClearPtr (); |
115 // get the raw pointer and release it. | 118 // get the raw pointer and release it. |
116 PtrExample *raw = GetPointer (prev); | 119 PtrExample *raw = GetPointer (prev); |
117 prev = 0; | 120 prev = 0; |
118 raw->Method (); | 121 raw->Method (); |
119 raw->Unref (); | 122 raw->Unref (); |
120 } | 123 } |
121 | 124 |
122 | 125 |
123 return 0; | 126 return 0; |
124 } | 127 } |
LEFT | RIGHT |