Add an istream class that wraps raw data buffer
This commit is contained in:
parent
3d3e6c583b
commit
3136c3b239
1 changed files with 31 additions and 0 deletions
31
libs/util/include/psemek/util/memory_stream.hpp
Normal file
31
libs/util/include/psemek/util/memory_stream.hpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace psemek::util
|
||||
{
|
||||
|
||||
struct memory_istream
|
||||
: std::istream
|
||||
{
|
||||
memory_istream(std::string_view data)
|
||||
: b_(data)
|
||||
{
|
||||
rdbuf(&b_);
|
||||
}
|
||||
|
||||
private:
|
||||
struct buf
|
||||
: std::streambuf
|
||||
{
|
||||
buf(std::string_view data)
|
||||
{
|
||||
char * p = const_cast<char *>(data.data());
|
||||
setg(p, p, p + data.size());
|
||||
}
|
||||
};
|
||||
|
||||
buf b_;
|
||||
};
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue