Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: ANN: AutoNe...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 13 Topic 9589 of 9828
Post > Topic >>

Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)

by "Alf P. Steinbach" <alfps@[EMAIL PROTECTED] > May 12, 2008 at 04:38 AM

* Alf P. Steinbach:
> I just coded this up, and hopefully by mentioning it here I'll get some 
> useful feedback, like, bugs, shortcomings, improvements...
> 
>
http://code.google.com/p/alfps/source/browse/trunk/alfs/pointers/AutoNewPtr.hpp

> (http://preview.tinyurl.com/3puorr)
> 
> AutoNewPtr ("new" Berkeley open source license)
> 
>   * Is not initialized with a raw pointer, but with constructor
>     arguments for the to-be referent: AutoNewPtr takes responsibility
>     for 'new'.
> 
>   * By doing that, it has the ability to add a notifier to the created
>     object, so that the smart pointer gets notified when referred
>     object self-destructs, if it does (e.g., a window or file closing,
>     or a non-correctable error).
> 
>   * After referred object destroyed, pointer re****ts that it's void
>     and throws on access via ->.
> 
>   * Also, the default constructor sets the pointer to void state.
> 
>   * Otherwise much like shared_ptr, except customization of deleter is
>     per type (via c++0x-like std::default_delete) rather than per
>     instance.

Now added dynamic cast functionality, but so far only the non-throwing
kind, i.e. nullpointer (void pointer) if the cast fails.

In the same way as avoiding explicit 'new' lets you avoid redundantly
stating the type twice  --  stating the type twice is more to write
and one more place a little bug might creep in  --  I thought it would
be nice if the same could be done for dynamic cast.

So the usage syntax is like (straight from basic test code, i.e. this
is code that compiles and works)


<code>
class PolymorphicA { public: virtual ~PolymorphicA() {} };
class PolymorphicB { public: virtual ~PolymorphicB() {} };
class Polymorphic: public PolymorphicA, public PolymorphicB {};

.....
         AutoNewPtr<Polymorphic>     p( newNoArgs );
         AutoNewPtr<PolymorphicA>    a = p;

         AutoNewPtr<PolymorphicB>    b = a.convertedOrVoid();

         b = a.convertedOrVoid();

</code>


Don't know if this is "magic" yet... :-)


> Praise and la****ngs and wild ideas all welcome.
> 
> Note that this is just freshly coded, it's currently more idea stuff 
> than anything else, but, might still be useful as-is!


Cheers,

- Alf

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 13 Posts in Topic:
ANN: AutoNewPtr (oh yes, yet another smartpointer)
"Alf P. Steinbach&qu  2008-05-11 09:42:27 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
=?ISO-8859-1?Q?Daniel_Kr=  2008-05-11 16:39:48 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
"Alf P. Steinbach&qu  2008-05-11 20:13:20 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
"Alf P. Steinbach&qu  2008-05-11 20:13:18 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
"Alf P. Steinbach&qu  2008-05-12 04:38:03 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
rpbg123@[EMAIL PROTECTED]  2008-05-12 09:27:13 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
Kai-Uwe Bux <jkherciue  2008-05-13 21:13:58 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
"Alf P. Steinbach&qu  2008-05-14 12:53:54 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
"Alf P. Steinbach&qu  2008-05-14 15:11:54 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
dizzy <dizzy@[EMAIL PR  2008-05-15 11:16:50 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
"Alf P. Steinbach&qu  2008-05-16 11:57:29 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
rpbg123@[EMAIL PROTECTED]  2008-05-16 17:29:51 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
"Alf P. Steinbach&qu  2008-05-18 02:43:50 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 15:59:26 CDT 2008.