Minecraft Community Edition 0.1.0
Loading...
Searching...
No Matches
FileInputStream.hpp
1#pragma once
2
3#include "..\..\Platform.hpp"
4#include <fstream>
5
6#include "InputStream.hpp"
7
8#include <EASTL/string_view.h>
9
10#ifdef MCE_PLATFORM_WINDOWS
11#ifdef INVALID_FILE_SIZE
12#undef INVALID_FILE_SIZE
13#endif
14#endif
15
16namespace mce::io::stream {
17 class FileInputStream final : public InputStream {
18 public:
19 FileInputStream();
20 ~FileInputStream();
25 //explicit FileInputStream(eastl::string_view file);
26
31 bool open(const std::string& file);
32
36 bool isOpen() const;
37
41 void close();
42
49 size_t read(void* buffer, size_t size) override;
50
56 size_t seek(size_t position) override;
57
61 size_t tell() override;
62
66 size_t getSize() override;
67
68 static inline constexpr size_t FILE_NOT_FOUND = 0;
69 static inline constexpr size_t INVALID_FILE_SIZE = ~(0);
70 static inline constexpr size_t INVALID_FILE_POSITION = ~(0);
71 private:
72#ifdef MCE_PLATFORM_WINDOWS
73 void* __ptr64 hFile = nullptr;
74#elif defined(MCE_PLATFORM_LINUX) || defined(MCE_PLATFORM_MACOS)
75 std::FILE* file;
76#endif
77 };
78}
size_t seek(size_t position) override
Changes the current position the stream is reading.
size_t read(void *buffer, size_t size) override
Reads from the input stream.
void close()
Closes the file.
bool open(const std::string &file)
Constructs the stream and opens a file.