source: trunk/src/core/RpPtr.cc @ 2726

Last change on this file since 2726 was 1328, checked in by gah, 16 years ago

added missing assert.h headers

File size: 916 bytes
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
17using namespace Rappture;
18
19PtrCore::PtrCore(void* ptr)
20  : _ptr(ptr),
21    _refcount(1)
22{
23}
24
25PtrCore::~PtrCore()
26{
27    assert(_refcount <= 0);
28}
29
30void*
31PtrCore::pointer() const
32{
33    return _ptr;
34}
35
36void
37PtrCore::attach()
38{
39    _refcount++;
40}
41
42void*
43PtrCore::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.