Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
84ec78fe
Commit
84ec78fe
authored
Mar 21, 2016
by
Wenzel Jakob
Browse files
minor redesign/generalization of def_property mechanism
parent
76eb607d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
20 deletions
+29
-20
include/pybind11/pybind11.h
include/pybind11/pybind11.h
+29
-20
No files found.
include/pybind11/pybind11.h
View file @
84ec78fe
...
...
@@ -799,7 +799,6 @@ public:
template
<
typename
C
,
typename
D
,
typename
...
Extra
>
class_
&
def_readwrite
(
const
char
*
name
,
D
C
::*
pm
,
const
Extra
&
...
extra
)
{
cpp_function
fget
([
pm
](
const
C
&
c
)
->
const
D
&
{
return
c
.
*
pm
;
},
return_value_policy
::
reference_internal
,
is_method
(
*
this
),
extra
...),
fset
([
pm
](
C
&
c
,
const
D
&
value
)
{
c
.
*
pm
=
value
;
},
is_method
(
*
this
),
extra
...);
...
...
@@ -810,7 +809,6 @@ public:
template
<
typename
C
,
typename
D
,
typename
...
Extra
>
class_
&
def_readonly
(
const
char
*
name
,
const
D
C
::*
pm
,
const
Extra
&
...
extra
)
{
cpp_function
fget
([
pm
](
const
C
&
c
)
->
const
D
&
{
return
c
.
*
pm
;
},
return_value_policy
::
reference_internal
,
is_method
(
*
this
),
extra
...);
def_property_readonly
(
name
,
fget
);
return
*
this
;
...
...
@@ -818,8 +816,7 @@ public:
template
<
typename
D
,
typename
...
Extra
>
class_
&
def_readwrite_static
(
const
char
*
name
,
D
*
pm
,
const
Extra
&
...
extra
)
{
cpp_function
fget
([
pm
](
object
)
->
const
D
&
{
return
*
pm
;
},
return_value_policy
::
reference_internal
,
scope
(
*
this
),
extra
...),
cpp_function
fget
([
pm
](
object
)
->
const
D
&
{
return
*
pm
;
},
scope
(
*
this
),
extra
...),
fset
([
pm
](
object
,
const
D
&
value
)
{
*
pm
=
value
;
},
scope
(
*
this
),
extra
...);
def_property_static
(
name
,
fget
,
fset
);
return
*
this
;
...
...
@@ -827,37 +824,43 @@ public:
template
<
typename
D
,
typename
...
Extra
>
class_
&
def_readonly_static
(
const
char
*
name
,
const
D
*
pm
,
const
Extra
&
...
extra
)
{
cpp_function
fget
([
pm
](
object
)
->
const
D
&
{
return
*
pm
;
},
return_value_policy
::
reference_internal
,
scope
(
*
this
),
extra
...);
cpp_function
fget
([
pm
](
object
)
->
const
D
&
{
return
*
pm
;
},
scope
(
*
this
),
extra
...);
def_property_readonly_static
(
name
,
fget
);
return
*
this
;
}
class_
&
def_property_readonly
(
const
char
*
name
,
const
cpp_function
&
fget
,
const
char
*
doc
=
nullptr
)
{
def_property
(
name
,
fget
,
cpp_function
(),
doc
);
template
<
typename
...
Extra
>
class_
&
def_property_readonly
(
const
char
*
name
,
const
cpp_function
&
fget
,
const
Extra
&
...
extra
)
{
def_property
(
name
,
fget
,
cpp_function
(),
extra
...);
return
*
this
;
}
class_
&
def_property_readonly_static
(
const
char
*
name
,
const
cpp_function
&
fget
,
const
char
*
doc
=
nullptr
)
{
def_property_static
(
name
,
fget
,
cpp_function
(),
doc
);
template
<
typename
...
Extra
>
class_
&
def_property_readonly_static
(
const
char
*
name
,
const
cpp_function
&
fget
,
const
Extra
&
...
extra
)
{
def_property_static
(
name
,
fget
,
cpp_function
(),
extra
...);
return
*
this
;
}
class_
&
def_property
(
const
char
*
name
,
const
cpp_function
&
fget
,
const
cpp_function
&
fset
,
const
char
*
doc
=
nullptr
)
{
object
doc_obj
=
doc
?
pybind11
::
str
(
doc
)
:
(
object
)
fget
.
attr
(
"__doc__"
);
object
property
(
PyObject_CallFunctionObjArgs
((
PyObject
*
)
&
PyProperty_Type
,
fget
.
ptr
()
?
fget
.
ptr
()
:
Py_None
,
fset
.
ptr
()
?
fset
.
ptr
()
:
Py_None
,
Py_None
,
doc_obj
.
ptr
(),
nullptr
),
false
);
attr
(
name
)
=
property
;
return
*
this
;
template
<
typename
...
Extra
>
class_
&
def_property
(
const
char
*
name
,
const
cpp_function
&
fget
,
const
cpp_function
&
fset
,
const
Extra
&
...
extra
)
{
return
def_property_static
(
name
,
fget
,
fset
,
is_method
(
*
this
),
return_value_policy
::
reference_internal
,
extra
...);
}
class_
&
def_property_static
(
const
char
*
name
,
const
cpp_function
&
fget
,
const
cpp_function
&
fset
,
const
char
*
doc
=
nullptr
)
{
object
doc_obj
=
doc
?
pybind11
::
str
(
doc
)
:
(
object
)
fget
.
attr
(
"__doc__"
);
template
<
typename
...
Extra
>
class_
&
def_property_static
(
const
char
*
name
,
const
cpp_function
&
fget
,
const
cpp_function
&
fset
,
const
Extra
&
...
extra
)
{
auto
rec_fget
=
get_function_record
(
fget
),
rec_fset
=
get_function_record
(
fset
);
detail
::
process_attributes
<
Extra
...
>::
init
(
extra
...,
rec_fget
);
if
(
rec_fset
)
detail
::
process_attributes
<
Extra
...
>::
init
(
extra
...,
rec_fset
);
pybind11
::
str
doc_obj
=
pybind11
::
str
(
rec_fget
->
doc
?
rec_fget
->
doc
:
""
);
object
property
(
PyObject_CallFunctionObjArgs
((
PyObject
*
)
&
PyProperty_Type
,
fget
.
ptr
()
?
fget
.
ptr
()
:
Py_None
,
fset
.
ptr
()
?
fset
.
ptr
()
:
Py_None
,
Py_None
,
doc_obj
.
ptr
(),
nullptr
),
false
);
metaclass
().
attr
(
name
)
=
property
;
if
(
rec_fget
->
class_
)
attr
(
name
)
=
property
;
else
metaclass
().
attr
(
name
)
=
property
;
return
*
this
;
}
...
...
@@ -911,6 +914,12 @@ private:
}
generic_type
::
dealloc
((
detail
::
instance
<
void
>
*
)
inst
);
}
static
detail
::
function_record
*
get_function_record
(
handle
h
)
{
h
=
detail
::
get_function
(
h
);
return
h
?
(
detail
::
function_record
*
)
capsule
(
PyCFunction_GetSelf
(
h
.
ptr
()),
true
)
:
nullptr
;
}
};
/// Binds C++ enumerations and enumeration classes to Python
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment