Commit e6d7f93d authored by Davis King's avatar Davis King

Added seekg() and made vectorstream more robust.

parent 45d21205
......@@ -29,6 +29,12 @@ namespace dlib
buffer(buffer_)
{}
void seekg(size_type pos)
{
read_pos = pos;
}
// ------------------------ OUTPUT FUNCTIONS ------------------------
int_type overflow ( int_type c)
......@@ -85,14 +91,14 @@ namespace dlib
std::streamsize n
)
{
const size_type num = std::min<size_type>(n, buffer.size()-read_pos);
if (num > 0)
if (read_pos < buffer.size())
{
const size_type num = std::min<size_type>(n, buffer.size()-read_pos);
std::memcpy(s, &buffer[read_pos], num);
read_pos += num;
return num;
}
return num;
return 0;
}
};
......@@ -106,6 +112,14 @@ namespace dlib
buf(buffer)
{}
std::istream& seekg (
std::streampos pos
)
{
buf.seekg(pos);
return *this;
}
private:
vector_streambuf buf;
};
......
......@@ -43,6 +43,17 @@ namespace dlib
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
!*/
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment