OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
memorystream.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_COMPONENTS_FILES_MEMORYSTREAM_H
2 #define OPENMW_COMPONENTS_FILES_MEMORYSTREAM_H
3 
4 #include <istream>
5 
6 namespace Files
7 {
8 
9  struct MemBuf : std::streambuf
10  {
11  MemBuf(char const* buffer, size_t size)
12  {
13  // a streambuf isn't specific to istreams, so we need a non-const pointer :/
14  char* nonconstBuffer = (const_cast<char*>(buffer));
15  this->setg(nonconstBuffer, nonconstBuffer, nonconstBuffer + size);
16  }
17  };
18 
20  struct IMemStream: virtual MemBuf, std::istream
21  {
22  IMemStream(char const* buffer, size_t size)
23  : MemBuf(buffer, size)
24  , std::istream(static_cast<std::streambuf*>(this))
25  {
26  }
27  };
28 
29 }
30 
31 #endif
MemBuf(char const *buffer, size_t size)
Definition: memorystream.hpp:11
IMemStream(char const *buffer, size_t size)
Definition: memorystream.hpp:22
Definition: memorystream.hpp:9
A variant of std::istream that reads from a constant in-memory buffer.
Definition: memorystream.hpp:20