source: trunk/src2/core/Ptr.cpp @ 829

Last change on this file since 829 was 576, checked in by dkearney, 17 years ago

moved rappture.h to rappture2.h becasue src/core already has a rappture.h
also changed Ptr.h, Ptr.cpp, and Outcome.h to use rappture2.h
updated Makefile.in, Makefile will now be created by rappture's configure.in

File size: 879 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#include "rappture2.h"
13
14using namespace Rappture;
15
16PtrCore::PtrCore(void* ptr)
17  : _ptr(ptr),
18    _refcount(1)
19{
20}
21
22PtrCore::~PtrCore()
23{
24    assert(_refcount <= 0);
25}
26
27void*
28PtrCore::pointer() const
29{
30    return _ptr;
31}
32
33void
34PtrCore::attach()
35{
36    _refcount++;
37}
38
39void*
40PtrCore::detach()
41{
42    if (--_refcount <= 0 && _ptr != NULL) {
43        return _ptr;
44    }
45    return NULL;
46}
Note: See TracBrowser for help on using the repository browser.