|
Boost : |
From: Borgerding, Mark A. (MarkAB_at_[hidden])
Date: 2000-02-08 10:50:48
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
In the linked_ptr class, I have the method dynamic_cast_from
returning get(). This was a change from my initial implementation
which returned a reference to *this. Small change, but it allows the
user to more easily do a conversion and test in 1 step.
e.g.
if ( myDerived.dynamic_cast_from( myBase ) ) { // dynamic_cast and
test
//myDerived now holds a non-null, correctly typed ptr
}else {
//myBase is not a derived type
}
- -- Mark
> -----Original Message-----
> From: Miki Jovanovic [mailto:miki_at_[hidden]]
> Sent: Tuesday, February 08, 2000 10:29 AM
> To: boost_at_[hidden]
> Subject: [boost] dynamic_cast for shared_ptr
>
>
>
> Hello all,
>
> Here is my proposition for dynamic_cast for shared_ptr. Would this
> be of value?
>
> public:
> template<typename Y> shared_ptr& dynamiccast( const
> shared_ptr<Y>& r
> ) {
> if ( pn != r.pn ) {
> dispose();
>
> dynamicShare( r.px, r.pn );
> }
> return *this;
> }
>
> protected:
> template<typename Y> void dynamicShare( Y* rpx, long* rpn ) {
> Y *cast_rpx = dynamic_cast<T*>( rpx );
> if ( rpx == NULL || cast_rpx != NULL ) { // check to avoid
> new() for NULL objects. too much?
> px = rpx;
> ++*(pn = rpn);
> }
> else { // dynamic_cast failed
> px = NULL;
> pn = new long(1);
> }
> }
>
>
> Cheers,
>
> Miki Jovanovic.
>
>
> --------------------------------------------------------------
> ----------
> What's better than getting a Great Deal from eGroups?
> Getting a Great Deal from eGroups delivered right to your
> email in-box!
> http://click.egroups.com/1/1236/1/_/9351/_/950023978/
>
> eGroups.com Home: http://www.egroups.com/group/boost/
> http://www.egroups.com - Simplifying group communications
>
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>
iQA/AwUBOKA7XP9Ej8AEXMygEQI4jACfZhD0lUoChuL2ueD2bo57SiZsQmwAn2AI
Of3zwoMJJn4RSyQOUbBSmpkv
=0oXP
-----END PGP SIGNATURE-----
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk