Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
15f6a003
Commit
15f6a003
authored
Jan 24, 2016
by
Wenzel Jakob
Browse files
enum comparison and conversion operations (closes #80)
parent
a40c27ee
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
2 deletions
+56
-2
example/example4.cpp
example/example4.cpp
+3
-2
example/example4.py
example/example4.py
+29
-0
example/example4.ref
example/example4.ref
+20
-0
include/pybind11/pybind11.h
include/pybind11/pybind11.h
+4
-0
No files found.
example/example4.cpp
View file @
15f6a003
...
@@ -21,8 +21,9 @@ public:
...
@@ -21,8 +21,9 @@ public:
ESecondMode
ESecondMode
};
};
static
void
test_function
(
EMode
mode
)
{
static
EMode
test_function
(
EMode
mode
)
{
std
::
cout
<<
"Example4::test_function(enum="
<<
mode
<<
")"
<<
std
::
endl
;
std
::
cout
<<
"Example4::test_function(enum="
<<
mode
<<
")"
<<
std
::
endl
;
return
mode
;
}
}
};
};
...
@@ -42,7 +43,7 @@ float test_function3(int i) {
...
@@ -42,7 +43,7 @@ float test_function3(int i) {
py
::
bytes
return_bytes
()
{
py
::
bytes
return_bytes
()
{
const
char
*
data
=
"
\x01\x00\x02\x00
"
;
const
char
*
data
=
"
\x01\x00\x02\x00
"
;
return
py
::
bytes
(
std
::
string
(
data
,
4
)
)
;
return
std
::
string
(
data
,
4
);
}
}
void
print_bytes
(
py
::
bytes
bytes
)
{
void
print_bytes
(
py
::
bytes
bytes
)
{
...
...
example/example4.py
View file @
15f6a003
...
@@ -20,10 +20,39 @@ print(test_function())
...
@@ -20,10 +20,39 @@ print(test_function())
print
(
test_function
(
7
))
print
(
test_function
(
7
))
print
(
test_function
(
EMyEnumeration
.
EFirstEntry
))
print
(
test_function
(
EMyEnumeration
.
EFirstEntry
))
print
(
test_function
(
EMyEnumeration
.
ESecondEntry
))
print
(
test_function
(
EMyEnumeration
.
ESecondEntry
))
print
(
"enum->integer = %i"
%
int
(
EMyEnumeration
.
ESecondEntry
))
print
(
"integer->enum = %s"
%
str
(
EMyEnumeration
(
2
)))
print
(
"A constant = "
+
str
(
some_constant
))
print
(
Example4
.
EMode
)
print
(
Example4
.
EMode
)
print
(
Example4
.
EMode
.
EFirstMode
)
print
(
Example4
.
EMode
.
EFirstMode
)
print
(
Example4
.
EFirstMode
)
print
(
Example4
.
EFirstMode
)
Example4
.
test_function
(
Example4
.
EFirstMode
)
Example4
.
test_function
(
Example4
.
EFirstMode
)
print
(
"Equality test 1: "
+
str
(
Example4
.
test_function
(
Example4
.
EFirstMode
)
==
Example4
.
test_function
(
Example4
.
EFirstMode
)))
print
(
"Inequality test 1: "
+
str
(
Example4
.
test_function
(
Example4
.
EFirstMode
)
!=
Example4
.
test_function
(
Example4
.
EFirstMode
)))
print
(
"Equality test 2: "
+
str
(
Example4
.
test_function
(
Example4
.
EFirstMode
)
==
Example4
.
test_function
(
Example4
.
ESecondMode
)))
print
(
"Inequality test 2: "
+
str
(
Example4
.
test_function
(
Example4
.
EFirstMode
)
!=
Example4
.
test_function
(
Example4
.
ESecondMode
)))
x
=
{
Example4
.
test_function
(
Example4
.
EFirstMode
):
1
,
Example4
.
test_function
(
Example4
.
ESecondMode
):
2
}
x
[
Example4
.
test_function
(
Example4
.
EFirstMode
)]
=
3
x
[
Example4
.
test_function
(
Example4
.
ESecondMode
)]
=
4
print
(
"Hashing test = "
+
str
(
x
))
print_bytes
(
return_bytes
())
print_bytes
(
return_bytes
())
example/example4.ref
View file @
15f6a003
...
@@ -10,10 +10,30 @@ test_function(enum=1)
...
@@ -10,10 +10,30 @@ test_function(enum=1)
None
None
test_function(enum=2)
test_function(enum=2)
None
None
enum->integer = 2
integer->enum = EMyEnumeration.ESecondEntry
A constant = 14
<class 'example.EMode'>
<class 'example.EMode'>
EMode.EFirstMode
EMode.EFirstMode
EMode.EFirstMode
EMode.EFirstMode
Example4::test_function(enum=1)
Example4::test_function(enum=1)
Example4::test_function(enum=1)
Example4::test_function(enum=1)
Equality test 1: True
Example4::test_function(enum=1)
Example4::test_function(enum=1)
Inequality test 1: False
Example4::test_function(enum=1)
Example4::test_function(enum=2)
Equality test 2: False
Example4::test_function(enum=1)
Example4::test_function(enum=2)
Inequality test 2: True
Example4::test_function(enum=1)
Example4::test_function(enum=2)
Example4::test_function(enum=1)
Example4::test_function(enum=2)
Hashing test = {EMode.EFirstMode: 3, EMode.ESecondMode: 4}
bytes[0]=1
bytes[0]=1
bytes[1]=0
bytes[1]=0
bytes[2]=2
bytes[2]=2
...
...
include/pybind11/pybind11.h
View file @
15f6a003
...
@@ -907,7 +907,11 @@ public:
...
@@ -907,7 +907,11 @@ public:
((
it
==
entries
->
end
())
?
std
::
string
(
"???"
)
((
it
==
entries
->
end
())
?
std
::
string
(
"???"
)
:
std
::
string
(
it
->
second
));
:
std
::
string
(
it
->
second
));
});
});
this
->
def
(
"__init__"
,
[](
Type
&
value
,
int
i
)
{
value
=
(
Type
)
i
;
});
this
->
def
(
"__int__"
,
[](
Type
value
)
{
return
(
int
)
value
;
});
this
->
def
(
"__int__"
,
[](
Type
value
)
{
return
(
int
)
value
;
});
this
->
def
(
"__eq__"
,
[](
const
Type
&
value
,
Type
value2
)
{
return
value
==
value2
;
});
this
->
def
(
"__ne__"
,
[](
const
Type
&
value
,
Type
value2
)
{
return
value
!=
value2
;
});
this
->
def
(
"__hash__"
,
[](
const
Type
&
value
)
{
return
(
int
)
value
;
});
m_entries
=
entries
;
m_entries
=
entries
;
}
}
...
...
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