Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
8fe13b88
Commit
8fe13b88
authored
Sep 05, 2016
by
Dean Moldovan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply make_caster and intrinsic_t aliases everywhere
parent
56e86ed0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
29 deletions
+29
-29
include/pybind11/attr.h
+1
-1
include/pybind11/cast.h
+19
-19
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>> {
...
@@ -240,7 +240,7 @@ struct process_attribute<arg_t<T>> : process_attribute_default<arg_t<T>> {
r
->
args
.
emplace_back
(
"self"
,
nullptr
,
handle
());
r
->
args
.
emplace_back
(
"self"
,
nullptr
,
handle
());
/* Convert keyword value into a Python object */
/* Convert keyword value into a Python object */
object
o
=
object
(
detail
::
type_caster
<
typename
detail
::
intrinsic_type
<
T
>::
type
>::
cast
(
auto
o
=
object
(
detail
::
make_caster
<
T
>::
cast
(
*
a
.
value
,
return_value_policy
::
automatic
,
handle
()),
false
);
*
a
.
value
,
return_value_policy
::
automatic
,
handle
()),
false
);
if
(
!
o
)
{
if
(
!
o
)
{
...
...
include/pybind11/cast.h
View file @
8fe13b88
...
@@ -252,8 +252,8 @@ protected:
...
@@ -252,8 +252,8 @@ protected:
/* Determine suitable casting operator */
/* Determine suitable casting operator */
template
<
typename
T
>
template
<
typename
T
>
using
cast_op_type
=
typename
std
::
conditional
<
std
::
is_pointer
<
typename
std
::
remove_reference
<
T
>::
type
>::
value
,
using
cast_op_type
=
typename
std
::
conditional
<
std
::
is_pointer
<
typename
std
::
remove_reference
<
T
>::
type
>::
value
,
typename
std
::
add_pointer
<
typename
intrinsic_type
<
T
>::
type
>::
type
,
typename
std
::
add_pointer
<
intrinsic_t
<
T
>
>::
type
,
typename
std
::
add_lvalue_reference
<
typename
intrinsic_type
<
T
>::
type
>::
type
>::
type
;
typename
std
::
add_lvalue_reference
<
intrinsic_t
<
T
>
>::
type
>::
type
;
/// Generic type caster for objects stored on the heap
/// Generic type caster for objects stored on the heap
template
<
typename
type
>
class
type_caster_base
:
public
type_caster_generic
{
template
<
typename
type
>
class
type_caster_base
:
public
type_caster_generic
{
...
@@ -612,8 +612,8 @@ public:
...
@@ -612,8 +612,8 @@ public:
}
}
static
handle
cast
(
const
type
&
src
,
return_value_policy
policy
,
handle
parent
)
{
static
handle
cast
(
const
type
&
src
,
return_value_policy
policy
,
handle
parent
)
{
object
o1
=
object
(
type_caster
<
typename
intrinsic_type
<
T1
>::
type
>::
cast
(
src
.
first
,
policy
,
parent
),
false
);
object
o1
=
object
(
make_caster
<
T1
>::
cast
(
src
.
first
,
policy
,
parent
),
false
);
object
o2
=
object
(
type_caster
<
typename
intrinsic_type
<
T2
>::
type
>::
cast
(
src
.
second
,
policy
,
parent
),
false
);
object
o2
=
object
(
make_caster
<
T2
>::
cast
(
src
.
second
,
policy
,
parent
),
false
);
if
(
!
o1
||
!
o2
)
if
(
!
o1
||
!
o2
)
return
handle
();
return
handle
();
tuple
result
(
2
);
tuple
result
(
2
);
...
@@ -624,24 +624,24 @@ public:
...
@@ -624,24 +624,24 @@ public:
static
PYBIND11_DESCR
name
()
{
static
PYBIND11_DESCR
name
()
{
return
type_descr
(
return
type_descr
(
_
(
"Tuple["
)
+
type_caster
<
typename
intrinsic_type
<
T1
>::
type
>::
name
()
+
_
(
"Tuple["
)
+
make_caster
<
T1
>::
name
()
+
_
(
", "
)
+
make_caster
<
T2
>::
name
()
+
_
(
"]"
)
_
(
", "
)
+
type_caster
<
typename
intrinsic_type
<
T2
>::
type
>::
name
()
+
_
(
"]"
)
);
);
}
}
template
<
typename
T
>
using
cast_op_type
=
type
;
template
<
typename
T
>
using
cast_op_type
=
type
;
operator
type
()
{
operator
type
()
{
return
type
(
first
.
operator
typename
type_caster
<
typename
intrinsic_type
<
T1
>::
type
>::
template
cast_op_type
<
T1
>
(),
return
type
(
first
.
operator
typename
make_caster
<
T1
>::
template
cast_op_type
<
T1
>
(),
second
.
operator
typename
type_caster
<
typename
intrinsic_type
<
T2
>::
type
>::
template
cast_op_type
<
T2
>
());
second
.
operator
typename
make_caster
<
T2
>::
template
cast_op_type
<
T2
>
());
}
}
protected
:
protected
:
type_caster
<
typename
intrinsic_type
<
T1
>::
type
>
first
;
make_caster
<
T1
>
first
;
type_caster
<
typename
intrinsic_type
<
T2
>::
type
>
second
;
make_caster
<
T2
>
second
;
};
};
template
<
typename
...
Tuple
>
class
type_caster
<
std
::
tuple
<
Tuple
...
>>
{
template
<
typename
...
Tuple
>
class
type_caster
<
std
::
tuple
<
Tuple
...
>>
{
typedef
std
::
tuple
<
Tuple
...
>
type
;
typedef
std
::
tuple
<
Tuple
...
>
type
;
typedef
std
::
tuple
<
typename
intrinsic_type
<
Tuple
>::
type
...
>
itype
;
typedef
std
::
tuple
<
intrinsic_t
<
Tuple
>
...
>
itype
;
typedef
std
::
tuple
<
args
>
args_type
;
typedef
std
::
tuple
<
args
>
args_type
;
typedef
std
::
tuple
<
args
,
kwargs
>
args_kwargs_type
;
typedef
std
::
tuple
<
args
,
kwargs
>
args_kwargs_type
;
public
:
public
:
...
@@ -681,7 +681,7 @@ public:
...
@@ -681,7 +681,7 @@ public:
}
}
static
PYBIND11_DESCR
element_names
()
{
static
PYBIND11_DESCR
element_names
()
{
return
detail
::
concat
(
type_caster
<
typename
intrinsic_type
<
Tuple
>::
typ
e
>::
name
()...);
return
detail
::
concat
(
make_caster
<
Tupl
e
>::
name
()...);
}
}
static
PYBIND11_DESCR
name
()
{
static
PYBIND11_DESCR
name
()
{
...
@@ -706,12 +706,12 @@ public:
...
@@ -706,12 +706,12 @@ public:
protected
:
protected
:
template
<
typename
ReturnValue
,
typename
Func
,
size_t
...
Index
>
ReturnValue
call
(
Func
&&
f
,
index_sequence
<
Index
...
>
)
{
template
<
typename
ReturnValue
,
typename
Func
,
size_t
...
Index
>
ReturnValue
call
(
Func
&&
f
,
index_sequence
<
Index
...
>
)
{
return
f
(
std
::
get
<
Index
>
(
value
)
return
f
(
std
::
get
<
Index
>
(
value
)
.
operator
typename
type_caster
<
typename
intrinsic_type
<
Tuple
>::
typ
e
>::
template
cast_op_type
<
Tuple
>
()...);
.
operator
typename
make_caster
<
Tupl
e
>::
template
cast_op_type
<
Tuple
>
()...);
}
}
template
<
size_t
...
Index
>
type
cast
(
index_sequence
<
Index
...
>
)
{
template
<
size_t
...
Index
>
type
cast
(
index_sequence
<
Index
...
>
)
{
return
type
(
std
::
get
<
Index
>
(
value
)
return
type
(
std
::
get
<
Index
>
(
value
)
.
operator
typename
type_caster
<
typename
intrinsic_type
<
Tuple
>::
typ
e
>::
template
cast_op_type
<
Tuple
>
()...);
.
operator
typename
make_caster
<
Tupl
e
>::
template
cast_op_type
<
Tuple
>
()...);
}
}
template
<
size_t
...
Indices
>
bool
load
(
handle
src
,
bool
convert
,
index_sequence
<
Indices
...
>
)
{
template
<
size_t
...
Indices
>
bool
load
(
handle
src
,
bool
convert
,
index_sequence
<
Indices
...
>
)
{
...
@@ -728,7 +728,7 @@ protected:
...
@@ -728,7 +728,7 @@ protected:
/* Implementation: Convert a C++ tuple into a Python tuple */
/* 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
...
>
)
{
template
<
size_t
...
Indices
>
static
handle
cast
(
const
type
&
src
,
return_value_policy
policy
,
handle
parent
,
index_sequence
<
Indices
...
>
)
{
std
::
array
<
object
,
size
>
entries
{{
std
::
array
<
object
,
size
>
entries
{{
object
(
type_caster
<
typename
intrinsic_type
<
Tuple
>::
typ
e
>::
cast
(
std
::
get
<
Indices
>
(
src
),
policy
,
parent
),
false
)...
object
(
make_caster
<
Tupl
e
>::
cast
(
std
::
get
<
Indices
>
(
src
),
policy
,
parent
),
false
)...
}};
}};
for
(
const
auto
&
entry
:
entries
)
for
(
const
auto
&
entry
:
entries
)
if
(
!
entry
)
if
(
!
entry
)
...
@@ -741,7 +741,7 @@ protected:
...
@@ -741,7 +741,7 @@ protected:
}
}
protected
:
protected
:
std
::
tuple
<
type_caster
<
typename
intrinsic_type
<
Tuple
>::
typ
e
>
...
>
value
;
std
::
tuple
<
make_caster
<
Tupl
e
>
...
>
value
;
};
};
/// Type caster for holder types like std::shared_ptr, etc.
/// 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
...
@@ -848,7 +848,7 @@ template <typename T> using move_never = std::integral_constant<bool, !move_alwa
NAMESPACE_END
(
detail
)
NAMESPACE_END
(
detail
)
template
<
typename
T
>
T
cast
(
const
handle
&
handle
)
{
template
<
typename
T
>
T
cast
(
const
handle
&
handle
)
{
typedef
detail
::
type_caster
<
typename
detail
::
intrinsic_type
<
T
>::
type
>
type_caster
;
using
type_caster
=
detail
::
make_caster
<
T
>
;
type_caster
conv
;
type_caster
conv
;
if
(
!
conv
.
load
(
handle
,
true
))
{
if
(
!
conv
.
load
(
handle
,
true
))
{
#if defined(NDEBUG)
#if defined(NDEBUG)
...
@@ -868,7 +868,7 @@ template <typename T> object cast(const T &value,
...
@@ -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
;
policy
=
std
::
is_pointer
<
T
>::
value
?
return_value_policy
::
take_ownership
:
return_value_policy
::
copy
;
else
if
(
policy
==
return_value_policy
::
automatic_reference
)
else
if
(
policy
==
return_value_policy
::
automatic_reference
)
policy
=
std
::
is_pointer
<
T
>::
value
?
return_value_policy
::
reference
:
return_value_policy
::
copy
;
policy
=
std
::
is_pointer
<
T
>::
value
?
return_value_policy
::
reference
:
return_value_policy
::
copy
;
return
object
(
detail
::
type_caster
<
typename
detail
::
intrinsic_type
<
T
>::
type
>::
cast
(
value
,
policy
,
parent
),
false
);
return
object
(
detail
::
make_caster
<
T
>::
cast
(
value
,
policy
,
parent
),
false
);
}
}
template
<
typename
T
>
T
handle
::
cast
()
const
{
return
pybind11
::
cast
<
T
>
(
*
this
);
}
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,
...
@@ -929,7 +929,7 @@ template <return_value_policy policy = return_value_policy::automatic_reference,
typename
...
Args
>
tuple
make_tuple
(
Args
&&
...
args_
)
{
typename
...
Args
>
tuple
make_tuple
(
Args
&&
...
args_
)
{
const
size_t
size
=
sizeof
...(
Args
);
const
size_t
size
=
sizeof
...(
Args
);
std
::
array
<
object
,
size
>
args
{
std
::
array
<
object
,
size
>
args
{
{
object
(
detail
::
type_caster
<
typename
detail
::
intrinsic_type
<
Args
>::
type
>::
cast
(
{
object
(
detail
::
make_caster
<
Args
>::
cast
(
std
::
forward
<
Args
>
(
args_
),
policy
,
nullptr
),
false
)...
}
std
::
forward
<
Args
>
(
args_
),
policy
,
nullptr
),
false
)...
}
};
};
for
(
auto
&
arg_value
:
args
)
{
for
(
auto
&
arg_value
:
args
)
{
...
...
include/pybind11/stl.h
View file @
8fe13b88
...
@@ -26,8 +26,8 @@ NAMESPACE_BEGIN(pybind11)
...
@@ -26,8 +26,8 @@ NAMESPACE_BEGIN(pybind11)
NAMESPACE_BEGIN
(
detail
)
NAMESPACE_BEGIN
(
detail
)
template
<
typename
Type
,
typename
Key
>
struct
set_caster
{
template
<
typename
Type
,
typename
Key
>
struct
set_caster
{
typedef
Type
t
ype
;
using
type
=
T
ype
;
typedef
type_caster
<
typename
intrinsic_type
<
Key
>::
type
>
key_conv
;
using
key_conv
=
make_caster
<
Key
>
;
bool
load
(
handle
src
,
bool
convert
)
{
bool
load
(
handle
src
,
bool
convert
)
{
pybind11
::
set
s
(
src
,
true
);
pybind11
::
set
s
(
src
,
true
);
...
@@ -57,9 +57,9 @@ template <typename Type, typename Key> struct set_caster {
...
@@ -57,9 +57,9 @@ template <typename Type, typename Key> struct set_caster {
};
};
template
<
typename
Type
,
typename
Key
,
typename
Value
>
struct
map_caster
{
template
<
typename
Type
,
typename
Key
,
typename
Value
>
struct
map_caster
{
typedef
Type
t
ype
;
using
type
=
T
ype
;
typedef
type_caster
<
typename
intrinsic_type
<
Key
>::
type
>
key_conv
;
using
key_conv
=
make_caster
<
Key
>
;
typedef
type_caster
<
typename
intrinsic_type
<
Value
>::
type
>
value_conv
;
using
value_conv
=
make_caster
<
Value
>
;
bool
load
(
handle
src
,
bool
convert
)
{
bool
load
(
handle
src
,
bool
convert
)
{
dict
d
(
src
,
true
);
dict
d
(
src
,
true
);
...
@@ -93,8 +93,8 @@ template <typename Type, typename Key, typename Value> struct map_caster {
...
@@ -93,8 +93,8 @@ template <typename Type, typename Key, typename Value> struct map_caster {
};
};
template
<
typename
Type
,
typename
Value
>
struct
list_caster
{
template
<
typename
Type
,
typename
Value
>
struct
list_caster
{
typedef
Type
t
ype
;
using
type
=
T
ype
;
typedef
type_caster
<
typename
intrinsic_type
<
Value
>::
type
>
value_conv
;
using
value_conv
=
make_caster
<
Value
>
;
bool
load
(
handle
src
,
bool
convert
)
{
bool
load
(
handle
src
,
bool
convert
)
{
list
l
(
src
,
true
);
list
l
(
src
,
true
);
...
@@ -138,8 +138,8 @@ template <typename Type, typename Alloc> struct type_caster<std::list<Type, Allo
...
@@ -138,8 +138,8 @@ template <typename Type, typename Alloc> struct type_caster<std::list<Type, Allo
:
list_caster
<
std
::
list
<
Type
,
Alloc
>
,
Type
>
{
};
:
list_caster
<
std
::
list
<
Type
,
Alloc
>
,
Type
>
{
};
template
<
typename
Type
,
size_t
Size
>
struct
type_caster
<
std
::
array
<
Type
,
Size
>>
{
template
<
typename
Type
,
size_t
Size
>
struct
type_caster
<
std
::
array
<
Type
,
Size
>>
{
typedef
std
::
array
<
Type
,
Size
>
array_type
;
using
array_type
=
std
::
array
<
Type
,
Size
>
;
typedef
type_caster
<
typename
intrinsic_type
<
Type
>::
type
>
value_conv
;
using
value_conv
=
make_caster
<
Type
>
;
bool
load
(
handle
src
,
bool
convert
)
{
bool
load
(
handle
src
,
bool
convert
)
{
list
l
(
src
,
true
);
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