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
8fe13b88
Commit
8fe13b88
authored
Sep 05, 2016
by
Dean Moldovan
Browse files
Apply make_caster and intrinsic_t aliases everywhere
parent
56e86ed0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
29 deletions
+29
-29
include/pybind11/attr.h
include/pybind11/attr.h
+1
-1
include/pybind11/cast.h
include/pybind11/cast.h
+19
-19
include/pybind11/stl.h
include/pybind11/stl.h
+9
-9
No files found.
include/pybind11/attr.h
View file @
8fe13b88
...
...
@@ -240,7 +240,7 @@ struct process_attribute<arg_t<T>> : process_attribute_default<arg_t<T>> {
r
->
args
.
emplace_back
(
"self"
,
nullptr
,
handle
());
/* Convert keyword value into a Python object */
object
o
=
object
(
detail
::
typ
e_caster
<
typename
detail
::
intrinsic_type
<
T
>::
type
>::
cast
(
auto
o
=
object
(
detail
::
mak
e_caster
<
T
>::
cast
(
*
a
.
value
,
return_value_policy
::
automatic
,
handle
()),
false
);
if
(
!
o
)
{
...
...
include/pybind11/cast.h
View file @
8fe13b88
...
...
@@ -252,8 +252,8 @@ protected:
/* Determine suitable casting operator */
template
<
typename
T
>
using
cast_op_type
=
typename
std
::
conditional
<
std
::
is_pointer
<
typename
std
::
remove_reference
<
T
>::
type
>::
value
,
typename
std
::
add_pointer
<
typename
intrinsic_t
ype
<
T
>::
type
>::
type
,
typename
std
::
add_lvalue_reference
<
typename
intrinsic_t
ype
<
T
>::
type
>::
type
>::
type
;
typename
std
::
add_pointer
<
intrinsic_t
<
T
>
>::
type
,
typename
std
::
add_lvalue_reference
<
intrinsic_t
<
T
>
>::
type
>::
type
;
/// Generic type caster for objects stored on the heap
template
<
typename
type
>
class
type_caster_base
:
public
type_caster_generic
{
...
...
@@ -612,8 +612,8 @@ public:
}
static
handle
cast
(
const
type
&
src
,
return_value_policy
policy
,
handle
parent
)
{
object
o1
=
object
(
typ
e_caster
<
typename
intrinsic_type
<
T1
>::
type
>::
cast
(
src
.
first
,
policy
,
parent
),
false
);
object
o2
=
object
(
typ
e_caster
<
typename
intrinsic_type
<
T2
>::
type
>::
cast
(
src
.
second
,
policy
,
parent
),
false
);
object
o1
=
object
(
mak
e_caster
<
T1
>::
cast
(
src
.
first
,
policy
,
parent
),
false
);
object
o2
=
object
(
mak
e_caster
<
T2
>::
cast
(
src
.
second
,
policy
,
parent
),
false
);
if
(
!
o1
||
!
o2
)
return
handle
();
tuple
result
(
2
);
...
...
@@ -624,24 +624,24 @@ public:
static
PYBIND11_DESCR
name
()
{
return
type_descr
(
_
(
"Tuple["
)
+
typ
e_caster
<
typename
intrinsic_type
<
T1
>::
type
>::
name
()
+
_
(
", "
)
+
type_caster
<
typename
intrinsic_type
<
T2
>::
type
>::
name
()
+
_
(
"]"
)
);
_
(
"Tuple["
)
+
mak
e_caster
<
T1
>::
name
()
+
_
(
", "
)
+
make_caster
<
T2
>::
name
()
+
_
(
"]"
)
);
}
template
<
typename
T
>
using
cast_op_type
=
type
;
operator
type
()
{
return
type
(
first
.
operator
typename
typ
e_caster
<
typename
intrinsic_type
<
T1
>::
type
>::
template
cast_op_type
<
T1
>(),
second
.
operator
typename
typ
e_caster
<
typename
intrinsic_type
<
T2
>::
type
>::
template
cast_op_type
<
T2
>());
return
type
(
first
.
operator
typename
mak
e_caster
<
T1
>::
template
cast_op_type
<
T1
>(),
second
.
operator
typename
mak
e_caster
<
T2
>::
template
cast_op_type
<
T2
>());
}
protected:
typ
e_caster
<
typename
intrinsic_type
<
T1
>::
type
>
first
;
typ
e_caster
<
typename
intrinsic_type
<
T2
>::
type
>
second
;
mak
e_caster
<
T1
>
first
;
mak
e_caster
<
T2
>
second
;
};
template
<
typename
...
Tuple
>
class
type_caster
<
std
::
tuple
<
Tuple
...
>>
{
typedef
std
::
tuple
<
Tuple
...
>
type
;
typedef
std
::
tuple
<
typename
intrinsic_t
ype
<
Tuple
>
::
type
...
>
itype
;
typedef
std
::
tuple
<
intrinsic_t
<
Tuple
>
...
>
itype
;
typedef
std
::
tuple
<
args
>
args_type
;
typedef
std
::
tuple
<
args
,
kwargs
>
args_kwargs_type
;
public:
...
...
@@ -681,7 +681,7 @@ public:
}
static
PYBIND11_DESCR
element_names
()
{
return
detail
::
concat
(
typ
e_caster
<
typename
intrinsic_type
<
Tuple
>::
typ
e
>::
name
()...);
return
detail
::
concat
(
mak
e_caster
<
Tupl
e
>::
name
()...);
}
static
PYBIND11_DESCR
name
()
{
...
...
@@ -706,12 +706,12 @@ public:
protected:
template
<
typename
ReturnValue
,
typename
Func
,
size_t
...
Index
>
ReturnValue
call
(
Func
&&
f
,
index_sequence
<
Index
...
>
)
{
return
f
(
std
::
get
<
Index
>
(
value
)
.
operator
typename
typ
e_caster
<
typename
intrinsic_type
<
Tuple
>::
typ
e
>::
template
cast_op_type
<
Tuple
>()...);
.
operator
typename
mak
e_caster
<
Tupl
e
>::
template
cast_op_type
<
Tuple
>()...);
}
template
<
size_t
...
Index
>
type
cast
(
index_sequence
<
Index
...
>
)
{
return
type
(
std
::
get
<
Index
>
(
value
)
.
operator
typename
typ
e_caster
<
typename
intrinsic_type
<
Tuple
>::
typ
e
>::
template
cast_op_type
<
Tuple
>()...);
.
operator
typename
mak
e_caster
<
Tupl
e
>::
template
cast_op_type
<
Tuple
>()...);
}
template
<
size_t
...
Indices
>
bool
load
(
handle
src
,
bool
convert
,
index_sequence
<
Indices
...
>
)
{
...
...
@@ -728,7 +728,7 @@ protected:
/* Implementation: Convert a C++ tuple into a Python tuple */
template
<
size_t
...
Indices
>
static
handle
cast
(
const
type
&
src
,
return_value_policy
policy
,
handle
parent
,
index_sequence
<
Indices
...
>
)
{
std
::
array
<
object
,
size
>
entries
{{
object
(
typ
e_caster
<
typename
intrinsic_type
<
Tuple
>::
typ
e
>::
cast
(
std
::
get
<
Indices
>
(
src
),
policy
,
parent
),
false
)...
object
(
mak
e_caster
<
Tupl
e
>::
cast
(
std
::
get
<
Indices
>
(
src
),
policy
,
parent
),
false
)...
}};
for
(
const
auto
&
entry
:
entries
)
if
(
!
entry
)
...
...
@@ -741,7 +741,7 @@ protected:
}
protected:
std
::
tuple
<
typ
e_caster
<
typename
intrinsic_type
<
Tuple
>::
typ
e
>
...
>
value
;
std
::
tuple
<
mak
e_caster
<
Tupl
e
>
...
>
value
;
};
/// Type caster for holder types like std::shared_ptr, etc.
...
...
@@ -848,7 +848,7 @@ template <typename T> using move_never = std::integral_constant<bool, !move_alwa
NAMESPACE_END
(
detail
)
template
<
typename
T
>
T
cast
(
const
handle
&
handle
)
{
typedef
detail
::
type_caster
<
typename
detail
::
intrinsic_type
<
T
>::
type
>
typ
e_caster
;
using
type_caster
=
detail
::
mak
e_caster
<
T
>
;
type_caster
conv
;
if
(
!
conv
.
load
(
handle
,
true
))
{
#if defined(NDEBUG)
...
...
@@ -868,7 +868,7 @@ template <typename T> object cast(const T &value,
policy
=
std
::
is_pointer
<
T
>::
value
?
return_value_policy
::
take_ownership
:
return_value_policy
::
copy
;
else
if
(
policy
==
return_value_policy
::
automatic_reference
)
policy
=
std
::
is_pointer
<
T
>::
value
?
return_value_policy
::
reference
:
return_value_policy
::
copy
;
return
object
(
detail
::
typ
e_caster
<
typename
detail
::
intrinsic_type
<
T
>::
type
>::
cast
(
value
,
policy
,
parent
),
false
);
return
object
(
detail
::
mak
e_caster
<
T
>::
cast
(
value
,
policy
,
parent
),
false
);
}
template
<
typename
T
>
T
handle
::
cast
()
const
{
return
pybind11
::
cast
<
T
>
(
*
this
);
}
...
...
@@ -929,7 +929,7 @@ template <return_value_policy policy = return_value_policy::automatic_reference,
typename
...
Args
>
tuple
make_tuple
(
Args
&&
...
args_
)
{
const
size_t
size
=
sizeof
...(
Args
);
std
::
array
<
object
,
size
>
args
{
{
object
(
detail
::
typ
e_caster
<
typename
detail
::
intrinsic_type
<
Args
>::
type
>::
cast
(
{
object
(
detail
::
mak
e_caster
<
Args
>::
cast
(
std
::
forward
<
Args
>
(
args_
),
policy
,
nullptr
),
false
)...
}
};
for
(
auto
&
arg_value
:
args
)
{
...
...
include/pybind11/stl.h
View file @
8fe13b88
...
...
@@ -26,8 +26,8 @@ NAMESPACE_BEGIN(pybind11)
NAMESPACE_BEGIN
(
detail
)
template
<
typename
Type
,
typename
Key
>
struct
set_caster
{
typedef
Type
t
ype
;
typedef
type_caster
<
typename
intrinsic_type
<
Key
>::
type
>
key_conv
;
using
type
=
T
ype
;
using
key_conv
=
make_caster
<
Key
>
;
bool
load
(
handle
src
,
bool
convert
)
{
pybind11
::
set
s
(
src
,
true
);
...
...
@@ -57,9 +57,9 @@ template <typename Type, typename Key> struct set_caster {
};
template
<
typename
Type
,
typename
Key
,
typename
Value
>
struct
map_caster
{
typedef
Type
t
ype
;
typedef
type_caster
<
typename
intrinsic_type
<
Key
>::
type
>
key_conv
;
typedef
type_caster
<
typename
intrinsic_type
<
Value
>::
type
>
value_conv
;
using
type
=
T
ype
;
using
key_conv
=
make_caster
<
Key
>
;
using
value_conv
=
make_caster
<
Value
>
;
bool
load
(
handle
src
,
bool
convert
)
{
dict
d
(
src
,
true
);
...
...
@@ -93,8 +93,8 @@ template <typename Type, typename Key, typename Value> struct map_caster {
};
template
<
typename
Type
,
typename
Value
>
struct
list_caster
{
typedef
Type
t
ype
;
typedef
type_caster
<
typename
intrinsic_type
<
Value
>::
type
>
value_conv
;
using
type
=
T
ype
;
using
value_conv
=
make_caster
<
Value
>
;
bool
load
(
handle
src
,
bool
convert
)
{
list
l
(
src
,
true
);
...
...
@@ -138,8 +138,8 @@ template <typename Type, typename Alloc> struct type_caster<std::list<Type, Allo
:
list_caster
<
std
::
list
<
Type
,
Alloc
>
,
Type
>
{
};
template
<
typename
Type
,
size_t
Size
>
struct
type_caster
<
std
::
array
<
Type
,
Size
>>
{
type
def
std
::
array
<
Type
,
Size
>
array_type
;
typedef
type_caster
<
typename
intrinsic_type
<
Type
>::
type
>
value_conv
;
using
array_
type
=
std
::
array
<
Type
,
Size
>
;
using
value_conv
=
make_caster
<
Type
>
;
bool
load
(
handle
src
,
bool
convert
)
{
list
l
(
src
,
true
);
...
...
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