-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcommon.i
More file actions
101 lines (86 loc) · 2.17 KB
/
common.i
File metadata and controls
101 lines (86 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef quantlib_common_i
#define quantlib_common_i
%include stl.i
%include exception.i
%include boost_shared_ptr.i
%define QL_TYPECHECK_BOOL 7210 %enddef
%{
// This is necessary to avoid compile failures on
// GCC 4
// see http://svn.boost.org/trac/boost/ticket/1793
#if defined(NDEBUG)
#define BOOST_DISABLE_ASSERTS 1
#endif
#include <boost/algorithm/string/case_conv.hpp>
%}
%typemap(in) boost::optional<bool> %{
if($input == Py_None)
$1 = boost::none;
else if ($input == Py_True)
$1 = true;
else
$1 = false;
%}
%typecheck (QL_TYPECHECK_BOOL) boost::optional<bool> {
if (PyBool_Check($input) || Py_None == $input)
$1 = 1;
else
$1 = 0;
}
%{
// generally useful classes
using QuantLib::Error;
using QuantLib::Handle;
using QuantLib::RelinkableHandle;
%}
namespace boost {
%extend shared_ptr {
T* operator->() {
return (*self).operator->();
}
bool __nonzero__() {
return !!(*self);
}
bool __bool__() {
return !!(*self);
}
}
}
template <class T>
class Handle {
public:
Handle(const boost::shared_ptr<T>& = boost::shared_ptr<T>());
boost::shared_ptr<T> operator->();
%extend {
bool __nonzero__() {
return !self->empty();
}
bool __bool__() {
return !self->empty();
}
}
};
template <class T>
class RelinkableHandle : public Handle<T> {
public:
RelinkableHandle(const boost::shared_ptr<T>& = boost::shared_ptr<T>());
void linkTo(const boost::shared_ptr<T>&);
%extend {
// could be defined in C++ class, added here in the meantime
void reset() {
self->linkTo(boost::shared_ptr<T>());
}
}
};
%define swigr_list_converter(ContainerRType,
ContainerCType, ElemCType)
%enddef
%define deprecate_feature(OldName, NewName)
%pythoncode %{
def OldName(*args, **kwargs):
from warnings import warn
warn('%s is deprecated; use %s' % (OldName.__name__, NewName.__name__))
return NewName(*args, **kwargs)
%}
%enddef
#endif //quantlib_common_i