Login  Register

Re: Handle & type casting

Posted by Simon Ibbotson - Straumur on Feb 28, 2008; 1:06pm
URL: http://quantlib.414.s1.nabble.com/Handle-type-casting-tp11733p11735.html

If you have a handle to any Observable -  Handle<T1> but you need a
handle to a derived type Handle<T2>, I can find no way of currently
doing this without going through the process of
a) Getting the underlying boost::shared_ptr<T1>
b) Using boost::dynamic_pointer_cast to get a boost::shared_ptr<T2>
c) Creating a Handle<T2> using the new shared_ptr<T2>.

Unfortunately, this means that if the original Handle<T1> points to a
new object, the Handle<T2> does not point to this updated object.

Implementing this part of the functionality is easy... using the
Observer/Observable pattern to create a helper class. However, cleaning
up after the original Handle::Link object has been deleted requires that
the helper class is notified upon deletion of the Handle::Link object
(and can delete itself).

If this has already been discussed and a solution reached, let me know.

Hope this makes sense,

Simon
 

-----Original Message-----
From: Luigi Ballabio [mailto:[hidden email]]
Sent: 28 February 2008 12:50
To: Simon Ibbotson
Cc: [hidden email]
Subject: Re: [Quantlib-dev] Handle & type casting

On Thu, 2008-02-28 at 12:43 +0000, Simon Ibbotson wrote:
> Would anyone mind if I changed the Handle::Link class to allow dynamic
> typecasting of Handles / RelinkableHandles? It would mean adding a
> shared pointer for a helper class that would be notified when the
> Handle::Link class was deleted (only if a typecast had occurred).

Simon,
        I'm afraid I'm not getting what you mean. Do you have an
example?

Luigi


--

Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it.
-- Brian W. Kernighan



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev