www.digitalmars.com         C & C++   DMDScript  

c++.stlsoft - scoped_handle but for functions?

reply "ClŠudio Albuquerque" <0318222801 netcabo.pt> writes:
Hi Mathew,



I've been browsing the STLSoft documentation looking for something like 
scoped_handle but that applies the same principle but to two functions. 
Unfortunately did not find it, and instead of rushing into the 
implementation, a chosen a wiser path and decided that asking you would 
hurt. So STLSoft already has something like applying the RAII idea but to 
functions?



Thanks

ClŠudio Albuquerque
Feb 07 2007
parent reply "Matthew Wilson" <matthew hat.stlsoft.dot.org> writes:
Not sure what you mean. Can you give me an illustration of what you mean?

Matthew


"ClŠudio Albuquerque" <0318222801 netcabo.pt> wrote in message
news:eqc6nd$2815$1 digitaldaemon.com...
 Hi Mathew,



 I've been browsing the STLSoft documentation looking for something like
 scoped_handle but that applies the same principle but to two functions.
 Unfortunately did not find it, and instead of rushing into the
 implementation, a chosen a wiser path and decided that asking you would
 hurt. So STLSoft already has something like applying the RAII idea but to
 functions?



 Thanks

 ClŠudio Albuquerque

Feb 07 2007
parent reply "ClŠudio Albuquerque" <0318222801 netcabo.pt> writes:
Sure,

void MyFunc()
{
 ...
    scoped_functions<InitializeFunc,FinalizeFunc> OpInitializeFinalize;
...
}

When I declare the scoped_functions object, it will call the 
InitializeFunc() function, when the object goes out of scope it will call 
the FinalizeFun().

Hope this explanation helps.

Regards
ClŠudio Albuquerque


"Matthew Wilson" <matthew hat.stlsoft.dot.org> wrote in message 
news:eqcc8u$2fni$1 digitaldaemon.com...
 Not sure what you mean. Can you give me an illustration of what you mean?

 Matthew


 "ClŠudio Albuquerque" <0318222801 netcabo.pt> wrote in message
 news:eqc6nd$2815$1 digitaldaemon.com...
 Hi Mathew,



 I've been browsing the STLSoft documentation looking for something like
 scoped_handle but that applies the same principle but to two functions.
 Unfortunately did not find it, and instead of rushing into the
 implementation, a chosen a wiser path and decided that asking you would
 hurt. So STLSoft already has something like applying the RAII idea but to
 functions?



 Thanks

 ClŠudio Albuquerque


Feb 07 2007
parent reply "Matthew Wilson" <matthew hat.stlsoft.dot.org> writes:
I see.

No, scoped_handle does not support that syntax. However, it does support
that functionality, as in:

void MyFunc()
{
    ...
    InitializeFunc();
    scoped_functions<void> OpInitializeFinalize(FinalizeFunc);
    ...
}

:-)

Cheers

Matthew


"ClŠudio Albuquerque" <0318222801 netcabo.pt> wrote in message
news:eqd624$in5$1 digitaldaemon.com...
 Sure,

 void MyFunc()
 {
  ...
     scoped_functions<InitializeFunc,FinalizeFunc> OpInitializeFinalize;
 ...
 }

 When I declare the scoped_functions object, it will call the
 InitializeFunc() function, when the object goes out of scope it will call
 the FinalizeFun().

 Hope this explanation helps.

 Regards
 ClŠudio Albuquerque


 "Matthew Wilson" <matthew hat.stlsoft.dot.org> wrote in message
 news:eqcc8u$2fni$1 digitaldaemon.com...
 Not sure what you mean. Can you give me an illustration of what you


 Matthew


 "ClŠudio Albuquerque" <0318222801 netcabo.pt> wrote in message
 news:eqc6nd$2815$1 digitaldaemon.com...
 Hi Mathew,



 I've been browsing the STLSoft documentation looking for something like
 scoped_handle but that applies the same principle but to two functions.
 Unfortunately did not find it, and instead of rushing into the
 implementation, a chosen a wiser path and decided that asking you would
 hurt. So STLSoft already has something like applying the RAII idea but



 functions?



 Thanks

 ClŠudio Albuquerque



Feb 07 2007
parent reply "Matthew Wilson" <matthew hat.stlsoft.dot.org> writes:
I mean:

void MyFunc()
{
    ...
    InitializeFunc();
    scoped_handle<void> OpInitializeFinalize(FinalizeFunc);
    ...
}
Feb 07 2007
parent reply "ClŠudio Albuquerque" <0318222801 netcabo.pt> writes:
Humm I see

Ok, although I would like the "other" syntax better, I can see also some 
advantages to this.

Thanks Mathew!


"Matthew Wilson" <matthew hat.stlsoft.dot.org> wrote in message 
news:eqd9t0$nv0$1 digitaldaemon.com...
 I mean:

 void MyFunc()
 {
    ...
    InitializeFunc();
    scoped_handle<void> OpInitializeFinalize(FinalizeFunc);
    ...
 }

 

