1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
4 * Moonlight List (moonlight-list@lists.ximian.com)
6 * Copyright 2007 Novell, Inc. (http://www.novell.com)
8 * See the LICENSE file included with the distribution for details.
12 #ifndef __MONO_PTR_H__
13 #define __MONO_PTR_H__
19 // to prevent unwanted assignments
22 void operator==(const PtrBase
&b
) const;
23 void operator!=(const PtrBase
&b
) const;
27 /*************************************************************
28 DOPtr takes ownership of a refcounted object, so it won't
29 touch the initial refcount, it will only unref when destroyed
30 **************************************************************/
32 class DOPtr
: private PtrBase
{
34 DOPtr(T
* ptr
= 0) : value(ptr
), initted(false) {
39 ds (printf("~DOPtr %p %p %d\n", this, value
, initted
));
43 operator bool() const { return(value
!= 0); }
45 DOPtr
* operator=(T
* ptr
) {
50 if (old
&& initted
) old
->unref();
55 T
* get() const { return value
; }
56 T
* operator->() const { return value
; }
57 T
& operator*() const { return *value
; }
59 operator T
*() { return value
; }
62 operator U
*() { return static_cast<U
*> (value
); }
69 ds (printf("init %p %p\n", this, value
));