Line | |
---|
1 | /* |
---|
2 | * ====================================================================== |
---|
3 | * Rappture::Ptr<type> |
---|
4 | * |
---|
5 | * AUTHOR: Michael McLennan, Purdue University |
---|
6 | * Copyright (c) 2004-2006 Purdue Research Foundation |
---|
7 | * ---------------------------------------------------------------------- |
---|
8 | * See the file "license.terms" for information on usage and |
---|
9 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
10 | * ====================================================================== |
---|
11 | */ |
---|
12 | |
---|
13 | #include <stdlib.h> |
---|
14 | #include <RpPtr.h> |
---|
15 | #include <assert.h> |
---|
16 | |
---|
17 | using namespace Rappture; |
---|
18 | |
---|
19 | PtrCore::PtrCore(void* ptr) |
---|
20 | : _ptr(ptr), |
---|
21 | _refcount(1) |
---|
22 | { |
---|
23 | } |
---|
24 | |
---|
25 | PtrCore::~PtrCore() |
---|
26 | { |
---|
27 | assert(_refcount <= 0); |
---|
28 | } |
---|
29 | |
---|
30 | void* |
---|
31 | PtrCore::pointer() const |
---|
32 | { |
---|
33 | return _ptr; |
---|
34 | } |
---|
35 | |
---|
36 | void |
---|
37 | PtrCore::attach() |
---|
38 | { |
---|
39 | _refcount++; |
---|
40 | } |
---|
41 | |
---|
42 | void* |
---|
43 | PtrCore::detach() |
---|
44 | { |
---|
45 | if (--_refcount <= 0 && _ptr != NULL) { |
---|
46 | return _ptr; |
---|
47 | } |
---|
48 | return NULL; |
---|
49 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.