Feb 07 2007
parent reply "Matthew Wilson" <matthew hat.stlsoft.dot.org> writes:
"ClŠudio Albuquerque" <0318222801 netcabo.pt> wrote in message
news:eqdc5a$r9r$1 digitaldaemon.com...
 Humm I see

 Ok, although I would like the "other" syntax better, I can see also some
 advantages to this.

 Thanks Mathew!

You're welcome. ;-)
 "Matthew Wilson" <matthew hat.stlsoft.dot.org> wrote in message
 news:eqd9t0$nv0$1 digitaldaemon.com...
 I mean:

 void MyFunc()
 {
    ...
    InitializeFunc();
    scoped_handle<void> OpInitializeFinalize(FinalizeFunc);
    ...
 }


Feb 07 2007
next sibling parent "ClŠudio Albuquerque" <0318222801 netcabo.pt> writes:
Hi Mathew,

I'm trying to use the implementation that you recomended 
[scoped_handle<void> OpInitializeFinalize(FinalizeFunc);], but with member 
functions and I got a couple of errors. Could you help is it possible for 
you to help me on this? [I am using beta-44.]

Thanks In Advance
ClŠudio Albuquerque

stlsoft::scoped_handle<void> scopedEndOperation ( 
&baseClass::EndOperation );

Error 4 error C2664: 'stlsoft::scoped_handle<void>::scoped_handle(void 
(__cdecl *)(void))' : cannot convert parameter 1 from 'bool (__thiscall 
teste::* )(void)' to 'void (__cdecl *)(void)'

scoped_handle<void> scopedFinalize( baseClass::OpFinalize() );

Error 5 error C2664: 'stlsoft::scoped_handle<void>::scoped_handle(void 
(__cdecl *)(void))' : cannot convert parameter 1 from 'bool' to 'void 
(__cdecl *)(void)'



"Matthew Wilson" <matthew hat.stlsoft.dot.org> wrote in message 
news:eqdfu3$10ap$1 digitaldaemon.com...
 "ClŠudio Albuquerque" <0318222801 netcabo.pt> wrote in message
 news:eqdc5a$r9r$1 digitaldaemon.com...
 Humm I see

 Ok, although I would like the "other" syntax better, I can see also some
 advantages to this.

 Thanks Mathew!

You're welcome. ;-)
 "Matthew Wilson" <matthew hat.stlsoft.dot.org> wrote in message
 news:eqd9t0$nv0$1 digitaldaemon.com...
 I mean:

 void MyFunc()
 {
    ...
    InitializeFunc();
    scoped_handle<void> OpInitializeFinalize(FinalizeFunc);
    ...
 }



Mar 08 2007
prev sibling parent reply "ClŠudio Albuquerque" <0318222801 netcabo.pt> writes:
Hi Mathew,

I'm trying to use the implementation that you recomended
[scoped_handle<void> OpInitializeFinalize(FinalizeFunc);], but with member
functions and I got a couple of errors. Could you help is it possible for
you to help me on this? [I am using beta-44.]

Thanks In Advance
ClŠudio Albuquerque

stlsoft::scoped_handle<void> scopedEndOperation (
&baseClass::EndOperation );

Error 4 error C2664: 'stlsoft::scoped_handle<void>::scoped_handle(void
(__cdecl *)(void))' : cannot convert parameter 1 from 'bool (__thiscall
teste::* )(void)' to 'void (__cdecl *)(void)'

scoped_handle<void> scopedFinalize( baseClass::OpFinalize() );

Error 5 error C2664: 'stlsoft::scoped_handle<void>::scoped_handle(void
(__cdecl *)(void))' : cannot convert parameter 1 from 'bool' to 'void
(__cdecl *)(void)'



"Matthew Wilson" <matthew hat.stlsoft.dot.org> wrote in message
news:eqdfu3$10ap$1 digitaldaemon.com...
 "ClŠudio Albuquerque" <0318222801 netcabo.pt> wrote in message
 news:eqdc5a$r9r$1 digitaldaemon.com...
 Humm I see

 Ok, although I would like the "other" syntax better, I can see also some
 advantages to this.

 Thanks Mathew!

You're welcome. ;-)
 "Matthew Wilson" <matthew hat.stlsoft.dot.org> wrote in message
 news:eqd9t0$nv0$1 digitaldaemon.com...
 I mean:

 void MyFunc()
 {
    ...
    InitializeFunc();
    scoped_handle<void> OpInitializeFinalize(FinalizeFunc);
    ...
 }



Mar 09 2007
parent reply "Matthew Wilson" <matthew hat.stlsoft.dot.org> writes:
Ah, the problem there is that it's not designed to do that for member
functions.

I wouldn't want to alter scoped_handle to do that, but I would be open to
implementing an RAII class template - e.g. scoped_method - to do that.

Anyone got any ideas on this one, to give me a kick start?


