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
a88334f9
Commit
a88334f9
authored
Mar 02, 2016
by
hulucc
Browse files
add wchar_t caster
parent
c8f68b3d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
+33
-0
include/pybind11/cast.h
include/pybind11/cast.h
+33
-0
No files found.
include/pybind11/cast.h
View file @
a88334f9
...
...
@@ -404,6 +404,39 @@ protected:
std
::
string
value
;
};
template
<
>
class
type_caster
<
wchar_t
>
{
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
wchar_t
*
src
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
return
PyUnicode_FromWideChar
(
src
,
wcslen
(
src
));
}
static
handle
cast
(
wchar_t
src
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
wchar_t
wstr
[
2
]
=
{
src
,
L'\0'
};
return
PyUnicode_FromWideChar
(
wstr
,
1
);
}
operator
wchar_t
*
()
{
return
(
wchar_t
*
)
value
.
c_str
();
}
operator
wchar_t
()
{
if
(
value
.
length
()
>
0
)
return
value
[
0
];
else
return
L'\0'
;
}
static
PYBIND11_DESCR
name
()
{
return
type_descr
(
_
(
PYBIND11_STRING_NAME
));
}
protected:
std
::
wstring
value
;
};
template
<
typename
T1
,
typename
T2
>
class
type_caster
<
std
::
pair
<
T1
,
T2
>>
{
typedef
std
::
pair
<
T1
,
T2
>
type
;
public:
...
...
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