25#ifndef quantlib_handle_hpp
26#define quantlib_handle_hpp
45 Link(
const ext::shared_ptr<T>& h,
46 bool registerAsObserver);
47 Link(ext::shared_ptr<T>&& h,
48 bool registerAsObserver);
50 bool registerAsObserver);
56 ext::shared_ptr<T>
h_;
79 :
Handle(ext::shared_ptr<
T>()) {}
80 explicit Handle(
const ext::shared_ptr<T>& p,
81 bool registerAsObserver =
true)
82 :
link_(new
Link(p, registerAsObserver)) {}
83 explicit Handle(ext::shared_ptr<T>&& p,
84 bool registerAsObserver =
true)
94 operator ext::shared_ptr<Observable>()
const;
122 const ext::shared_ptr<T>& p,
123 bool registerAsObserver =
true);
125 ext::shared_ptr<T>&& p,
126 bool registerAsObserver =
true);
130#if defined(_MSC_VER) && (_MSC_VER < 1916)
133 [[deprecated(
"Use one of the constructors taking shared_ptr.")]]
137 bool registerAsObserver =
true);
139 bool registerAsObserver =
true);
141 bool registerAsObserver =
true);
149 linkTo(h, registerAsObserver);
154 linkTo(std::move(h), registerAsObserver);
159 bool registerAsObserver) {
160 if ((h != h_) || (isObserver_ != registerAsObserver)) {
161 if (h_ && isObserver_)
164 isObserver_ = registerAsObserver;
165 if (h_ && isObserver_)
175 return link_->currentLink();
181 return link_->currentLink();
187 return link_->currentLink();
192 return link_->empty();
203 bool registerAsObserver)
204 :
Handle<
T>(p,registerAsObserver) {}
208 bool registerAsObserver)
209 :
Handle<
T>(
std::move(p), registerAsObserver) {}
213 bool registerAsObserver)
214 :
Handle<
T>(p,registerAsObserver) {}
218 bool registerAsObserver) {
219 this->link_->linkTo(h, registerAsObserver);
224 bool registerAsObserver) {
225 this->link_->linkTo(std::move(h), registerAsObserver);
void linkTo(ext::shared_ptr< T >, bool registerAsObserver)
Link(const ext::shared_ptr< T > &h, 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
Handle(ext::shared_ptr< T > &&p, bool registerAsObserver=true)
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.
void linkTo(const ext::shared_ptr< T > &h, bool registerAsObserver=true)
void linkTo(ext::shared_ptr< T > &&h, bool registerAsObserver=true)
RelinkableHandle(ext::shared_ptr< T > &&p, bool registerAsObserver=true)
RelinkableHandle(T *p, bool registerAsObserver=true)
RelinkableHandle(const ext::shared_ptr< T > &p, bool registerAsObserver=true)
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
observer/observable pattern