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
e6d7f93d
Commit
e6d7f93d
authored
Nov 18, 2012
by
Davis King
Browse files
Added seekg() and made vectorstream more robust.
parent
45d21205
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
4 deletions
+29
-4
dlib/vectorstream/vectorstream.h
dlib/vectorstream/vectorstream.h
+18
-4
dlib/vectorstream/vectorstream_abstract.h
dlib/vectorstream/vectorstream_abstract.h
+11
-0
No files found.
dlib/vectorstream/vectorstream.h
View file @
e6d7f93d
...
@@ -29,6 +29,12 @@ namespace dlib
...
@@ -29,6 +29,12 @@ namespace dlib
buffer
(
buffer_
)
buffer
(
buffer_
)
{}
{}
void
seekg
(
size_type
pos
)
{
read_pos
=
pos
;
}
// ------------------------ OUTPUT FUNCTIONS ------------------------
// ------------------------ OUTPUT FUNCTIONS ------------------------
int_type
overflow
(
int_type
c
)
int_type
overflow
(
int_type
c
)
...
@@ -85,14 +91,14 @@ namespace dlib
...
@@ -85,14 +91,14 @@ namespace dlib
std
::
streamsize
n
std
::
streamsize
n
)
)
{
{
const
size_type
num
=
std
::
min
<
size_type
>
(
n
,
buffer
.
size
()
-
read_pos
);
if
(
read_pos
<
buffer
.
size
())
if
(
num
>
0
)
{
{
const
size_type
num
=
std
::
min
<
size_type
>
(
n
,
buffer
.
size
()
-
read_pos
);
std
::
memcpy
(
s
,
&
buffer
[
read_pos
],
num
);
std
::
memcpy
(
s
,
&
buffer
[
read_pos
],
num
);
read_pos
+=
num
;
read_pos
+=
num
;
return
num
;
}
}
return
0
;
return
num
;
}
}
};
};
...
@@ -106,6 +112,14 @@ namespace dlib
...
@@ -106,6 +112,14 @@ namespace dlib
buf
(
buffer
)
buf
(
buffer
)
{}
{}
std
::
istream
&
seekg
(
std
::
streampos
pos
)
{
buf
.
seekg
(
pos
);
return
*
this
;
}
private:
private:
vector_streambuf
buf
;
vector_streambuf
buf
;
};
};
...
...
dlib/vectorstream/vectorstream_abstract.h
View file @
e6d7f93d
...
@@ -43,6 +43,17 @@ namespace dlib
...
@@ -43,6 +43,17 @@ namespace dlib
immediately show up in the buffer.
immediately show up in the buffer.
!*/
!*/
std
::
istream
&
seekg
(
std
::
streampos
pos
);
/*!
ensures
- The next read from this object will read from the position buffer[pos],
where buffer is the std::vector given to this object's constructor. Note
that if pos >= buffer.size() then the next read will simply return EOF.
- returns *this
!*/
};
};
}
}
...
...
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