www.digitalmars.com         C & C++   DMDScript  

c++.stlsoft - [COMSTL; Adi's report] stlsoft::interface_ptr is a zombie; use stlsoft::ref_ptr

reply "Matthew" <matthew hat.stlsoft.dot.org> writes:
Adi

comstl::interface_ptr<> is obsolete. It offers nothing that
stlsoft::ref_ptr<> does not; it actually offers less.

I don't know why this component has continued to be available. I've just
grepped all my sources and can find only a single use of it (which I've just
changed).

My apologies for having left it in there.

The preferred approach is to use stlsoft::ref_ptr<>. Why? Because it
facilitates forward declaration of a smart pointer specialisation. (I'm
working on a small article to explain how/why, which I hope to publish -
perhaps on CodeProject - soonish.)

I'm changing comstl/smartptr/interface_ptr.hpp as we speak to issue a
warning if included, and will redefine the class to be implemented in terms
of stlsoft::ref_ptr<>.

Sorry about that ... :$

Matthew

And now to the next question ...
Dec 01 2006
parent reply Adi Shavit <adish gentech.co.il> writes:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body dir="ltr" bgcolor="#ffffff" text="#000066">
<p style="margin-bottom: 0cm; margin-top: 0pt;"><font size="-1"><font
 face="Verdana">I wasn't even aware of ref_ptr.</font></font></p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><span
 style="font-size: 13px;"><font face="Verdana">I'll try it and let you
know how it goes.<br>
</font></span><span style="font-size: 13px;"></span></p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><span
 style="font-size: 13px;"><font face="Verdana">Adi</font></span><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><span
 style="font-size: 13px;"></span><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><span
 style="font-size: 13px;"></span></p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
Matthew wrote:<br>
</p>
<blockquote cite="midekrbio$313n$1 digitaldaemon.com" type="cite">
  <pre wrap="">Adi

comstl::interface_ptr&lt;&gt; is obsolete. It offers nothing that
stlsoft::ref_ptr&lt;&gt; does not; it actually offers less.

I don't know why this component has continued to be available. I've just
grepped all my sources and can find only a single use of it (which I've just
changed).

My apologies for having left it in there.

The preferred approach is to use stlsoft::ref_ptr&lt;&gt;. Why? Because it
facilitates forward declaration of a smart pointer specialisation. (I'm
working on a small article to explain how/why, which I hope to publish -
perhaps on CodeProject - soonish.)

I'm changing comstl/smartptr/interface_ptr.hpp as we speak to issue a
warning if included, and will redefine the class to be implemented in terms
of stlsoft::ref_ptr&lt;&gt;.

Sorry about that ... :$

Matthew

And now to the next question ...



  </pre>
</blockquote>
</body>
</html>
Dec 03 2006
parent reply Adi Shavit <adish gentech.co.il> writes:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000099">
<font face="Verdana">I see that ref_ptr doesn't have a set() method.<br>
How can I implement the code I posted before:<br>
</font>
<blockquote><font face="Courier New, Courier,
monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //
Create a source filter specified by filename<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; interface_ptr&lt;IBaseFilter&gt; pSource; // The
interface_ptr&lt;&gt; object<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IBaseFilter* ppSource= NULL;
// temporary bare pointer<br>
  <br>
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if(FAILED(pGraph-&gt;AddSourceFilter(a2w(c_str_ptr(filename)),0,&amp;ppSource)))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
pSource.<u><b>set</b></u>(ppSource, false); // setting the
smart pointer.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br>
  </font></blockquote>
<font face="Verdana">Am I missing something??<br>
<br>
Adi<br>
</font><br>
Adi Shavit wrote:
<blockquote cite="mid4572E9F7.7040801 gentech.co.il" type="cite">
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <p style="margin-bottom: 0cm; margin-top: 0pt;"><font size="-1"><font
 face="Verdana">I wasn't even aware of ref_ptr.</font></font></p>
  <p style="margin-bottom: 0cm; margin-top: 0pt;"><span
 style="font-size: 13px;"><font face="Verdana">I'll try it and let you
know how it goes.<br>
  </font></span><span style="font-size: 13px;"></span></p>
  <p style="margin-bottom: 0cm; margin-top: 0pt;"><span
 style="font-size: 13px;"><font face="Verdana">Adi</font></span><br>
  </p>
  <p style="margin-bottom: 0cm; margin-top: 0pt;"><span
 style="font-size: 13px;"></span><br>
  </p>
  <p style="margin-bottom: 0cm; margin-top: 0pt;"><span
 style="font-size: 13px;"></span></p>
  <p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
Matthew wrote:<br>
  </p>
  <blockquote cite="midekrbio$313n$1 digitaldaemon.com" type="cite">
    <pre wrap="">Adi

comstl::interface_ptr&lt;&gt; is obsolete. It offers nothing that
stlsoft::ref_ptr&lt;&gt; does not; it actually offers less.

I don't know why this component has continued to be available. I've just
grepped all my sources and can find only a single use of it (which I've just
changed).

My apologies for having left it in there.

The preferred approach is to use stlsoft::ref_ptr&lt;&gt;. Why? Because it
facilitates forward declaration of a smart pointer specialisation. (I'm
working on a small article to explain how/why, which I hope to publish -
perhaps on CodeProject - soonish.)

I'm changing comstl/smartptr/interface_ptr.hpp as we speak to issue a
warning if included, and will redefine the class to be implemented in terms
of stlsoft::ref_ptr&lt;&gt;.

Sorry about that ... :$

Matthew

And now to the next question ...



  </pre>
  </blockquote>
</blockquote>
</body>
</html>
Dec 05 2006
parent reply "Matthew" <matthew hat.stlsoft.dot.org> writes:
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

You use conversion constructor and copy assignment, as in:

      interface_ptr<IBaseFilter> pSource; // The interface_ptr<> object
      {
         IBaseFilter* ppSource=3D NULL; // temporary bare pointer


         =
if(FAILED(pGraph->AddSourceFilter(a2w(c_str_ptr(filename)),0,&ppSource)))=

         {
           //...
           return 0;
         }
         pSource =3D interface_ptr<IBaseFilter>(ppSource, false); // =
setting the smart pointer.
      }=20

But since, in your code, you've not used a typedef (I would usually =
define IBaseFilter_ptr) this looks like more of a burden than I'm used =
to.

