Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
46182697
Commit
46182697
authored
May 31, 2013
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made dlib.range() iterable
parent
f47786c3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
0 deletions
+32
-0
basic.cpp
tools/python/src/basic.cpp
+32
-0
No files found.
tools/python/src/basic.cpp
View file @
46182697
...
...
@@ -77,6 +77,34 @@ string range__repr__ (const std::pair<unsigned long,unsigned long>& p)
return
sout
.
str
();
}
struct
range_iter
{
std
::
pair
<
unsigned
long
,
unsigned
long
>
range
;
unsigned
long
cur
;
unsigned
long
next
()
{
if
(
cur
<
range
.
second
)
{
return
cur
++
;
}
else
{
PyErr_SetString
(
PyExc_StopIteration
,
"No more data."
);
boost
::
python
::
throw_error_already_set
();
return
0
;
}
}
};
range_iter
make_range_iterator
(
const
std
::
pair
<
unsigned
long
,
unsigned
long
>&
p
)
{
range_iter
temp
;
temp
.
range
=
p
;
temp
.
cur
=
p
.
first
;
return
temp
;
}
string
pair__str__
(
const
std
::
pair
<
unsigned
long
,
double
>&
p
)
{
std
::
ostringstream
sout
;
...
...
@@ -146,8 +174,12 @@ void bind_basic_types()
.
def_readwrite
(
"end"
,
&
range_type
::
second
,
"One past the index of the last element in the range."
)
.
def
(
"__str__"
,
range__str__
)
.
def
(
"__repr__"
,
range__repr__
)
.
def
(
"__iter__"
,
&
make_range_iterator
)
.
def_pickle
(
serialize_pickle
<
range_type
>
());
class_
<
range_iter
>
(
"_range_iter"
)
.
def
(
"next"
,
&
range_iter
::
next
);
{
typedef
std
::
vector
<
std
::
pair
<
unsigned
long
,
unsigned
long
>
>
type
;
class_
<
type
>
(
"ranges"
,
"This object is an array of range objects."
)
...
...
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