Core/Enum: Convert OpenMode and StreamOption to the new flags system

This commit is contained in:
Lynix
2016-11-27 13:40:47 +01:00
parent 1a5617bc55
commit a34d1e410c
17 changed files with 78 additions and 60 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// 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
@@ -19,7 +19,7 @@ namespace Nz
{
public:
inline ByteStream(Stream* stream = nullptr);
ByteStream(ByteArray* byteArray, UInt32 openMode = OpenMode_ReadWrite);
ByteStream(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
ByteStream(void* ptr, Nz::UInt64 size);
ByteStream(const void* ptr, Nz::UInt64 size);
ByteStream(const ByteStream&) = delete;
@@ -36,7 +36,7 @@ namespace Nz
inline void SetDataEndianness(Endianness endiannes);
inline void SetStream(Stream* stream);
void SetStream(ByteArray* byteArray, UInt32 openMode = OpenMode_ReadWrite);
void SetStream(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
void SetStream(void* ptr, Nz::UInt64 size);
void SetStream(const void* ptr, Nz::UInt64 size);

View File

@@ -7,6 +7,8 @@
#ifndef NAZARA_ENUMS_CORE_HPP
#define NAZARA_ENUMS_CORE_HPP
#include <Nazara/Core/Flags.hpp>
namespace Nz
{
enum CoordSys
@@ -73,23 +75,31 @@ namespace Nz
HashType_Max = HashType_Whirlpool
};
enum OpenModeFlags
enum OpenMode
{
OpenMode_NotOpen = 0x00, // Use the current mod of opening
OpenMode_NotOpen, // Use the current mod of opening
OpenMode_Append = 0x01, // Disable writing on existing parts and put the cursor at the end
OpenMode_Lock = 0x02, // Disable modifying the file before it is open
OpenMode_MustExit = 0x04, // Fail if the file doesn't exists, even if opened in write mode
OpenMode_ReadOnly = 0x08, // Open in read only
OpenMode_Text = 0x10, // Open in text mod
OpenMode_Truncate = 0x20, // Create the file if it doesn't exist and empty it if it exists
OpenMode_WriteOnly = 0x40, // Open in write only, create the file if it doesn't exist
OpenMode_Append, // Disable writing on existing parts and put the cursor at the end
OpenMode_Lock, // Disable modifying the file before it is open
OpenMode_MustExit, // Fail if the file doesn't exists, even if opened in write mode
OpenMode_ReadOnly, // Open in read only
OpenMode_Text, // Open in text mod
OpenMode_Truncate, // Create the file if it doesn't exist and empty it if it exists
OpenMode_WriteOnly, // Open in write only, create the file if it doesn't exist
OpenMode_ReadWrite = OpenMode_ReadOnly | OpenMode_WriteOnly, // Open in read and write
OpenMode_Max = OpenMode_WriteOnly * 2 - 1
OpenMode_Max = OpenMode_WriteOnly
};
template<>
struct EnableFlagsOperators<OpenMode>
{
static constexpr bool value = true;
};
using OpenModeFlags = Flags<OpenMode>;
constexpr OpenModeFlags OpenMode_ReadWrite = OpenMode_ReadOnly | OpenMode_WriteOnly;
enum ParameterType
{
ParameterType_Boolean,
@@ -173,16 +183,24 @@ namespace Nz
SphereType_Max = SphereType_UV
};
enum StreamOptionFlags
enum StreamOption
{
StreamOption_None = 0,
StreamOption_None,
StreamOption_Sequential = 0x1,
StreamOption_Text = 0x2,
StreamOption_Sequential,
StreamOption_Text,
StreamOption_Max = StreamOption_Text * 2 - 1
StreamOption_Max = StreamOption_Text
};
template<>
struct EnableFlagsOperators<StreamOption>
{
static constexpr bool value = true;
};
using StreamOptionFlags = Flags<StreamOption>;
enum Ternary
{
Ternary_False,

View File

@@ -31,7 +31,7 @@ namespace Nz
public:
File();
File(const String& filePath);
File(const String& filePath, UInt32 openMode);
File(const String& filePath, OpenModeFlags openMode);
File(const File&) = delete;
File(File&& file) noexcept;
~File();
@@ -57,8 +57,8 @@ namespace Nz
bool IsOpen() const;
bool Open(unsigned int openMode = OpenMode_NotOpen);
bool Open(const String& filePath, unsigned int openMode = OpenMode_NotOpen);
bool Open(OpenModeFlags openMode = OpenMode_NotOpen);
bool Open(const String& filePath, OpenModeFlags openMode = OpenMode_NotOpen);
bool Rename(const String& newFilePath);

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// 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
@@ -18,7 +18,7 @@ namespace Nz
{
public:
inline MemoryStream();
inline MemoryStream(ByteArray* byteArray, UInt32 openMode = OpenMode_ReadWrite);
inline MemoryStream(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
MemoryStream(const MemoryStream&) = default;
MemoryStream(MemoryStream&&) = default;
~MemoryStream() = default;
@@ -32,7 +32,7 @@ namespace Nz
UInt64 GetCursorPos() const override;
UInt64 GetSize() const override;
void SetBuffer(ByteArray* byteArray, UInt32 openMode = OpenMode_ReadWrite);
void SetBuffer(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
bool SetCursorPos(UInt64 offset) override;
MemoryStream& operator=(const MemoryStream&) = default;

View File

@@ -24,7 +24,7 @@ namespace Nz
* \param byteArray Bytes to stream
* \param openMode Reading/writing mode for the stream
*/
inline MemoryStream::MemoryStream(ByteArray* byteArray, UInt32 openMode) :
inline MemoryStream::MemoryStream(ByteArray* byteArray, OpenModeFlags openMode) :
MemoryStream()
{
SetBuffer(byteArray, openMode);

View File

@@ -32,8 +32,8 @@ namespace Nz
virtual UInt64 GetCursorPos() const = 0;
virtual String GetDirectory() const;
virtual String GetPath() const;
inline UInt32 GetOpenMode() const;
inline UInt32 GetStreamOptions() const;
inline OpenModeFlags GetOpenMode() const;
inline StreamOptionFlags GetStreamOptions() const;
virtual UInt64 GetSize() const = 0;
@@ -55,14 +55,14 @@ namespace Nz
Stream& operator=(Stream&&) = default;
protected:
inline Stream(UInt32 streamOptions = StreamOption_None, UInt32 openMode = OpenMode_NotOpen);
inline Stream(StreamOptionFlags streamOptions = StreamOption_None, OpenModeFlags openMode = OpenMode_NotOpen);
virtual void FlushStream() = 0;
virtual std::size_t ReadBlock(void* buffer, std::size_t size) = 0;
virtual std::size_t WriteBlock(const void* buffer, std::size_t size) = 0;
UInt32 m_openMode;
UInt32 m_streamOptions;
OpenModeFlags m_openMode;
StreamOptionFlags m_streamOptions;
};
}

View File

@@ -15,7 +15,7 @@ namespace Nz
* \param openMode Reading/writing mode for the stream
*/
inline Stream::Stream(UInt32 streamOptions, UInt32 openMode) :
inline Stream::Stream(StreamOptionFlags streamOptions, OpenModeFlags openMode) :
m_openMode(openMode),
m_streamOptions(streamOptions)
{
@@ -53,7 +53,7 @@ namespace Nz
* \return Reading/writing mode for the stream
*/
inline UInt32 Stream::GetOpenMode() const
inline OpenModeFlags Stream::GetOpenMode() const
{
return m_openMode;
}
@@ -63,7 +63,7 @@ namespace Nz
* \return Options of the stream
*/
inline UInt32 Stream::GetStreamOptions() const
inline StreamOptionFlags Stream::GetStreamOptions() const
{
return m_streamOptions;
}
@@ -116,7 +116,7 @@ namespace Nz
* \param size Size meant to be read
*
* \remark Produces a NazaraAssert if stream is not readable
* \remark If preallocated space of buffer is less than the size, the behaviour is undefined
* \remark If preallocated space of buffer is less than the size, the behavior is undefined
*/
inline std::size_t Stream::Read(void* buffer, std::size_t size)
@@ -134,7 +134,7 @@ namespace Nz
* \param size Size meant to be written
*
* \remark Produces a NazaraAssert if stream is not writable
* \remark If preallocated space of buffer is less than the size, the behaviour is undefined
* \remark If preallocated space of buffer is less than the size, the behavior is undefined
*/
inline std::size_t Stream::Write(const void* buffer, std::size_t size)