From 7af32caec2ee274ca1372114752d0273df1eb5ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Fri, 11 Mar 2022 17:46:24 +0100 Subject: [PATCH] Changed path type from std::string to std::filesystem::path in CInputStream, CInputStreamBuffer, COutputStream and COutputStreamBuffer --- src/common/resources/inputstream.cpp | 8 ++++---- src/common/resources/inputstream.h | 5 +++-- src/common/resources/inputstreambuffer.cpp | 4 ++-- src/common/resources/inputstreambuffer.h | 3 ++- src/common/resources/outputstream.cpp | 8 ++++---- src/common/resources/outputstream.h | 9 +++++---- src/common/resources/outputstreambuffer.cpp | 8 +++++--- src/common/resources/outputstreambuffer.h | 5 +++-- 8 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/common/resources/inputstream.cpp b/src/common/resources/inputstream.cpp index 259c0eb9..3bdf32d6 100644 --- a/src/common/resources/inputstream.cpp +++ b/src/common/resources/inputstream.cpp @@ -28,20 +28,20 @@ CInputStream::CInputStream() { } -CInputStream::CInputStream(const std::string& filename) +CInputStream::CInputStream(const std::filesystem::path& path) : CInputStreamBufferContainer(), std::istream(&m_buffer) { - open(filename); + open(path); } CInputStream::~CInputStream() { } -void CInputStream::open(const std::string& filename) +void CInputStream::open(const std::filesystem::path& path) { - m_buffer.open(filename); + m_buffer.open(path); } void CInputStream::close() diff --git a/src/common/resources/inputstream.h b/src/common/resources/inputstream.h index a2dea6ee..220cc8f6 100644 --- a/src/common/resources/inputstream.h +++ b/src/common/resources/inputstream.h @@ -22,6 +22,7 @@ #include "common/resources/inputstreambuffer.h" #include +#include #include #include @@ -37,10 +38,10 @@ class CInputStream : public CInputStreamBufferContainer, public std::istream { public: CInputStream(); - CInputStream(const std::string& filename); + CInputStream(const std::filesystem::path& path); virtual ~CInputStream(); - void open(const std::string& filename); + void open(const std::filesystem::path& path); void close(); bool is_open(); std::size_t size(); diff --git a/src/common/resources/inputstreambuffer.cpp b/src/common/resources/inputstreambuffer.cpp index 4df9ea97..3bdd685d 100644 --- a/src/common/resources/inputstreambuffer.cpp +++ b/src/common/resources/inputstreambuffer.cpp @@ -43,10 +43,10 @@ CInputStreamBuffer::~CInputStreamBuffer() } -void CInputStreamBuffer::open(const std::string &filename) +void CInputStreamBuffer::open(const std::filesystem::path& path) { if (PHYSFS_isInit()) - m_file = PHYSFS_openRead(CResourceManager::CleanPath(filename).c_str()); + m_file = PHYSFS_openRead(CResourceManager::CleanPath(path.generic_u8string()).c_str()); } diff --git a/src/common/resources/inputstreambuffer.h b/src/common/resources/inputstreambuffer.h index bef025d1..542d62b4 100644 --- a/src/common/resources/inputstreambuffer.h +++ b/src/common/resources/inputstreambuffer.h @@ -20,6 +20,7 @@ #pragma once #include +#include #include #include #include @@ -35,7 +36,7 @@ public: CInputStreamBuffer(const CInputStreamBuffer &) = delete; CInputStreamBuffer &operator= (const CInputStreamBuffer &) = delete; - void open(const std::string &filename); + void open(const std::filesystem::path &filename); void close(); bool is_open(); std::size_t size(); diff --git a/src/common/resources/outputstream.cpp b/src/common/resources/outputstream.cpp index 935d955a..0ab472a3 100644 --- a/src/common/resources/outputstream.cpp +++ b/src/common/resources/outputstream.cpp @@ -28,20 +28,20 @@ COutputStream::COutputStream() { } -COutputStream::COutputStream(const std::string& filename, std::ios_base::openmode mode) +COutputStream::COutputStream(const std::filesystem::path& path, std::ios_base::openmode mode) : COutputStreamBufferContainer(), std::ostream(&m_buffer) { - open(filename, mode); + open(path, mode); } COutputStream::~COutputStream() { } -void COutputStream::open(const std::string& filename, std::ios_base::openmode mode) +void COutputStream::open(const std::filesystem::path& path, std::ios_base::openmode mode) { - m_buffer.open(filename, mode); + m_buffer.open(path, mode); } void COutputStream::close() diff --git a/src/common/resources/outputstream.h b/src/common/resources/outputstream.h index 6da2cd86..fcf16f6a 100644 --- a/src/common/resources/outputstream.h +++ b/src/common/resources/outputstream.h @@ -21,6 +21,7 @@ #include "common/resources/outputstreambuffer.h" +#include #include #include @@ -38,20 +39,20 @@ public: /** Construct and Open Stream for writing * - * \param filename + * \param path * \param mode one of: std::ios_base::out - Open for writing, std::ios_base::app - Append to file * */ - COutputStream(const std::string& filename, std::ios_base::openmode mode = std::ios_base::out); + COutputStream(const std::filesystem::path& path, std::ios_base::openmode mode = std::ios_base::out); virtual ~COutputStream(); /** Open Stream for writing * - * \param filename + * \param path * \param mode one of: std::ios_base::out - Open for writing, std::ios_base::app - Append to file * */ - void open(const std::string& filename, std::ios_base::openmode mode = std::ios_base::out); + void open(const std::filesystem::path& path, std::ios_base::openmode mode = std::ios_base::out); void close(); bool is_open(); }; diff --git a/src/common/resources/outputstreambuffer.cpp b/src/common/resources/outputstreambuffer.cpp index 8e24d1c9..9b3611a6 100644 --- a/src/common/resources/outputstreambuffer.cpp +++ b/src/common/resources/outputstreambuffer.cpp @@ -43,12 +43,14 @@ COutputStreamBuffer::~COutputStreamBuffer() } -void COutputStreamBuffer::open(const std::string &filename, std::ios_base::openmode mode) +void COutputStreamBuffer::open(const std::filesystem::path& path, std::ios_base::openmode mode) { if (PHYSFS_isInit()) { - if ( mode == std::ios_base::out ) m_file = PHYSFS_openWrite(CResourceManager::CleanPath(filename).c_str()); - else if ( mode == std::ios_base::app ) m_file = PHYSFS_openAppend(CResourceManager::CleanPath(filename).c_str()); + if ( mode == std::ios_base::out ) + m_file = PHYSFS_openWrite(CResourceManager::CleanPath(path.generic_u8string()).c_str()); + else if ( mode == std::ios_base::app ) + m_file = PHYSFS_openAppend(CResourceManager::CleanPath(path.generic_u8string()).c_str()); } } diff --git a/src/common/resources/outputstreambuffer.h b/src/common/resources/outputstreambuffer.h index 6021dde9..244a1e98 100644 --- a/src/common/resources/outputstreambuffer.h +++ b/src/common/resources/outputstreambuffer.h @@ -20,6 +20,7 @@ #pragma once #include +#include #include #include #include @@ -37,11 +38,11 @@ public: /** Open Stream Buffer for writing * - * \param filename + * \param path * \param mode one of: std::ios_base::out - Open for writing, std::ios_base::app - Append to file * */ - void open(const std::string &filename, std::ios_base::openmode mode); + void open(const std::filesystem::path &path, std::ios_base::openmode mode); void close(); bool is_open();