|
From: Simon I. <Sim...@st...> - 2008-02-28 13:06:40
|
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:lui...@gm...] Sent: 28 February 2008 12:50 To: Simon Ibbotson Cc: qua...@li... 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 |