| |
| |
| |
| |
| |
| |
| |
| |
| #ifndef IGL_FILEMEMORYSTREAM_H |
| #define IGL_FILEMEMORYSTREAM_H |
|
|
| #include "igl_inline.h" |
|
|
| #include <streambuf> |
| #include <istream> |
| #include <string> |
|
|
| namespace igl { |
| struct FileMemoryBuffer : public std::streambuf |
| { |
| char *p_start{nullptr}; |
| char *p_end{nullptr}; |
| size_t size; |
| |
| FileMemoryBuffer(char const *first_elem, size_t size) |
| : p_start(const_cast<char *>(first_elem)), p_end(p_start + size), |
| size(size) |
| { |
| setg(p_start, p_start, p_end); |
| } |
| |
| pos_type seekoff( |
| off_type off, |
| std::ios_base::seekdir dir, |
| std::ios_base::openmode which) override |
| { |
| if (dir == std::ios_base::cur) |
| { |
| gbump(static_cast<int>(off)); |
| }else |
| { |
| setg(p_start,(dir==std::ios_base::beg ? p_start : p_end) + off,p_end); |
| } |
| return gptr() - p_start; |
| } |
| |
| pos_type seekpos(pos_type pos, std::ios_base::openmode which) override |
| { |
| return seekoff(pos, std::ios_base::beg, which); |
| } |
| }; |
| |
| struct FileMemoryStream : virtual FileMemoryBuffer, public std::istream |
| { |
| FileMemoryStream( char const *first_elem, size_t size) |
| : FileMemoryBuffer(first_elem, size), |
| std::istream( static_cast<std::streambuf *>(this)) |
| {} |
| }; |
| } |
|
|
| #endif |
|
|
|
|