-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathOCP_specific.inc
More file actions
66 lines (48 loc) · 1.8 KB
/
Copy pathOCP_specific.inc
File metadata and controls
66 lines (48 loc) · 1.8 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
#pragma once
#include <Standard_Handle.hxx>
#include <type_traits>
#include <memory>
#include <fmt/format.h>
namespace py = pybind11;
PYBIND11_DECLARE_HOLDER_TYPE(T, opencascade::handle<T>, true);
using opencascade::handle;
template <typename CppException>
void register_occ_exception(py::handle scope,
const char *name){
py::register_exception<CppException>(scope, name);
};
template <typename T, typename Ptr>
inline void register_default_constructor(py::module m, const char* name){
if constexpr (std::is_constructible<T>::value){
static_cast<py::class_<T ,Ptr>>(m.attr(name))
.def(py::init([]() { return new T; }));
}
};
template <typename T>
inline void copy_if_assignable(T& t1, T& t2){
if constexpr (std::is_assignable<T, T>::value){
t1 = t2;
}
else
{
throw py::type_error("Cannot assign, function wrapper not working properly.");
}
};
template <typename T> inline opencascade::handle<T> cast_pyobject(const py::object &arg){
if(py::isinstance(arg, py::type::of<T>()))
return opencascade::handle(py::cast<T*>(arg));
else
throw py::value_error(fmt::format("Cannot convert the argument to the required type {}", typeid(T).name()));
};
template<typename T, template<typename> typename Deleter = std::default_delete>
struct shared_ptr : public std::shared_ptr<T>{
explicit shared_ptr(T* t = nullptr) : std::shared_ptr<T>(t, Deleter<T>()) {};
void reset(T* t = nullptr) { std::shared_ptr<T>::reset(t, Deleter<T>()); };
};
template<typename T> struct nodelete{
void operator()(T* p) const {};
};
template<typename T> using shared_ptr_nodelete = shared_ptr<T,nodelete>;
PYBIND11_DECLARE_HOLDER_TYPE(T, shared_ptr<T>);
PYBIND11_DECLARE_HOLDER_TYPE(T, shared_ptr_nodelete<T>);
#include "pystreambuf.h"