-
Notifications
You must be signed in to change notification settings - Fork 18
/
xylib.i
48 lines (40 loc) · 1.33 KB
/
xylib.i
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
%module xylib
%{
#define BUILDING_XYLIB
#define SWIG_FILE_WITH_INIT
#include "xylib/xylib.h"
%}
%include "std_string.i"
%include "std_except.i"
/* possible improvements:
* - better __str__/__repr__
* - better exception handling
*/
%catches(std::runtime_error) load_file(std::string const& path,
std::string const& format_name="",
std::string const& options="");
%catches(std::runtime_error) load_string(std::string const& buffer,
std::string const& format_name,
std::string const& options="");
#if defined(SWIGPYTHON)
// istream is not wrapped automatically
%ignore load_stream;
%ignore guess_filetype;
%ignore check_format;
%#if PY_VERSION_HEX >= 0x03000000
// buffer in load_string() must be mapped to bytes not string
%typemap(typecheck) std::string const& buffer %{
$1 = PyBytes_Check($input) ? 1 : 0;
%}
%typemap(in) std::string const& buffer (std::string temp) {
char *cstr;
Py_ssize_t len;
if (PyBytes_AsStringAndSize($input, &cstr, &len) < 0) SWIG_fail;
temp.assign(cstr, len);
$1 = &temp;
}
// delete default freearg typemap that checks res$argnum
%typemap(freearg) std::string const& buffer "";
%#endif // python3
#endif // SWIGPYTHON
%include "xylib/xylib.h"