There's no reason why you should do the typedef thing, of course.

btw, I would normally do this differently, as in:

      {
         IBaseFilter* ppSource=3D NULL; // temporary bare pointer


         =
if(FAILED(pGraph->AddSourceFilter(a2w(c_str_ptr(filename)),0,&ppSource)))=

         {
           //...
           return 0;
         }
         else
         {
            interface_ptr<IBaseFilter> pSource(ppSource, false); // =
setting the smart pointer.

            . . .
         }
      }=20


But again, there's no reason why you _must_ follow the way I do it. So =
it looks like a set() method's called for. (As you'll probably have =
picked up on by now, I don't like adding _any_ functionality until it's =
proven to be needed. But, once it's proven, well ...)

I'll make this change now, and it'll be in beta 31 (31!). That should be =
available in the next 36 hrs, maybe sooner. ;-)

Cheers

Matthew

  "Adi Shavit" <adish gentech.co.il> wrote in message =
news:4575C6FD.9060408 gentech.co.il...
  I see that ref_ptr doesn't have a set() method.
  How can I implement the code I posted before:

          // Create a source filter specified by filename
          interface_ptr<IBaseFilter> pSource; // The interface_ptr<> =
object
          {
             IBaseFilter* ppSource=3D NULL; // temporary bare pointer


             =
if(FAILED(pGraph->AddSourceFilter(a2w(c_str_ptr(filename)),0,&ppSource)))=

             {
               //...
               return 0;
             }
             pSource.set(ppSource, false); // setting the smart pointer.
          }=20

  Am I missing something??

  Adi

  Adi Shavit wrote:=20
    I wasn't even aware of ref_ptr.

    I'll try it and let you know how it goes.


    Adi







    Matthew wrote:


Adi

comstl::interface_ptr<> is obsolete. It offers nothing that
stlsoft::ref_ptr<> does not; it actually offers less.

I don't know why this component has continued to be available. I've just
grepped all my sources and can find only a single use of it (which I've =
just
changed).

My apologies for having left it in there.

The preferred approach is to use stlsoft::ref_ptr<>. Why? Because it
facilitates forward declaration of a smart pointer specialisation. (I'm
working on a small article to explain how/why, which I hope to publish -
perhaps on CodeProject - soonish.)

I'm changing comstl/smartptr/interface_ptr.hpp as we speak to issue a
warning if included, and will redefine the class to be implemented in =
terms
of stlsoft::ref_ptr<>.

Sorry about that ... :$

Matthew