"ClŠudio Albuquerque" <0318222801 netcabo.pt> wrote in message
news:esraio$12d3$2 digitalmars.com...
 Hi Mathew,

 I'm trying to use the implementation that you recomended
 [scoped_handle<void> OpInitializeFinalize(FinalizeFunc);], but with member
 functions and I got a couple of errors. Could you help is it possible for
 you to help me on this? [I am using beta-44.]

 Thanks In Advance
 ClŠudio Albuquerque

 stlsoft::scoped_handle<void> scopedEndOperation (
 &baseClass::EndOperation );

 Error 4 error C2664: 'stlsoft::scoped_handle<void>::scoped_handle(void
 (__cdecl *)(void))' : cannot convert parameter 1 from 'bool (__thiscall
 teste::* )(void)' to 'void (__cdecl *)(void)'

 scoped_handle<void> scopedFinalize( baseClass::OpFinalize() );

 Error 5 error C2664: 'stlsoft::scoped_handle<void>::scoped_handle(void
 (__cdecl *)(void))' : cannot convert parameter 1 from 'bool' to 'void
 (__cdecl *)(void)'



 "Matthew Wilson" <matthew hat.stlsoft.dot.org> wrote in message
 news:eqdfu3$10ap$1 digitaldaemon.com...
 "ClŠudio Albuquerque" <0318222801 netcabo.pt> wrote in message
 news:eqdc5a$r9r$1 digitaldaemon.com...
 Humm I see

 Ok, although I would like the "other" syntax better, I can see also



 advantages to this.

 Thanks Mathew!

You're welcome. ;-)
 "Matthew Wilson" <matthew hat.stlsoft.dot.org> wrote in message
 news:eqd9t0$nv0$1 digitaldaemon.com...
 I mean:

 void MyFunc()
 {
    ...
    InitializeFunc();
    scoped_handle<void> OpInitializeFinalize(FinalizeFunc);
    ...
 }




Mar 09 2007
parent "ClŠudio Albuquerque" <0318222801 netcabo.pt> writes:
Mathew,



Since I'm the only one interested here it goes:

My suggestion goes for a different name (for example: scoped_function :-) ). 
The name suggestion is just because then I would like something that acts 
like scope_handle<void> but also support's the this calling convention. 
Getting the this pointer into the RAII class as well as supporting a other 
type of functions is something I would consider you a better person to solve 
and I. :-)
The problem here is that there would be an overlap of functionality, 
although in the case of this new functionality appeared in stlsoft then I 
would only use scope_handle when there is some sort of recourse that I want 
to manage.

I only suggest a more general approach, because I would prefer then just one 
way of calling a function upon a closure of scope. I would think that the 
Thief constructor would also be helpful; at least I'm using it.



Kind Regards

ClŠudio Albuquerque








"Matthew Wilson" <matthew hat.stlsoft.dot.org> wrote in message 
news:essph4$sji$1 digitalmars.com...
 Ah, the problem there is that it's not designed to do that for member
 functions.

 I wouldn't want to alter scoped_handle to do that, but I would be open to
 implementing an RAII class template - e.g. scoped_method - to do that.

 Anyone got any ideas on this one, to give me a kick start?


 "ClŠudio Albuquerque" <0318222801 netcabo.pt> wrote in message
 news:esraio$12d3$2 digitalmars.com...
 Hi Mathew,

 I'm trying to use the implementation that you recomended
 [scoped_handle<void> OpInitializeFinalize(FinalizeFunc);], but with 
 member
 functions and I got a couple of errors. Could you help is it possible for
 you to help me on this? [I am using beta-44.]

 Thanks In Advance
 ClŠudio Albuquerque

 stlsoft::scoped_handle<void> scopedEndOperation (
 &baseClass::EndOperation );

 Error 4 error C2664: 'stlsoft::scoped_handle<void>::scoped_handle(void
 (__cdecl *)(void))' : cannot convert parameter 1 from 'bool (__thiscall
 teste::* )(void)' to 'void (__cdecl *)(void)'

 scoped_handle<void> scopedFinalize( baseClass::OpFinalize() );

 Error 5 error C2664: 'stlsoft::scoped_handle<void>::scoped_handle(void
 (__cdecl *)(void))' : cannot convert parameter 1 from 'bool' to 'void
 (__cdecl *)(void)'



 "Matthew Wilson" <matthew hat.stlsoft.dot.org> wrote in message
 news:eqdfu3$10ap$1 digitaldaemon.com...
 "ClŠudio Albuquerque" <0318222801 netcabo.pt> wrote in message
 news:eqdc5a$r9r$1 digitaldaemon.com...
 Humm I see

 Ok, although I would like the "other" syntax better, I can see also



 advantages to this.

 Thanks Mathew!

You're welcome. ;-)
 "Matthew Wilson" <matthew hat.stlsoft.dot.org> wrote in message
 news:eqd9t0$nv0$1 digitaldaemon.com...
 I mean:

 void MyFunc()
 {
    ...
    InitializeFunc();
    scoped_handle<void> OpInitializeFinalize(FinalizeFunc);
    ...
 }





Mar 12 2007