Skip to content

Commit

Permalink
Export new LazyObject interface (#574)
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Jul 11, 2023
2 parents 4928c05 + 6a1f47a commit 62eb1b1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
6 changes: 2 additions & 4 deletions SWIG/instruments.i
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
%include types.i
%include marketelements.i
%include observer.i
%include lazyobject.i
%include stl.i

// pricing engine
Expand All @@ -45,15 +46,12 @@ using QuantLib::Instrument;
%}

%shared_ptr(Instrument)
class Instrument : public Observable {
class Instrument : public LazyObject {
public:
Real NPV() const;
Real errorEstimate() const;
bool isExpired() const;
void setPricingEngine(const ext::shared_ptr<PricingEngine>&);
void recalculate();
void freeze();
void unfreeze();
private:
Instrument();
};
Expand Down
53 changes: 53 additions & 0 deletions SWIG/lazyobject.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

/*
Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
Copyright (C) 2018 Matthias Lungwitz

This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/

QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<[email protected]>. The license is also available online at
<http://quantlib.org/license.shtml>.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/

#ifndef quantlib_lazy_object_i
#define quantlib_lazy_object_i

%include common.i
%include types.i
%include observer.i

%{
using QuantLib::LazyObject;
%}

%shared_ptr(LazyObject)
class LazyObject : public Observable {
private:
LazyObject();
public:
void recalculate();
void freeze();
void unfreeze();
%extend {
static void forwardFirstNotificationOnly() {
LazyObject::Defaults::instance().forwardFirstNotificationOnly();
}
static void alwaysForwardNotifications() {
LazyObject::Defaults::instance().alwaysForwardNotifications();
}
static bool forwardsAllNotifications() {
return LazyObject::Defaults::instance().forwardsAllNotifications();
}
}
};


#endif
1 change: 1 addition & 0 deletions SWIG/ql.i
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ QL_DEPRECATED_DISABLE_WARNING
%include integrals.i
%include interestrate.i
%include interpolation.i
%include lazyobject.i
%include linearalgebra.i
%include localvolatilities.i
%include lmm.i
Expand Down

0 comments on commit 62eb1b1

Please sign in to comment.