On Wednesday 26 June 2002 6:16 pm, Andre Poenitz wrote:
> On Wed, Jun 26, 2002 at 05:59:24PM +0100, Angus Leeming wrote:
> > > I have a cached 'BufferView *' already anyway.
> >
> > Which becomes unsafe as soon as we start creating and destroying multiple
> > buferviews?
>
> Probably.
>
> > Hence my thoughts on using a signal to invoke the update...
>
> And I still have not understood that signal stuff. Call me dumb...

In this case it's easy.

class A {
        void Func1(B const & b);
        void Func2(...);
        boost::signal0<void> Signal1
};

class B : boost::trackable {
        void someConnectingFunc()
};

The idea: A::Func2 is going to be called at some stage and what to invoke 
B::someConnectingFunc for the instance B const & b that was passed to 
A::Func1. Only A::Func2 doesn't remember what bv is unless A cache's it (your 
way). Only A::Func2 HAS NO WAY of knowing whether this cached B* points to 
anything anymore.

What to do?

Use a signal which (because B derives from boost::trackable) will just Do The 
Right Thing.

A::Func1(B const & bv)
{
        Signal1.connect(&B::someConnectingFunc, &bv);
}

A::Func2(...)
{
        if (...)
                Signal1();
}

I too have no idea about the internals of the boost signal stuff. I don't 
need to ;-)

Angus
        

Reply via email to