Core: Update Stream interface

Add Open Mode to Stream level, Add IsReadable() and IsWritable()


Former-commit-id: 0da5fa798c0f3bd3bf1545cb57f6bc923b222de8
This commit is contained in:
Lynix
2015-11-17 13:19:44 +01:00
parent fb920f0016
commit 8371ce068f
14 changed files with 114 additions and 102 deletions

View File

@@ -32,7 +32,7 @@ namespace Nz
public:
File();
File(const String& filePath);
File(const String& filePath, unsigned int openMode);
File(const String& filePath, UInt32 openMode);
File(const File&) = delete;
File(File&& file) noexcept;
~File();
@@ -71,7 +71,7 @@ namespace Nz
bool SetCursorPos(UInt64 offset) override;
void SetEndianness(Endianness endianness);
bool SetFile(const String& filePath);
bool SetOpenMode(unsigned int openMode);
bool SetOpenMode(UInt32 openMode);
using OutputStream::Write;
std::size_t Write(const void* buffer, std::size_t size) override;
@@ -102,8 +102,8 @@ namespace Nz
Endianness m_endianness;
String m_filePath;
UInt32 m_openMode;
FileImpl* m_impl;
unsigned int m_openMode;
};
template<>

View File

@@ -23,7 +23,12 @@ namespace Nz
virtual std::size_t Read(void* buffer, std::size_t size) = 0;
virtual String ReadLine(unsigned int lineSize = 0);
protected:
inline InputStream();
};
}
#include <Nazara/Core/InputStream.inl>
#endif // NAZARA_INPUTSTREAM_HPP

View File

@@ -0,0 +1,11 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
namespace Nz
{
inline InputStream::InputStream() :
Stream(OpenMode_Current)
{
}
}

View File

@@ -22,7 +22,12 @@ namespace Nz
bool Write(const ByteArray& byteArray);
bool Write(const String& string);
virtual std::size_t Write(const void* buffer, std::size_t size) = 0;
protected:
inline OutputStream();
};
}
#include <Nazara/Core/OutputStream.inl>
#endif // NAZARA_OUTPUTSTREAM_HPP

View File

@@ -0,0 +1,11 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
namespace Nz
{
inline OutputStream::OutputStream() :
Stream(OpenMode_Current)
{
}
}

View File

@@ -16,7 +16,6 @@ namespace Nz
class NAZARA_CORE_API Stream
{
public:
Stream() = default;
Stream(const Stream&) = default;
Stream(Stream&&) = default;
virtual ~Stream();
@@ -24,17 +23,26 @@ namespace Nz
virtual UInt64 GetCursorPos() const = 0;
virtual String GetDirectory() const;
virtual String GetPath() const;
unsigned int GetStreamOptions() const;
inline UInt32 GetOpenMode() const;
inline UInt32 GetStreamOptions() const;
inline bool IsReadable() const;
inline bool IsWritable() const;
virtual bool SetCursorPos(UInt64 offset) = 0;
void SetStreamOptions(unsigned int options);
void SetStreamOptions(UInt32 options);
Stream& operator=(const Stream&) = default;
Stream& operator=(Stream&&) = default;
protected:
unsigned int m_streamOptions = 0;
inline Stream(UInt32 openMode);
UInt32 m_openMode;
UInt32 m_streamOptions;
};
}
#include <Nazara/Core/Stream.inl>
#endif // NAZARA_STREAM_HPP

View File

@@ -0,0 +1,37 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
namespace Nz
{
inline Stream::Stream(UInt32 openMode) :
m_openMode(openMode),
m_streamOptions(0)
{
}
inline UInt32 Stream::GetOpenMode() const
{
return m_openMode;
}
inline UInt32 Stream::GetStreamOptions() const
{
return m_streamOptions;
}
inline bool Stream::IsReadable() const
{
return m_openMode & OpenMode_ReadOnly || m_openMode & OpenMode_ReadWrite;
}
inline bool Stream::IsWritable() const
{
return m_openMode & OpenMode_ReadWrite || m_openMode & OpenMode_WriteOnly;
}
inline void Stream::SetStreamOptions(UInt32 options)
{
m_streamOptions = options;
}
}