Worldstone
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
Stream.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <memory>
9 #include "IOBase.h"
10 
11 namespace WorldStone
12 {
13 
22 class IStream : public IOBase
23 {
24 public:
26  bool eof() const { return (_state & eofbit) != 0; }
27 
28  enum seekdir
29  {
30  beg,
31  cur,
32  end
33  };
38  virtual long size() = 0;
46  virtual size_t read(void* buffer, size_t size) = 0;
47 
48  template<typename T>
49  bool readRaw(T& out)
50  {
51  static_assert(std::is_trivially_copyable<T>::value,
52  "The type must be trivially copyable to access it as byte storage");
53  return sizeof(out) == read(&out, sizeof(out));
54  }
59  virtual int getc();
65  virtual long tell() = 0;
73  virtual bool seek(long offset, seekdir origin) = 0;
74 
75  virtual ~IStream();
76 };
77 
78 using StreamPtr = std::unique_ptr<IStream>;
79 }
This class reuses the parts of std::ios API but doesn't provide heavy stream functionnality (ie...
Definition: IOBase.h:16
An interface for a stream of data.
Definition: Stream.h:22
virtual long size()=0
Compute the size of the file.
bool eof() const
True if the end of the stream was reached during the last read operation.
Definition: Stream.h:26
virtual long tell()=0
Return the current position of the stream pointer.
virtual bool seek(long offset, seekdir origin)=0
Change the pointer of the stream to a given position.
virtual size_t read(void *buffer, size_t size)=0
Read data from the stream.
virtual int getc()
Read one byte from the stream.
Definition: _VTablesTU.cpp:17