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
c8f68b3d
Commit
c8f68b3d
authored
Mar 02, 2016
by
hulucc
Browse files
add wstring caster
parent
937d646b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
0 deletions
+23
-0
include/pybind11/cast.h
include/pybind11/cast.h
+23
-0
No files found.
include/pybind11/cast.h
View file @
c8f68b3d
...
...
@@ -348,6 +348,29 @@ public:
PYBIND11_TYPE_CASTER
(
std
::
string
,
_
(
PYBIND11_STRING_NAME
));
};
template
<
>
class
type_caster
<
std
::
wstring
>
{
public:
bool
load
(
handle
src
,
bool
)
{
object
temp
;
handle
load_src
=
src
;
if
(
!
PyUnicode_Check
(
load_src
.
ptr
()))
{
temp
=
object
(
PyUnicode_FromObject
(
load_src
.
ptr
()),
false
);
if
(
!
temp
)
{
PyErr_Clear
();
return
false
;
}
load_src
=
temp
;
}
wchar_t
*
buffer
=
PyUnicode_AS_UNICODE
(
load_src
.
ptr
());
size_t
length
=
PyUnicode_GET_SIZE
(
load_src
.
ptr
());
value
=
std
::
wstring
(
buffer
,
length
);
return
true
;
}
static
handle
cast
(
const
std
::
wstring
&
src
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
return
PyUnicode_FromWideChar
(
src
.
c_str
(),
src
.
length
());
}
PYBIND11_TYPE_CASTER
(
std
::
wstring
,
_
(
PYBIND11_STRING_NAME
));
};
template
<
>
class
type_caster
<
char
>
{
public:
bool
load
(
handle
src
,
bool
)
{
...
...
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