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
fb74df50
Commit
fb74df50
authored
Oct 20, 2016
by
Ivan Smirnov
Browse files
Implement format/numpy descriptors for enums
parent
35995856
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
+17
-0
include/pybind11/numpy.h
include/pybind11/numpy.h
+17
-0
No files found.
include/pybind11/numpy.h
View file @
fb74df50
...
@@ -552,6 +552,14 @@ template <size_t N> struct format_descriptor<std::array<char, N>> {
...
@@ -552,6 +552,14 @@ template <size_t N> struct format_descriptor<std::array<char, N>> {
static
std
::
string
format
()
{
return
std
::
to_string
(
N
)
+
"s"
;
}
static
std
::
string
format
()
{
return
std
::
to_string
(
N
)
+
"s"
;
}
};
};
template
<
typename
T
>
struct
format_descriptor
<
T
,
detail
::
enable_if_t
<
std
::
is_enum
<
T
>::
value
>>
{
static
std
::
string
format
()
{
return
format_descriptor
<
typename
std
::
remove_cv
<
typename
std
::
underlying_type
<
T
>::
type
>::
type
>::
format
();
}
};
NAMESPACE_BEGIN
(
detail
)
NAMESPACE_BEGIN
(
detail
)
template
<
typename
T
>
struct
is_std_array
:
std
::
false_type
{
};
template
<
typename
T
>
struct
is_std_array
:
std
::
false_type
{
};
template
<
typename
T
,
size_t
N
>
struct
is_std_array
<
std
::
array
<
T
,
N
>>
:
std
::
true_type
{
};
template
<
typename
T
,
size_t
N
>
struct
is_std_array
<
std
::
array
<
T
,
N
>>
:
std
::
true_type
{
};
...
@@ -563,6 +571,7 @@ struct is_pod_struct {
...
@@ -563,6 +571,7 @@ struct is_pod_struct {
!
std
::
is_array
<
T
>::
value
&&
!
std
::
is_array
<
T
>::
value
&&
!
is_std_array
<
T
>::
value
&&
!
is_std_array
<
T
>::
value
&&
!
std
::
is_integral
<
T
>::
value
&&
!
std
::
is_integral
<
T
>::
value
&&
!
std
::
is_enum
<
T
>::
value
&&
!
std
::
is_same
<
typename
std
::
remove_cv
<
T
>::
type
,
float
>::
value
&&
!
std
::
is_same
<
typename
std
::
remove_cv
<
T
>::
type
,
float
>::
value
&&
!
std
::
is_same
<
typename
std
::
remove_cv
<
T
>::
type
,
double
>::
value
&&
!
std
::
is_same
<
typename
std
::
remove_cv
<
T
>::
type
,
double
>::
value
&&
!
std
::
is_same
<
typename
std
::
remove_cv
<
T
>::
type
,
bool
>::
value
&&
!
std
::
is_same
<
typename
std
::
remove_cv
<
T
>::
type
,
bool
>::
value
&&
...
@@ -612,6 +621,14 @@ template <size_t N> struct npy_format_descriptor<char[N]> { DECL_CHAR_FMT };
...
@@ -612,6 +621,14 @@ template <size_t N> struct npy_format_descriptor<char[N]> { DECL_CHAR_FMT };
template
<
size_t
N
>
struct
npy_format_descriptor
<
std
::
array
<
char
,
N
>>
{
DECL_CHAR_FMT
};
template
<
size_t
N
>
struct
npy_format_descriptor
<
std
::
array
<
char
,
N
>>
{
DECL_CHAR_FMT
};
#undef DECL_CHAR_FMT
#undef DECL_CHAR_FMT
template
<
typename
T
>
struct
npy_format_descriptor
<
T
,
enable_if_t
<
std
::
is_enum
<
T
>::
value
>>
{
private:
using
base_descr
=
npy_format_descriptor
<
typename
std
::
underlying_type
<
T
>::
type
>
;
public:
static
PYBIND11_DESCR
name
()
{
return
base_descr
::
name
();
}
static
pybind11
::
dtype
dtype
()
{
return
base_descr
::
dtype
();
}
};
struct
field_descriptor
{
struct
field_descriptor
{
const
char
*
name
;
const
char
*
name
;
size_t
offset
;
size_t
offset
;
...
...
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