Handle class conversion. Open discussion.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Handle class conversion. Open discussion.

Kakhkhor Abdijalilov
Dear all,
Current implementation of Handle class doesn't permit conversion from
Handle<Derived> to Handle<Base>. If we supply Handle<Base> with
converting constructor, an instance of Handle<Derived> could be
substituted where an instance of Handle<Base> is expected. For
example, an instance of Handle<SimpleQuote> could be passed  to term
structure constructors instead of Handle<Quote> instance. This
conversion makes sense, since SimpleQuote is a subtype of Quote.

Enabling conversion would allow user code use derived class features
without a need for dynamic casting. Safety of conversion can be
checked at runtime, similar to pointer down-casting.

I did some coding in this direction and so far everything looks OK.
Since it is a design decision and not a bug fix, I wanted to know what
other think before submitting my code.

Regards,
Kakhkhor Abdijalilov.

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Handle class conversion. Open discussion.

Simon Ibbotson-2
Hi Kakhkhor,

I created some dynamic_handle_cast code about 2 years ago. There was
some discussion at the time: see 28th Feb 2008

http://osdir.com/ml/finance.quantlib.devel/2008-02/

I submitted an implementation but had no response - and it hasn't made
its way into the library. I can provide it again if required.

Simon

-----Original Message-----
From: Kakhkhor Abdijalilov [mailto:[hidden email]]
Sent: 24 December 2010 23:39
To: [hidden email]
Subject: [Quantlib-dev] Handle class conversion. Open discussion.

Dear all,
Current implementation of Handle class doesn't permit conversion from
Handle<Derived> to Handle<Base>. If we supply Handle<Base> with
converting constructor, an instance of Handle<Derived> could be
substituted where an instance of Handle<Base> is expected. For
example, an instance of Handle<SimpleQuote> could be passed  to term
structure constructors instead of Handle<Quote> instance. This
conversion makes sense, since SimpleQuote is a subtype of Quote.

Enabling conversion would allow user code use derived class features
without a need for dynamic casting. Safety of conversion can be
checked at runtime, similar to pointer down-casting.

I did some coding in this direction and so far everything looks OK.
Since it is a design decision and not a bug fix, I wanted to know what
other think before submitting my code.

Regards,
Kakhkhor Abdijalilov.

------------------------------------------------------------------------
------
Learn how Oracle Real Application Clusters (RAC) One Node allows
customers
to consolidate database storage, standardize their database environment,
and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev



This communication and any attachments contains information which is confidential and may be subject to legal privilege. It is for intended recipients only. If you are not the intended recipient you must not copy, distribute, publish, rely on or otherwise use it without our consent. Some of our communications may contain confidential information which it could be a criminal offence for you to disclose or use without authority. If you have received this email in error please notify [hidden email] immediately and delete the email from your computer.

The FSA reserves the right to monitor all email communications for compliance with legal, regulatory and professional standards.
This email is not intended to nor should it be taken to create any legal relations or contractual relationships. This email has originated from

The Financial Services Authority (FSA)
25 The North Colonnade,
Canary Wharf,
London
E14 5HS
United Kingdom

Registered as a Limited Company in England and Wales No.1920623.
Registered Office as above

Switchboard: 020 7066 1000
Web Site: http://www.fsa.gov.uk
*****************************************************************


------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Handle class conversion. Open discussion.

Ferdinando M. Ametrano-3
I agree on the proposal and sorry Simon if your previous contribution
was missed.

Luigi?

ciao -- Nando

On Tue, Jan 4, 2011 at 11:36 AM, Simon Ibbotson
<[hidden email]> wrote:

