FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python/include/boost/python/lvalue_from_pytype.hpp at python313 · boostorg/python · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
boostorg
/
python
Public
Notifications
You must be signed in to change notification settings
Fork
223
Star
537
Code
Issues
173
Pull requests
34
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python
/
include
/
boost
/
python
/
lvalue_from_pytype.hpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
117 lines (106 loc) · 3.53 KB
Breadcrumbs
python
/
include
/
boost
/
python
/
lvalue_from_pytype.hpp
Copy path
File metadata and controls
117 lines (106 loc) · 3.53 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
Copyright David Abrahams 2002.
//
Distributed under the Boost Software License, Version 1.0. (See
//
accompanying file LICENSE_1_0.txt or copy at
//
http://www.boost.org/LICENSE_1_0.txt)
#
ifndef
LVALUE_FROM_PYTYPE_DWA2002130_HPP
#
define
LVALUE_FROM_PYTYPE_DWA2002130_HPP
#
include
<
boost/python/detail/prefix.hpp
>
#
ifndef
BOOST_PYTHON_NO_PY_SIGNATURES
#
include
<
boost/python/converter/pytype_function.hpp
>
#
endif
#
include
<
boost/python/type_id.hpp
>
#
include
<
boost/python/converter/registry.hpp
>
#
include
<
boost/python/detail/void_ptr.hpp
>
#
include
<
boost/python/detail/type_traits.hpp
>
namespace
boost
{
namespace
python
{
namespace
detail
{
//
Given a pointer-to-function of 1 parameter returning a reference
//
type, return the type_id of the function's return type.
template
<
class
T
,
class
U
>
inline
type_info
extractor_type_id
(T&(*)(U))
{
return
type_id<T>();
}
//
A function generator whose static execute() function is an lvalue
//
from_python converter using the given Extractor. U is expected to
//
be the actual type of the PyObject instance from which the result
//
is being extracted.
template
<
class
Extractor
,
class
U
>
struct
normalized_extractor
{
static
inline
void
*
execute
(PyObject* op)
{
typedef
typename
add_lvalue_reference<U>::type param;
return
&
Extractor::execute
(
boost::python::detail::void_ptr_to_reference
(
op, (
param
(*)())
0
)
);
}
};
//
Given an Extractor type and a pointer to its execute function,
//
return a new object whose static execute function does the same
//
job but is a conforming lvalue from_python conversion function.
//
//
usage: normalize<Extractor>(&Extractor::execute)
template
<
class
Extractor
,
class
T
,
class
U
>
inline
normalized_extractor<Extractor,U>
normalize
(T(*)(U), Extractor* =
0
)
{
return
normalized_extractor<Extractor, U>();
}
}
//
An Extractor which extracts the given member from a Python object
//
whose instances are stored as InstanceType.
template
<
class
InstanceType
,
class
MemberType
, MemberType (InstanceType::*member)>
struct
extract_member
{
static
MemberType&
execute
(InstanceType& c)
{
(
void
)
Py_TYPE
(&c);
//
static assertion
return
c.*member;
}
};
//
An Extractor which simply extracts the entire python object
//
instance of InstanceType.
template
<
class
InstanceType
>
struct
extract_identity
{
static
InstanceType&
execute
(InstanceType& c)
{
(
void
)
Py_TYPE
(&c);
//
static assertion
return
c;
}
};
//
Registers a from_python conversion which extracts lvalues using
//
Extractor's static execute function from Python objects whose type
//
object is python_type.
template
<
class
Extractor
, PyTypeObject
const
* python_type>
struct
lvalue_from_pytype
{
lvalue_from_pytype
()
{
converter::registry::insert
( &extract
,
detail::extractor_type_id
(&Extractor::execute)
#
ifndef
BOOST_PYTHON_NO_PY_SIGNATURES
, &get_pytype
#
endif
);
}
private:
static
void
*
extract
(PyObject* op)
{
return
PyObject_TypeCheck
(op,
const_cast
<PyTypeObject*>(python_type))
?
const_cast
<
void
*>(
static_cast
<
void
const
volatile
*>(
detail::normalize<Extractor>(&Extractor::execute).
execute
(op)))
:
0
;
}
#
ifndef
BOOST_PYTHON_NO_PY_SIGNATURES
static
PyTypeObject
const
*
get_pytype
() {
return
python_type; }
#
endif
};
}}
//
namespace boost::python
#
endif
//
LVALUE_FROM_PYTYPE_DWA2002130_HPP
Back
|
FazBrowse Home
|
New Git URL