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
OpenDAS
dlib
Commits
46182697
"...kernels/git@developer.sourcefind.cn:OpenDAS/lmdeploy.git" did not exist on "816022e451cccef83c93a5c392fd4cbea2b5cffe"
Commit
46182697
authored
May 30, 2013
by
Davis King
Browse files
Made dlib.range() iterable
parent
f47786c3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
0 deletions
+32
-0
tools/python/src/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)
...
@@ -77,6 +77,34 @@ string range__repr__ (const std::pair<unsigned long,unsigned long>& p)
return
sout
.
str
();
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
)
string
pair__str__
(
const
std
::
pair
<
unsigned
long
,
double
>&
p
)
{
{
std
::
ostringstream
sout
;
std
::
ostringstream
sout
;
...
@@ -146,8 +174,12 @@ void bind_basic_types()
...
@@ -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_readwrite
(
"end"
,
&
range_type
::
second
,
"One past the index of the last element in the range."
)
.
def
(
"__str__"
,
range__str__
)
.
def
(
"__str__"
,
range__str__
)
.
def
(
"__repr__"
,
range__repr__
)
.
def
(
"__repr__"
,
range__repr__
)
.
def
(
"__iter__"
,
&
make_range_iterator
)
.
def_pickle
(
serialize_pickle
<
range_type
>
());
.
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
;
typedef
std
::
vector
<
std
::
pair
<
unsigned
long
,
unsigned
long
>
>
type
;
class_
<
type
>
(
"ranges"
,
"This object is an array of range objects."
)
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