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
8da213cc
Commit
8da213cc
authored
Sep 01, 2013
by
Davis King
Browse files
Made len() work on dlib.range objects.
parent
10caab26
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
2 deletions
+11
-2
tools/python/src/basic.cpp
tools/python/src/basic.cpp
+11
-2
No files found.
tools/python/src/basic.cpp
View file @
8da213cc
...
@@ -140,6 +140,14 @@ string sparse_vector__repr__ (const std::vector<std::pair<unsigned long,double>
...
@@ -140,6 +140,14 @@ string sparse_vector__repr__ (const std::vector<std::pair<unsigned long,double>
return
sout
.
str
();
return
sout
.
str
();
}
}
unsigned
long
range_len
(
const
std
::
pair
<
unsigned
long
,
unsigned
long
>&
r
)
{
if
(
r
.
second
>
r
.
first
)
return
r
.
second
-
r
.
first
;
else
return
0
;
}
template
<
typename
T
>
template
<
typename
T
>
void
resize
(
T
&
v
,
unsigned
long
n
)
{
v
.
resize
(
n
);
}
void
resize
(
T
&
v
,
unsigned
long
n
)
{
v
.
resize
(
n
);
}
...
@@ -174,11 +182,12 @@ void bind_basic_types()
...
@@ -174,11 +182,12 @@ void bind_basic_types()
typedef
pair
<
unsigned
long
,
unsigned
long
>
range_type
;
typedef
pair
<
unsigned
long
,
unsigned
long
>
range_type
;
class_
<
range_type
>
(
"range"
,
"This object is used to represent a range of elements in an array."
,
init
<>
()
)
class_
<
range_type
>
(
"range"
,
"This object is used to represent a range of elements in an array."
,
init
<>
()
)
.
def
(
init
<
unsigned
long
,
unsigned
long
>
())
.
def
(
init
<
unsigned
long
,
unsigned
long
>
())
.
def_readwrite
(
"begin"
,
&
range_type
::
first
,
"The index of the first element in the range."
)
.
def_readwrite
(
"begin"
,
&
range_type
::
first
,
"The index of the first element in the range.
This is represented using an unsigned integer.
"
)
.
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.
This is represented using an unsigned integer.
"
)
.
def
(
"__str__"
,
range__str__
)
.
def
(
"__str__"
,
range__str__
)
.
def
(
"__repr__"
,
range__repr__
)
.
def
(
"__repr__"
,
range__repr__
)
.
def
(
"__iter__"
,
&
make_range_iterator
)
.
def
(
"__iter__"
,
&
make_range_iterator
)
.
def
(
"__len__"
,
&
range_len
)
.
def_pickle
(
serialize_pickle
<
range_type
>
());
.
def_pickle
(
serialize_pickle
<
range_type
>
());
class_
<
range_iter
>
(
"_range_iter"
)
class_
<
range_iter
>
(
"_range_iter"
)
...
...
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