25#ifndef quantlib_handle_hpp
26#define quantlib_handle_hpp
28#include <ql/patterns/observable.hpp>
45 explicit Link(
const ext::shared_ptr<T>& h,
46 bool registerAsObserver);
47 void linkTo(
const ext::shared_ptr<T>&,
48 bool registerAsObserver);
54 ext::shared_ptr<T>
h_;
77 :
Handle(ext::shared_ptr<T>()) {}
78 explicit Handle(
const ext::shared_ptr<T>& p,
79 bool registerAsObserver =
true)
80 :
link_(new
Link(p,registerAsObserver)) {}
89 operator ext::shared_ptr<Observable>()
const;
115 const ext::shared_ptr<T>& p = ext::shared_ptr<T>(),
116 bool registerAsObserver =
true);
119 bool registerAsObserver =
true);
121 bool registerAsObserver =
true);
129 linkTo(h,registerAsObserver);
134 bool registerAsObserver) {
135 if ((h != h_) || (isObserver_ != registerAsObserver)) {
136 if (h_ && isObserver_)
139 isObserver_ = registerAsObserver;
140 if (h_ && isObserver_)
149 QL_REQUIRE(!
empty(),
"empty Handle cannot be dereferenced");
150 return link_->currentLink();
155 QL_REQUIRE(!
empty(),
"empty Handle cannot be dereferenced");
156 return link_->currentLink();
161 QL_REQUIRE(!
empty(),
"empty Handle cannot be dereferenced");
162 return link_->currentLink();
167 return link_->empty();
178 bool registerAsObserver)
179 :
Handle<T>(p,registerAsObserver) {}
183 bool registerAsObserver)
184 :
Handle<T>(p,registerAsObserver) {}
188 bool registerAsObserver) {
189 this->link_->linkTo(h,registerAsObserver);
Link(const ext::shared_ptr< T > &h, bool registerAsObserver)
void linkTo(const ext::shared_ptr< T > &, bool registerAsObserver)
const ext::shared_ptr< T > & currentLink() const
Shared handle to an observable.
const ext::shared_ptr< T > & operator*() const
Handle(const ext::shared_ptr< T > &p, bool registerAsObserver=true)
bool operator<(const Handle< U > &other) const
strict weak ordering
const ext::shared_ptr< T > & operator->() const
bool operator==(const Handle< U > &other) const
equality test
bool operator!=(const Handle< U > &other) const
disequality test
bool empty() const
checks if the contained shared pointer points to anything
const ext::shared_ptr< T > & currentLink() const
dereferencing
ext::shared_ptr< Link > link_
Object that notifies its changes to a set of observers.
Object that gets notified when a given observable changes.
Relinkable handle to an observable.
RelinkableHandle(T *p, bool registerAsObserver=true)
RelinkableHandle(const ext::shared_ptr< T > &p=ext::shared_ptr< T >(), bool registerAsObserver=true)
void linkTo(const ext::shared_ptr< T > &, bool registerAsObserver=true)