Changed path type from std::string to std::filesystem::path in CInputStream, CInputStreamBuffer, COutputStream and COutputStreamBuffer

dev
Tomasz Kapuściński 2022-03-11 17:46:24 +01:00
parent 2d9db9c90a
commit 7af32caec2
8 changed files with 28 additions and 22 deletions

View File

@ -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()

View File

@ -22,6 +22,7 @@
#include "common/resources/inputstreambuffer.h"
#include <cstddef>
#include <filesystem>
#include <istream>
#include <string>
@ -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();

View File

@ -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());
}

View File

@ -20,6 +20,7 @@
#pragma once
#include <cstddef>
#include <filesystem>
#include <memory>
#include <streambuf>
#include <string>
@ -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();

View File

@ -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()

View File

@ -21,6 +21,7 @@
#include "common/resources/outputstreambuffer.h"
#include <filesystem>
#include <ostream>
#include <string>
@ -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();
};

View File

@ -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());
}
}

View File

@ -20,6 +20,7 @@
#pragma once
#include <cstddef>
#include <filesystem>
#include <memory>
#include <streambuf>
#include <string>
@ -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();