5 * Copyright (C) 2009 Pawel Dziepak
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 // mutable checked<unsigned int> &refs;
34 /* Pointers can not be placed on a heap */
35 // static void *operator new(unsigned int);
36 // static void operator delete(void *);
38 static const p
<T
> invalid
;
41 p() : pointer(0)/*, refs(*new checked<unsigned int>(0)) */{}
43 p(T
*ptr
) : pointer(ptr
)/*, refs(*new checked<unsigned int>(1))*/ {
48 p(T
*ptr
, checked
<unsigned int> &r
) : pointer(ptr
)/*, refs(r)*/ {}
58 p(const p
<T
> &cpy
) : pointer(cpy
.pointer
)/*, refs(cpy.refs) */{
64 p
<U
> pt(dynamic_cast<U
*>(pointer
)/*, refs*/);
71 p
<T
> &operator=(const p
<T
> mve
) {
80 pointer
= mve
.pointer
;
87 bool operator==(unsigned int x
) {
88 return (unsigned int)pointer
== x
;
91 bool operator!=(unsigned int x
) {
92 return (unsigned int)pointer
!= x
;
96 U
*cast(bool unsafe
) {
101 //debug("we dont like this");
102 /* We won't be able to collect garbage if pointer goes unsafe. */
111 //assert("attempt to dereference a null pointer", !pointer);
119 //assert("attempt to dereference a null pointer", !pointer);
127 //if (((unsigned int)pointer <= 0x100000 && (int)pointer != 0) || (unsigned int)pointer >= 0x400000)
128 // asm("cli\nhlt"::"a"(pointer), "b"(0xbad0713));
129 return (pointer
!= (T
*)0 && (unsigned int)pointer
< 0x400000);
133 bool operator==(p
<U
> _x
) {
134 p
<T
> x
= _x
.cast
<T
>();
135 return x
.pointer
== pointer
;
138 bool operator==(p
<T
> x
) {
139 return x
.pointer
== pointer
;
144 const p
<T
> p
<T
>::invalid
= p
<T
>(0);