www.digitalmars.com         C & C++   DMDScript  

c++.stlsoft - [COMSTL; Adi's report] ref_ptr<> as a unit of currency ...

reply "Matthew" <matthew hat.stlsoft.dot.org> writes:
 5. Functions like co_create_instance and other initialization functions
 expect an address of a pointer as the second argument. This means that
 when used with interface_ptr, a temporary bare pointer must be used to
 be given like so:

        // Create a source filter specified by filename
        interface_ptr<IBaseFilter> pSource; // The interface_ptr<> object
        {
           IBaseFilter* ppSource= 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.
        }

Agree that this is not pretty.
 It would be useful to have a method that exposes the internal member so
 it can be used directly in such functions.
 I know it might be dangerous (although there is an option to get the
 referent anyway) but maybe it should be considered.

I can't do this. This is one of the fatal mistakes made in ATL. I think a better way is to make it a design parameter of COMSTL that interface wrappers - i.e. stlsoft::ref_ptr<X> - are a fundamental unit of currency of the library. Thus, we would then overload the co_create_instance() function suite to work with stlsoft::ref_ptr<..., I> wrappers as well as raw pointers (I), as in: { const CLSID CLSID_pantheios_COM_LoggerManager = { 0x4E7D5C47, 0x8F96, 0x45DE, { 0x90, 0x5D, 0xAA, 0x3E, 0x9E, 0x59, 0x2D, 0xE3 } }; stlsoft::ref_ptr<IDispatch> logmgr; if(SUCCEEDED(comstl::co_create_instance(CLSID_pantheios_COM_LoggerManager, logmgr))) { } } { stlsoft::ref_ptr<IDispatch> logmgr; if(SUCCEEDED(comstl::co_create_instance(L"{4E7D5C47-8F96-45DE-905D-AA3E9E592 DE3}", logmgr))) { } } { stlsoft::ref_ptr<IDispatch> logmgr; if(SUCCEEDED(comstl::co_create_instance(L"pantheios.COM.LoggerManager", logmgr))) { } } This is acceptable in terms of physical coupling because stlsoft/smartptr/ref_ptr.hpp does not include any other headers (except stlsoft/stlsoft.h, of course), so the impact on compilation times and other -ve physical effects will be negligble. I'd like to hear from anyone who has any opinions on this question, i.e. Should interface wrappers be a fundamental unit of currency in COMSTL? Cheers Matthew
Dec 02 2006
parent reply "Matthew" <matthew hat.stlsoft.dot.org> writes:
"Matthew" <matthew hat.stlsoft.dot.org> wrote in message
news:ekt56t$1var$1 digitaldaemon.com...
 5. Functions like co_create_instance and other initialization functions
 expect an address of a pointer as the second argument. This means that
 when used with interface_ptr, a temporary bare pointer must be used to
 be given like so:

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


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

Agree that this is not pretty.
 It would be useful to have a method that exposes the internal member so
 it can be used directly in such functions.
 I know it might be dangerous (although there is an option to get the
 referent anyway) but maybe it should be considered.

I can't do this. This is one of the fatal mistakes made in ATL. I think a better way is to make it a design parameter of COMSTL that interface wrappers - i.e. stlsoft::ref_ptr<X> - are a fundamental unit of currency of the library. Thus, we would then overload the co_create_instance() function suite to work with stlsoft::ref_ptr<..., I> wrappers as well as raw pointers (I), as in: { const CLSID CLSID_pantheios_COM_LoggerManager = { 0x4E7D5C47, 0x8F96, 0x45DE, { 0x90, 0x5D, 0xAA, 0x3E, 0x9E, 0x59, 0x2D, 0xE3 } }; stlsoft::ref_ptr<IDispatch> logmgr; if(SUCCEEDED(comstl::co_create_instance(CLSID_pantheios_COM_LoggerManager, logmgr))) { } } { stlsoft::ref_ptr<IDispatch> logmgr;

 DE3}", logmgr)))
     {
     }
   }

   {
     stlsoft::ref_ptr<IDispatch> logmgr;

 logmgr)))
     {
     }
   }

 This is acceptable in terms of physical coupling because
 stlsoft/smartptr/ref_ptr.hpp does not include any other headers (except
 stlsoft/stlsoft.h, of course), so the impact on compilation times and
 other -ve physical effects will be negligble.

