Worldstone
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
FileStream.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include "Stream.h"
9 
10 namespace WorldStone
11 {
12 
16 class FileStream : public IStream
17 {
18  FILE* file = nullptr;
19 
20 public:
21  FileStream(const Path& filename);
22  ~FileStream() override;
23 
24  bool open(const Path& filename);
25  bool is_open() const { return file != nullptr; }
26  bool close();
27 
28  long tell() override;
29  bool seek(long offset, seekdir origin) override;
30 
36  long size() override;
37  size_t read(void* buffer, size_t size) override;
38  int getc() override;
39 };
40 }
An interface for a stream of data.
Definition: Stream.h:22
bool seek(long offset, seekdir origin) override
Change the pointer of the stream to a given position.
Definition: FileStream.cpp:52
long size() override
Computes the size of the file.
Definition: FileStream.cpp:59
int getc() override
Read one byte from the stream.
Definition: FileStream.cpp:72
size_t read(void *buffer, size_t size) override
Read data from the stream.
Definition: FileStream.cpp:29
long tell() override
Return the current position of the stream pointer.
Definition: FileStream.cpp:42
Wrapper around POSIX file io, same as ifstream but without iostream formatting.
Definition: FileStream.h:16