2 fegdk: FE Game Development Kit
3 Copyright (C) 2001-2008 Alexey "waker" Yakovenko
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 waker@users.sourceforge.net
33 virtual void call (void *data
) = 0;
36 // this class is used to store/access objects of different types in one list
37 class virtualDtorObject
40 virtual ~virtualDtorObject (void) {}
43 template <class T1
, class T2
>
44 inline const T1
checked_cast (T2 src
)
47 assert (dynamic_cast <T1
> (src
));
48 return static_cast <T1
> (src
);
51 template <class T
> class heapBuffer
54 // first buffer byte is a refc
58 unsigned char* mpBuffer
;
65 mpBuffer
= new unsigned char[cnt
* sizeof (T
) + 1];
69 heapBuffer (const heapBuffer
&b
)
71 mpBuffer
= b
.mpBuffer
;
77 if (--mpBuffer
[0] == 0)
83 return (T
*) (mpBuffer
+ 1);
88 template <class T
> class noAddrefReleaseOnSmartRefcPtr
: public T
91 noAddrefReleaseOnSmartRefcPtr (void) : T (NULL
) {}
92 virtual void addRef () = 0;
93 virtual void release () = 0;
96 template <class T
> class smartPtr
112 if ( (p
= lp
) != NULL
)
116 smartPtr (const smartPtr
<T
>& lp
)
118 if ( (p
= lp
.p
) != NULL
)
133 /* T& operator* () const
145 noAddrefReleaseOnSmartRefcPtr
<T
>* operator-> () const
148 return (noAddrefReleaseOnSmartRefcPtr
<T
>*)p
;
154 if ( (p
= lp
) != NULL
)
161 T
* operator= (const smartPtr
<T
>& lp
)
164 if ( (p
= lp
.p
) != NULL
)
171 template <class N
> smartPtr
<N
> dynamicCast (void) const
173 return p
? smartPtr
<N
> (checked_cast
<N
*> (p
)) : smartPtr
<N
> (NULL
);
178 template <class T
> class autoPtr
203 operator const T
* () const
213 #endif // __F_HELPERS_H