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
805c5862
"tests/test_modules.cpp" did not exist on "a576e6a8ca5f22f9f9d5f149929637c3337ad086"
Commit
805c5862
authored
Jan 25, 2020
by
Yannick Jadoul
Committed by
Wenzel Jakob
Apr 26, 2020
Browse files
Adding method names to cpp_function constructor calls in enum_base
parent
a86ac538
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
16 deletions
+18
-16
include/pybind11/pybind11.h
include/pybind11/pybind11.h
+18
-16
No files found.
include/pybind11/pybind11.h
View file @
805c5862
...
@@ -1427,7 +1427,7 @@ struct enum_base {
...
@@ -1427,7 +1427,7 @@ struct enum_base {
return
pybind11
::
str
(
"{}.{}"
).
format
(
type_name
,
kv
.
first
);
return
pybind11
::
str
(
"{}.{}"
).
format
(
type_name
,
kv
.
first
);
}
}
return
pybind11
::
str
(
"{}.???"
).
format
(
type_name
);
return
pybind11
::
str
(
"{}.???"
).
format
(
type_name
);
},
is_method
(
m_base
)
},
name
(
"__repr__"
),
is_method
(
m_base
)
);
);
m_base
.
attr
(
"name"
)
=
property
(
cpp_function
(
m_base
.
attr
(
"name"
)
=
property
(
cpp_function
(
...
@@ -1438,7 +1438,7 @@ struct enum_base {
...
@@ -1438,7 +1438,7 @@ struct enum_base {
return
pybind11
::
str
(
kv
.
first
);
return
pybind11
::
str
(
kv
.
first
);
}
}
return
"???"
;
return
"???"
;
},
is_method
(
m_base
)
},
name
(
"name"
),
is_method
(
m_base
)
));
));
m_base
.
attr
(
"__doc__"
)
=
static_property
(
cpp_function
(
m_base
.
attr
(
"__doc__"
)
=
static_property
(
cpp_function
(
...
@@ -1456,7 +1456,7 @@ struct enum_base {
...
@@ -1456,7 +1456,7 @@ struct enum_base {
docstring
+=
" : "
+
(
std
::
string
)
pybind11
::
str
(
comment
);
docstring
+=
" : "
+
(
std
::
string
)
pybind11
::
str
(
comment
);
}
}
return
docstring
;
return
docstring
;
}
}
,
name
(
"__doc__"
)
),
none
(),
none
(),
""
);
),
none
(),
none
(),
""
);
m_base
.
attr
(
"__members__"
)
=
static_property
(
cpp_function
(
m_base
.
attr
(
"__members__"
)
=
static_property
(
cpp_function
(
...
@@ -1465,7 +1465,7 @@ struct enum_base {
...
@@ -1465,7 +1465,7 @@ struct enum_base {
for
(
const
auto
&
kv
:
entries
)
for
(
const
auto
&
kv
:
entries
)
m
[
kv
.
first
]
=
kv
.
second
[
int_
(
0
)];
m
[
kv
.
first
]
=
kv
.
second
[
int_
(
0
)];
return
m
;
return
m
;
}),
none
(),
none
(),
""
}
,
name
(
"__members__"
)
),
none
(),
none
(),
""
);
);
#define PYBIND11_ENUM_OP_STRICT(op, expr, strict_behavior) \
#define PYBIND11_ENUM_OP_STRICT(op, expr, strict_behavior) \
...
@@ -1475,7 +1475,7 @@ struct enum_base {
...
@@ -1475,7 +1475,7 @@ struct enum_base {
strict_behavior; \
strict_behavior; \
return expr; \
return expr; \
}, \
}, \
is_method(m_base))
name(op),
is_method(m_base))
#define PYBIND11_ENUM_OP_CONV(op, expr) \
#define PYBIND11_ENUM_OP_CONV(op, expr) \
m_base.attr(op) = cpp_function( \
m_base.attr(op) = cpp_function( \
...
@@ -1483,7 +1483,7 @@ struct enum_base {
...
@@ -1483,7 +1483,7 @@ struct enum_base {
int_ a(a_), b(b_); \
int_ a(a_), b(b_); \
return expr; \
return expr; \
}, \
}, \
is_method(m_base))
name(op),
is_method(m_base))
#define PYBIND11_ENUM_OP_CONV_LHS(op, expr) \
#define PYBIND11_ENUM_OP_CONV_LHS(op, expr) \
m_base.attr(op) = cpp_function( \
m_base.attr(op) = cpp_function( \
...
@@ -1491,7 +1491,7 @@ struct enum_base {
...
@@ -1491,7 +1491,7 @@ struct enum_base {
int_ a(a_); \
int_ a(a_); \
return expr; \
return expr; \
}, \
}, \
is_method(m_base))
name(op),
is_method(m_base))
if
(
is_convertible
)
{
if
(
is_convertible
)
{
PYBIND11_ENUM_OP_CONV_LHS
(
"__eq__"
,
!
b
.
is_none
()
&&
a
.
equal
(
b
));
PYBIND11_ENUM_OP_CONV_LHS
(
"__eq__"
,
!
b
.
is_none
()
&&
a
.
equal
(
b
));
...
@@ -1509,7 +1509,7 @@ struct enum_base {
...
@@ -1509,7 +1509,7 @@ struct enum_base {
PYBIND11_ENUM_OP_CONV
(
"__xor__"
,
a
^
b
);
PYBIND11_ENUM_OP_CONV
(
"__xor__"
,
a
^
b
);
PYBIND11_ENUM_OP_CONV
(
"__rxor__"
,
a
^
b
);
PYBIND11_ENUM_OP_CONV
(
"__rxor__"
,
a
^
b
);
m_base
.
attr
(
"__invert__"
)
=
cpp_function
(
m_base
.
attr
(
"__invert__"
)
=
cpp_function
(
[](
object
arg
)
{
return
~
(
int_
(
arg
));
},
is_method
(
m_base
));
[](
object
arg
)
{
return
~
(
int_
(
arg
));
},
name
(
"__invert__"
),
is_method
(
m_base
));
}
}
}
else
{
}
else
{
PYBIND11_ENUM_OP_STRICT
(
"__eq__"
,
int_
(
a
).
equal
(
int_
(
b
)),
return
false
);
PYBIND11_ENUM_OP_STRICT
(
"__eq__"
,
int_
(
a
).
equal
(
int_
(
b
)),
return
false
);
...
@@ -1529,11 +1529,11 @@ struct enum_base {
...
@@ -1529,11 +1529,11 @@ struct enum_base {
#undef PYBIND11_ENUM_OP_CONV
#undef PYBIND11_ENUM_OP_CONV
#undef PYBIND11_ENUM_OP_STRICT
#undef PYBIND11_ENUM_OP_STRICT
object
getstate
=
cpp_function
(
m_base
.
attr
(
"__
getstate
__"
)
=
cpp_function
(
[](
object
arg
)
{
return
int_
(
arg
);
},
is_method
(
m_base
));
[](
object
arg
)
{
return
int_
(
arg
);
},
name
(
"__getstate__"
),
is_method
(
m_base
));
m_base
.
attr
(
"__
getstate__"
)
=
getstate
;
m_base
.
attr
(
"__
hash__"
)
=
cpp_function
(
m_base
.
attr
(
"__hash__"
)
=
getstate
;
[](
object
arg
)
{
return
int_
(
arg
);
},
name
(
"__hash__"
),
is_method
(
m_base
))
;
}
}
PYBIND11_NOINLINE
void
value
(
char
const
*
name_
,
object
value
,
const
char
*
doc
=
nullptr
)
{
PYBIND11_NOINLINE
void
value
(
char
const
*
name_
,
object
value
,
const
char
*
doc
=
nullptr
)
{
...
@@ -1586,10 +1586,12 @@ public:
...
@@ -1586,10 +1586,12 @@ public:
def
(
"__index__"
,
[](
Type
value
)
{
return
(
Scalar
)
value
;
});
def
(
"__index__"
,
[](
Type
value
)
{
return
(
Scalar
)
value
;
});
#endif
#endif
cpp_function
setstate
(
attr
(
"__setstate__"
)
=
cpp_function
(
[](
Type
&
value
,
Scalar
arg
)
{
value
=
static_cast
<
Type
>
(
arg
);
},
[](
detail
::
value_and_holder
&
v_h
,
Scalar
arg
)
{
is_method
(
*
this
));
detail
::
initimpl
::
setstate
<
Base
>
(
v_h
,
static_cast
<
Type
>
(
arg
),
attr
(
"__setstate__"
)
=
setstate
;
Py_TYPE
(
v_h
.
inst
)
!=
v_h
.
type
->
type
);
},
detail
::
is_new_style_constructor
(),
pybind11
::
name
(
"__setstate__"
),
is_method
(
*
this
));
}
}
/// Export enumeration entries into the parent scope
/// Export enumeration entries into the parent scope
...
...
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