-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.py
More file actions
46 lines (32 loc) · 1020 Bytes
/
Copy pathutils.py
File metadata and controls
46 lines (32 loc) · 1020 Bytes
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
from ogdf_python.loader import *
__all__ = ["is_nullptr", "typed_nullptr"]
_capture_stdout = """
std::ostringstream gCapturedStdout;
std::streambuf* gOldStdoutBuffer = nullptr;
static void BeginCaptureStdout() {
gOldStdoutBuffer = std::cout.rdbuf();
std::cout.rdbuf(gCapturedStdout.rdbuf());
}
static std::string EndCaptureStdout() {
std::cout.rdbuf(gOldStdoutBuffer);
gOldStdoutBuffer = nullptr;
std::string capturedStdout = std::move(gCapturedStdout).str();
gCapturedStdout.str("");
gCapturedStdout.clear();
return capturedStdout;
}"""
cppyy.cppdef("""
#include <sstream>
#include <streambuf>
#include <iostream>
namespace ogdf_pythonization {
%s
%s
}
""" % (_capture_stdout, _capture_stdout.replace("out", "err")))
def is_nullptr(o):
return cppyy.ll.addressof(o) == 0
def typed_nullptr(klass):
if isinstance(klass, type(ogdf.node)): # cppyy.TypedefPointerToClass
return klass() # returns typed nullptr
return cppyy.bind_object(cppyy.nullptr, klass)