summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2017-02-22 16:38:02 -0500
committerGuillaume Horel <guillaume.horel@gmail.com>2017-02-22 16:38:02 -0500
commit8baef999da28d8a51734994219514e20fe92a2d2 (patch)
treec3a1be6900fbc1036a2a887d43f10e4279a0591a
parentc373a9512d9cecd9d94497f0637d763ce7cfe9e5 (diff)
downloadpyisda-cpp.tar.gz
switch to C++cpp
-rw-r--r--Makefile2
-rw-r--r--cpp_layer/curve.hpp42
-rw-r--r--setup.py9
3 files changed, 49 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index c0eb427..82696cb 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ build:
python setup.py build_ext --inplace
clean:
- find pyisda \( -name *.c -o -name \*.h -o -name \*.so \) -exec rm {} \;
+ find pyisda \( -name *.c -o -name *.h -o -name *.so -o -name *.cpp -o -name *.html \) -exec rm {} \;
rm -rf build
install:
diff --git a/cpp_layer/curve.hpp b/cpp_layer/curve.hpp
new file mode 100644
index 0000000..8e54216
--- /dev/null
+++ b/cpp_layer/curve.hpp
@@ -0,0 +1,42 @@
+#include <vector>
+typedef long TDate;
+
+class CurveObject {
+public:
+ CurveObject(TDate baseDate, std::vector<TDate> dates, std::vector<double> rates,
+ double basis, long dayCountConv) {
+ _ptr = JpmcdsMakeTCurve(baseDate, dates.data(), rates.data(), dates.size(),
+ basis, dayCountConv);
+ }
+ CurveObject(TCurve* ptr) {
+ _ptr = ptr;
+ }
+ CurveObject(const CurveObject& other) {
+ _ptr = JpmcdsCopyCurve(other._ptr);
+ }
+ CurveObject(CurveObject&& other) : _ptr(other._ptr) {
+ other._ptr = nullptr;
+ }
+ CurveObject& operator=(const CurveObject& other) {
+ if( this != &other) {
+ JpmcdsFreeTCurve(_ptr);
+ _ptr = JpmcdsCopyCurve(other._ptr);
+ }
+ return *this;
+ }
+ CurveObject& operator=(CurveObject&& other) {
+ if( this != &other) {
+ JpmcdsFreeTCurve(_ptr);
+ _ptr = other._ptr;
+ other._ptr = nullptr;
+ }
+ return *this;
+ }
+ ~CurveObject() {
+ if(_ptr != nullptr) {
+ JpmcdsFreeTCurve(_ptr);
+ }
+ }
+private:
+ TCurve* _ptr;
+};
diff --git a/setup.py b/setup.py
index dd76e0d..da9a315 100644
--- a/setup.py
+++ b/setup.py
@@ -4,13 +4,16 @@ from Cython.Build import cythonize
import numpy
all_extensions = Extension("*", ["pyisda/*.pyx"],
- include_dirs = ['c_layer', numpy.get_include()],
- libraries = ["cds"])
+ include_dirs = ['cpp_layer', 'c_layer', numpy.get_include()],
+ libraries = ["cds"],
+ language = 'c++')
c_extension = Extension("pyisda.flat_hazard",
include_dirs = ['c_layer', numpy.get_include()],
sources = ['pyisda/flat_hazard.pyx', 'c_layer/cdsbootstrap.c'],
- libraries = ['cds'])
+ libraries = ['cds'],
+ language = 'c++')
+
all_extensions = cythonize([c_extension, all_extensions], nthreads = 4,
compiler_directives={'embedsignature':True})