> Hi Kakhkhor,
>
> I created some dynamic_handle_cast code about 2 years ago. There was
> some discussion at the time: see 28th Feb 2008
>
> http://osdir.com/ml/finance.quantlib.devel/2008-02/
>
> I submitted an implementation but had no response - and it hasn't made
> its way into the library. I can provide it again if required.
>
> Simon
>
> -----Original Message-----
> From: Kakhkhor Abdijalilov [mailto:[hidden email]]
> Sent: 24 December 2010 23:39
> To: [hidden email]
> Subject: [Quantlib-dev] Handle class conversion. Open discussion.
>
> Dear all,
> Current implementation of Handle class doesn't permit conversion from
> Handle<Derived> to Handle<Base>. If we supply Handle<Base> with
> converting constructor, an instance of Handle<Derived> could be
> substituted where an instance of Handle<Base> is expected. For
> example, an instance of Handle<SimpleQuote> could be passed  to term
> structure constructors instead of Handle<Quote> instance. This
> conversion makes sense, since SimpleQuote is a subtype of Quote.
>
> Enabling conversion would allow user code use derived class features
> without a need for dynamic casting. Safety of conversion can be
> checked at runtime, similar to pointer down-casting.
>
> I did some coding in this direction and so far everything looks OK.
> Since it is a design decision and not a bug fix, I wanted to know what
> other think before submitting my code.
>
> Regards,
> Kakhkhor Abdijalilov.
>
> ------------------------------------------------------------------------
> ------
> Learn how Oracle Real Application Clusters (RAC) One Node allows
> customers
> to consolidate database storage, standardize their database environment,
> and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> QuantLib-dev mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-dev
>
>
>
> This communication and any attachments contains information which is confidential and may be subject to legal privilege. It is for intended recipients only. If you are not the intended recipient you must not copy, distribute, publish, rely on or otherwise use it without our consent. Some of our communications may contain confidential information which it could be a criminal offence for you to disclose or use without authority. If you have received this email in error please notify [hidden email] immediately and delete the email from your computer.
>
> The FSA reserves the right to monitor all email communications for compliance with legal, regulatory and professional standards.
> This email is not intended to nor should it be taken to create any legal relations or contractual relationships. This email has originated from
>
> The Financial Services Authority (FSA)
> 25 The North Colonnade,
> Canary Wharf,
> London
> E14 5HS
> United Kingdom
>
> Registered as a Limited Company in England and Wales No.1920623.
> Registered Office as above
>
> Switchboard: 020 7066 1000
> Web Site: http://www.fsa.gov.uk
> *****************************************************************
>
>
> ------------------------------------------------------------------------------
> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> to consolidate database storage, standardize their database environment, and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> QuantLib-dev mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-dev
>

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Handle class conversion. Open discussion.

Luigi Ballabio
In reply to this post by Simon Ibbotson-2
On Tue, 2011-01-04 at 10:36 +0000, Simon Ibbotson wrote:
> I created some dynamic_handle_cast code about 2 years ago. There was
> some discussion at the time: see 28th Feb 2008
>
> http://osdir.com/ml/finance.quantlib.devel/2008-02/
>
> I submitted an implementation but had no response - and it hasn't made
> its way into the library. I can provide it again if required.

Hi Simon,
        sorry for the contribution being lost silently---I guess I lost track
of it.  I went back to it, and it seems to me it adds quite a bit of
complexity to the Handle class.  We can discuss it, though (for
instance, would it be acceptable for your use cases to have a separate
class for that?)

However, unless I misinterpreted Kakhkhor's post, his proposal was to
enable upcasting from Handle<Derived> to Handle<Base>, while yours
implemented downcasting from Handle<Base> to Handle<Derived>.  I think
upcasting was not implemented originally because all handles were
relinkable, and that made upcasting risky (as in:

class A {};
class B : public A {};
class C : public A {};

Handle<B> h1;
Handle<A> h2 = h1;
h2.linkTo(shared_ptr<C>(...));
// ... and now you're in trouble, because your
// original Handle<B> links to a C which is not a B.

for the same reason, C++ doesn't allow casting from Derived** to Base**)

But now that you can't link through a Handle, it might be safe (provided
that when you upcast a RelinkableHandle you get a simple Handle.)

Luigi


--

Don't say "yes" until I finish talking.
-- Darryl F. Zanuck



------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev