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

Last change on this file since 3177 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

File size: 913 bytes
Line 
1/*
2 * ======================================================================
3 *  Rappture::Ptr<type>
4 *
5 *  AUTHOR:  Michael McLennan, Purdue University
6 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
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.