Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
7ca27558
Commit
7ca27558
authored
Apr 22, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new type wrapper for iterable objects
parent
54b6fdd4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
3 deletions
+17
-3
include/pybind11/pytypes.h
+17
-3
No files found.
include/pybind11/pytypes.h
View file @
7ca27558
...
@@ -212,6 +212,16 @@ private:
...
@@ -212,6 +212,16 @@ private:
ssize_t
pos
=
0
;
ssize_t
pos
=
0
;
};
};
inline
bool
iterable_check
(
PyObject
*
obj
)
{
PyObject
*
iter
=
PyObject_GetIter
(
obj
);
if
(
iter
)
{
Py_DECREF
(
iter
);
return
true
;
}
else
{
PyErr_Clear
();
return
false
;
}
}
NAMESPACE_END
(
detail
)
NAMESPACE_END
(
detail
)
...
@@ -233,7 +243,6 @@ NAMESPACE_END(detail)
...
@@ -233,7 +243,6 @@ NAMESPACE_END(detail)
class
iterator
:
public
object
{
class
iterator
:
public
object
{
public
:
public
:
PYBIND11_OBJECT_DEFAULT
(
iterator
,
object
,
PyIter_Check
)
PYBIND11_OBJECT_DEFAULT
(
iterator
,
object
,
PyIter_Check
)
iterator
(
handle
obj
,
bool
borrowed
=
false
)
:
object
(
obj
,
borrowed
)
{
}
iterator
&
operator
++
()
{
iterator
&
operator
++
()
{
if
(
ptr
())
if
(
ptr
())
value
=
object
(
PyIter_Next
(
m_ptr
),
false
);
value
=
object
(
PyIter_Next
(
m_ptr
),
false
);
...
@@ -250,12 +259,17 @@ private:
...
@@ -250,12 +259,17 @@ private:
mutable
object
value
;
mutable
object
value
;
};
};
class
iterable
:
public
object
{
public
:
PYBIND11_OBJECT_DEFAULT
(
iterable
,
object
,
detail
::
iterable_check
)
};
inline
detail
::
accessor
handle
::
operator
[](
handle
key
)
const
{
return
detail
::
accessor
(
ptr
(),
key
.
ptr
(),
false
);
}
inline
detail
::
accessor
handle
::
operator
[](
handle
key
)
const
{
return
detail
::
accessor
(
ptr
(),
key
.
ptr
(),
false
);
}
inline
detail
::
accessor
handle
::
operator
[](
const
char
*
key
)
const
{
return
detail
::
accessor
(
ptr
(),
key
,
false
);
}
inline
detail
::
accessor
handle
::
operator
[](
const
char
*
key
)
const
{
return
detail
::
accessor
(
ptr
(),
key
,
false
);
}
inline
detail
::
accessor
handle
::
attr
(
handle
key
)
const
{
return
detail
::
accessor
(
ptr
(),
key
.
ptr
(),
true
);
}
inline
detail
::
accessor
handle
::
attr
(
handle
key
)
const
{
return
detail
::
accessor
(
ptr
(),
key
.
ptr
(),
true
);
}
inline
detail
::
accessor
handle
::
attr
(
const
char
*
key
)
const
{
return
detail
::
accessor
(
ptr
(),
key
,
true
);
}
inline
detail
::
accessor
handle
::
attr
(
const
char
*
key
)
const
{
return
detail
::
accessor
(
ptr
(),
key
,
true
);
}
inline
iterator
handle
::
begin
()
const
{
return
iterator
(
PyObject_GetIter
(
ptr
()));
}
inline
iterator
handle
::
begin
()
const
{
return
iterator
(
PyObject_GetIter
(
ptr
())
,
false
);
}
inline
iterator
handle
::
end
()
const
{
return
iterator
(
nullptr
);
}
inline
iterator
handle
::
end
()
const
{
return
iterator
(
nullptr
,
false
);
}
class
str
:
public
object
{
class
str
:
public
object
{
public
:
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