Just implemented this one, and it works a treat! Be out in 1.9.1 beta 31. (Oh when will I *ever* release 1.9.1 proper!? <g>) If you can, I'd appreciate feedback whenever you find a place within the libraries where an interface wrapper should be the means of currency. Cheers Matthew
Dec 02 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">
</head>
<body bgcolor="#ffffff" text="#000099">
<font face="Verdana">That's good and related to my 6th question, but it
does not really help with the example I gave.<br>
Adi<br>
</font><br>
Matthew wrote:
<blockquote cite="midekt6ot$218r$1 digitaldaemon.com" type="cite">
  <pre wrap="">"Matthew" <a class="moz-txt-link-rfc2396E"
href="mailto:matthew hat.stlsoft.dot.org">&lt;matthew hat.stl
oft.dot.org&gt;</a> wrote in message
<a class="moz-txt-link-freetext"
href="news:ekt56t$1var$1 digitaldaemon.com">news:ekt56t$1var$1 digitaldaemon.com</a>...
  </pre>
  <blockquote type="cite">
    <blockquote type="cite">
      <pre wrap="">5. Functions like co_create_instance and other
initialization functions
expect an address of a pointer as the second argument. This means that
when used with interface_ptr, a temporary bare pointer must be used to
be given like so:

       // Create a source filter specified by filename
       interface_ptr&lt;IBaseFilter&gt; pSource; // The interface_ptr&lt;&gt;
object
       {
          IBaseFilter* ppSource= NULL; // temporary bare pointer



      </pre>
    </blockquote>
  </blockquote>
  <pre wrap=""><!---->if(FAILED(pGraph-&gt;AddSourceFilter(a2w(c_str_ptr(filename)),0,&amp;ppSource)))
  </pre>
  <blockquote type="cite">
    <blockquote type="cite">
      <pre wrap="">          {
            //...
   return 0;
          }
          pSource.set(ppSource, false); // setting the smart pointer.
       }
      </pre>
    </blockquote>
    <pre wrap="">Agree that this is not pretty.

    </pre>
    <blockquote type="cite">
      <pre wrap="">It would be useful to have a method that exposes the
internal member so
it can be used directly in such functions.
I know it might be dangerous (although there is an option to get the
referent anyway) but maybe it should be considered.
      </pre>
    </blockquote>
    <pre wrap="">I can't do this. This is one of the fatal mistakes made in ATL.

I think a better way is to make it a design parameter of COMSTL that
interface wrappers - i.e. stlsoft::ref_ptr&lt;X&gt; - are a fundamental unit of
currency of the library. Thus, we would then overload the
co_create_instance() function suite to work with stlsoft::ref_ptr&lt;..., I&gt;
wrappers as well as raw pointers (I), as in:

  {
    const CLSID CLSID_pantheios_COM_LoggerManager  = { 0x4E7D5C47, 0x8F96,
0x45DE, { 0x90, 0x5D, 0xAA, 0x3E, 0x9E, 0x59, 0x2D, 0xE3 } };

    stlsoft::ref_ptr&lt;IDispatch&gt; logmgr;

if(SUCCEEDED(comstl::co_create_instance(CLSID_pantheios_COM_LoggerManager,
logmgr)))
    {
    }
  }

  {
    stlsoft::ref_ptr&lt;IDispatch&gt; logmgr;


    </pre>
  </blockquote>
  <pre wrap=""><!---->if(SUCCEEDED(comstl::co_create_instance(L"{4E7D5C47-8F96-45DE-905D-AA3E9E592
  </pre>
  <blockquote type="cite">
    <pre wrap="">DE3}", logmgr)))
    {
    }
  }

  {
    stlsoft::ref_ptr&lt;IDispatch&gt; logmgr;

    </pre>
  </blockquote>
  <pre wrap=""><!---->if(SUCCEEDED(comstl::co_create_instance(L"pantheios.COM.LoggerManager",
  </pre>
  <blockquote type="cite">
    <pre wrap="">logmgr)))
    {
    }
  }

This is acceptable in terms of physical coupling because
stlsoft/smartptr/ref_ptr.hpp does not include any other headers (except
stlsoft/stlsoft.h, of course), so the impact on compilation times and
other -ve physical effects will be negligble.
    </pre>
  </blockquote>
  <pre wrap=""><!---->
Just implemented this one, and it works a treat! Be out in 1.9.1 beta 31.
(Oh when will I *ever* release 1.9.1 proper!? &lt;g&gt;)

If you can, I'd appreciate feedback whenever you find a place within the
libraries where an interface wrapper should be the means of currency.

Cheers

Matthew


  </pre>
</blockquote>
</body>
</html>
Dec 05 2006