QuantLib
A free/open-source library for quantitative finance
Reference manual - version 1.20
Protected Attributes | List of all members
Handle< T > Class Template Reference

Shared handle to an observable. More...

#include <ql/handle.hpp>

+ Inheritance diagram for Handle< T >:

Public Member Functions

Constructors
Warning:
registerAsObserver is left as a backdoor in case the programmer cannot guarantee that the object pointed to will remain alive for the whole lifetime of the handle—namely, it should be set to false when the passed shared pointer does not own the pointee (this should only happen in a controlled environment, so that the programmer is aware of it). Failure to do so can very likely result in a program crash. If the programmer does want the handle to register as observer of such a shared pointer, it is his responsibility to ensure that the handle gets destroyed before the pointed object does.
 Handle (const ext::shared_ptr< T > &p=ext::shared_ptr< T >(), bool registerAsObserver=true)
 
const ext::shared_ptr< T > & currentLink () const
 dereferencing
 
const ext::shared_ptr< T > & operator-> () const
 
const ext::shared_ptr< T > & operator* () const
 
bool empty () const
 checks if the contained shared pointer points to anything
 
 operator ext::shared_ptr< Observable > () const
 allows registration as observable
 
template<class U >
bool operator== (const Handle< U > &other) const
 equality test
 
template<class U >
bool operator!= (const Handle< U > &other) const
 disequality test
 
template<class U >
bool operator< (const Handle< U > &other) const
 strict weak ordering
 

Protected Attributes

ext::shared_ptr< Link > link_
 

Detailed Description

template<class T>
class QuantLib::Handle< T >

Shared handle to an observable.

All copies of an instance of this class refer to the same observable by means of a relinkable smart pointer. When such pointer is relinked to another observable, the change will be propagated to all the copies.

Precondition
Class T must inherit from Observable
Examples
BasketLosses.cpp, BermudanSwaption.cpp, Bonds.cpp, CallableBonds.cpp, CDS.cpp, ConvertibleBonds.cpp, CVAIRS.cpp, DiscreteHedging.cpp, EquityOption.cpp, Gaussian1dModels.cpp, LatentModel.cpp, MulticurveBootstrapping.cpp, and Replication.cpp.