From 5feb199afc45bac6d1cd50323f28da61ce211dd0 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 12 Oct 2022 21:54:46 +0800 Subject: Implement file stream constructor on emscripten. --- include/cru/common/io/FileStream.h | 18 ++++++++---------- include/cru/common/platform/web/WebFileStream.h | 1 - 2 files changed, 8 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/include/cru/common/io/FileStream.h b/include/cru/common/io/FileStream.h index 333b6d64..9176739a 100644 --- a/include/cru/common/io/FileStream.h +++ b/include/cru/common/io/FileStream.h @@ -2,7 +2,7 @@ * Here are some notes about FileStream: * * 1. FileStream is currently implemented as a typedef of the corresponding - * specific XxxFileStream class implemented on each platform and controled with + * specific XxxFileStream class implemented on each platform and controlled with * preprocessor commands. There might be some other ways like proxy pattern but * I do this way for simplicity. So your duty to implement a new platform is to * define a new class and ensure it implements all the required interface. And @@ -11,15 +11,8 @@ * * 2. Since each platform defines their own way to open a file, especially the * flags to open a file, we have to define a common interface. I decide to - * mimic the C++ std stream open flags - * (https://en.cppreference.com/w/cpp/io/basic_filebuf/open) so on platforms - * where there is no direct support on certain flags we try our best to - * simulate it and make a note for users. The difference between cru design and - * std design is: - * 1. cru deletes `binary` flag because Stream does not have a so-called - * _text_ mode and it is always byte based. - * 2. cru adds `OpenFileFlags::Create` and `OpenFileFlags::Exclusive` flags - * mimicking Linux behavior which does not exist in std. + * mimic Linux flags so on platforms where there is no direct support on certain + * flags we try our best to simulate it and make a note for users. * * (TODO: Currently the problem is that when I implemented for Windows and UNIX * I didn't take this into consideration so I have to fix this inconsistency @@ -40,4 +33,9 @@ using FileStream = platform::unix::UnixFileStream; namespace cru::io { using FileStream = platform::win::Win32FileStream; } +#elif CRU_PLATFORM_EMSCRIPTEN +#include "../platform/web/WebFileStream.h" +namespace cru::io { +using FileStream = platform::web::WebFileStream; +} #endif diff --git a/include/cru/common/platform/web/WebFileStream.h b/include/cru/common/platform/web/WebFileStream.h index 171df495..76f3fa84 100644 --- a/include/cru/common/platform/web/WebFileStream.h +++ b/include/cru/common/platform/web/WebFileStream.h @@ -1,6 +1,5 @@ #pragma once -#include <_stdio.h> #include "../../PreConfig.h" #ifdef CRU_PLATFORM_EMSCRIPTEN -- cgit v1.2.3