And now to the next question ...



  
Dec 05 2006
parent Adi Shavit <adish gentech.co.il> writes:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000099">
<font face="Verdana">See below...</font><br>
<br>
Matthew wrote:
<blockquote cite="midel4iik$1rnv$1 digitaldaemon.com" type="cite">
  <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
  <meta content="MSHTML 6.00.2800.1578" name="GENERATOR">
  <style></style>
  <div><font color="#000000" face="Arial" size="2">You use conversion
constructor and copy assignment, as in:</font></div>
  <div>&nbsp;</div>
  <div><font color="#000000" face="Arial" size="2"><font
 face="Courier New" size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
interface_ptr&lt;IBaseFilter&gt;
pSource; // The interface_ptr&lt;&gt; object<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IBaseFilter* ppSource= NULL;
// temporary bare pointer<br>
  <br>
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if(FAILED(pGraph-&gt;AddSourceFilter(a2w(c_str_ptr(filename)),0,&amp;ppSource)))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSource =
<strong>interface_ptr&lt;IBaseFilter&gt;</strong>(ppSource,
false); // setting the smart pointer.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } </font><br>
  </font></div>
  <div><font color="#000000" face="Arial" size="2">But since, in your
code, you've not used a typedef (I would usually define
<strong>IBaseFilter_ptr</strong>)
this looks like more of a burden than I'm used to.</font></div>
  <div>&nbsp;</div>
  <div><font color="#000000" face="Arial" size="2">
  <div><font color="#000000" face="Arial" size="2">There's no reason
why you should do the typedef thing, of course.</font></div>
  </font></div>
</blockquote>
<font face="Verdana">Yes, I guessed that was how you intended it to be
used, though it seems to give the wrong impression, it feels odd.<br>
</font>
<blockquote cite="midel4iik$1rnv$1 digitaldaemon.com" type="cite">
  <div><font color="#000000" face="Arial" size="2">
  <div>&nbsp;</div>
btw, I would normally do this differently, as in:</font></div>
  <div>&nbsp;</div>
  <div><font color="#000000" face="Arial" size="2"><font
 face="Courier New" size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IBaseFilter* ppSource= NULL;
// temporary bare pointer<br>
  <br>
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if(FAILED(pGraph-&gt;AddSourceFilter(a2w(c_str_ptr(filename)),0,&amp;ppSource)))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></font></div>
  <div><font color="#000000" face="Arial" size="2"><font
 face="Courier New" size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else</font></font></div>
  <div><font color="#000000" face="Arial" size="2"><font
 face="Courier New" size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</font></font></div>
  <div><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>interface_ptr&lt;IBaseFilter&gt;</strong>
pSource</font><font color="#000000" face="Arial" size="2"><font
 face="Courier New" size="3">(ppSource, false); // setting the smart
pointer.</font></font></div>
  <div>&nbsp;</div>
  <div><font color="#000000" face="Courier
New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.
. .</font></div>
  <div><font color="#000000" face="Arial" size="2"><font
 face="Courier New" size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</font></font></div>
  <div><font color="#000000" face="Arial" size="2"><font
 face="Courier New" size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } </font><br>
  </font></div>
  <div>&nbsp;</div>
</blockquote>
<font face="Verdana">That's relevant only if pSource is used within the
scope of the else.<br>
If pSource external (e.g. a member), you would still need a
set()[-like] mechanism.<br>
<br>
</font>
<blockquote cite="midel4iik$1rnv$1 digitaldaemon.com" type="cite">
  <div><font color="#000000" face="Arial" size="2">But again, there's
no reason why you _must_ follow the way I do it. S</font><font
 color="#000000" face="Arial" size="2">o it looks like a <strong>set()</strong>
method's called for. (</font><font color="#000000" face="Arial" size="2">As
you'll probably have picked up on by now, I don't like adding _any_
functionality until it's proven to be needed. But, once it's proven,
well ...)</font></div>
  <div>&nbsp;</div>
  <div><font color="#000000" face="Arial" size="2">I'll make this
change now, and it'll be in beta 31 (31!). That should be available in
the next 36 hrs, maybe sooner. ;-)</font></div>
</blockquote>
<font face="Verdana">BTW, if the set/ctor would throw for a NULL ptr in
this example, the if check would be unnecessary (assuming it is part of
a bigger try-catch block), and the code would be more readable.<br>
<br>
Adi<br>
<br>
</font>
</body>
</html>
Dec 05 2006