diff --git a/include/Nazara/Core/Enums.hpp b/include/Nazara/Core/Enums.hpp index 9dcd77593..b3bb1bb2e 100644 --- a/include/Nazara/Core/Enums.hpp +++ b/include/Nazara/Core/Enums.hpp @@ -27,4 +27,11 @@ enum nzErrorType nzErrorType_Max = nzErrorType_Warning }; +enum nzStreamOptionFlags +{ + nzStreamOption_None = 0x0, + + nzStreamOption_Text = 0x1 +}; + #endif // NAZARA_ENUMS_CORE_HPP diff --git a/include/Nazara/Core/File.hpp b/include/Nazara/Core/File.hpp index 1f36f99f6..bcab9c24f 100644 --- a/include/Nazara/Core/File.hpp +++ b/include/Nazara/Core/File.hpp @@ -72,7 +72,6 @@ class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable NzString GetFileName() const; time_t GetLastAccessTime() const; time_t GetLastWriteTime() const; - NzString GetLine(unsigned int lineSize = 0) override; nzUInt64 GetSize() const; bool IsOpen() const; diff --git a/include/Nazara/Core/InputStream.hpp b/include/Nazara/Core/InputStream.hpp index cc2507314..4c99311ff 100644 --- a/include/Nazara/Core/InputStream.hpp +++ b/include/Nazara/Core/InputStream.hpp @@ -8,23 +8,21 @@ #define NAZARA_INPUTSTREAM_HPP #include +#include class NzString; -class NzInputStream +class NAZARA_API NzInputStream : public NzStream { public: virtual ~NzInputStream(); virtual bool EndOfStream() const = 0; - virtual nzUInt64 GetCursorPos() const = 0; virtual NzString GetLine(unsigned int lineSize = 0); virtual nzUInt64 GetSize() const = 0; virtual std::size_t Read(void* buffer, std::size_t size) = 0; - - virtual bool SetCursorPos(nzUInt64 offset) = 0; }; #endif // NAZARA_INPUTSTREAM_HPP diff --git a/include/Nazara/Core/Stream.hpp b/include/Nazara/Core/Stream.hpp new file mode 100644 index 000000000..ef67c337b --- /dev/null +++ b/include/Nazara/Core/Stream.hpp @@ -0,0 +1,28 @@ +// Copyright (C) 2012 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 + +#pragma once + +#ifndef NAZARA_STREAM_HPP +#define NAZARA_STREAM_HPP + +#include +#include + +class NAZARA_API NzStream +{ + public: + virtual ~NzStream(); + + virtual nzUInt64 GetCursorPos() const = 0; + unsigned int GetStreamOptions() const; + + virtual bool SetCursorPos(nzUInt64 offset) = 0; + void SetStreamOptions(unsigned int options); + + protected: + unsigned int m_streamOptions; +}; + +#endif // NAZARA_STREAM_HPP diff --git a/src/Nazara/Core/File.cpp b/src/Nazara/Core/File.cpp index 5a2148569..0325444b8 100644 --- a/src/Nazara/Core/File.cpp +++ b/src/Nazara/Core/File.cpp @@ -193,31 +193,6 @@ time_t NzFile::GetLastWriteTime() const return GetLastWriteTime(m_filePath); } -NzString NzFile::GetLine(unsigned int lineSize) -{ - NazaraLock(m_mutex) - - #if NAZARA_CORE_SAFE - if (!IsOpen()) - { - NazaraError("File not opened"); - return NzString(); - } - - if ((m_openMode & ReadOnly) == 0 && (m_openMode & ReadWrite) == 0) - { - NazaraError("File not opened with read access"); - return NzString(); - } - #endif - - NzString line = NzInputStream::GetLine(lineSize); - if (m_openMode & Text && !m_impl->EndOfFile() && line.EndsWith('\r')) - line.Resize(-1); - - return line; -} - nzUInt64 NzFile::GetSize() const { NazaraLock(m_mutex) @@ -272,7 +247,7 @@ std::size_t NzFile::Read(void* buffer, std::size_t typeSize, unsigned int count) if (byteRead == 0) return 0; - if (buffer && m_endianness != nzEndianness_Unknown && m_endianness != NzGetPlatformEndianness() && typeSize != 1) + if (buffer && typeSize != 1 && m_endianness != nzEndianness_Unknown && m_endianness != NzGetPlatformEndianness()) { unsigned int typeCount = byteRead/typeSize; for (unsigned int i = 0; i < typeCount; ++i) @@ -323,6 +298,9 @@ bool NzFile::Open(unsigned long openMode) return false; } + if (m_openMode & Text) + m_streamOptions &= nzStreamOption_Text; + return true; } @@ -410,6 +388,9 @@ bool NzFile::SetOpenMode(unsigned int openMode) delete m_impl; m_impl = impl; + + if (m_openMode & Text) + m_streamOptions &= nzStreamOption_Text; } m_openMode = openMode; @@ -423,7 +404,7 @@ bool NzFile::Write(const NzString& string) NzString temp(string); - if (m_openMode & Text) + if (m_streamOptions & nzStreamOption_Text) { #if defined(NAZARA_PLATFORM_WINDOWS) temp.Replace("\n", "\r\n"); diff --git a/src/Nazara/Core/InputStream.cpp b/src/Nazara/Core/InputStream.cpp index 76e4d46ea..7049a080e 100644 --- a/src/Nazara/Core/InputStream.cpp +++ b/src/Nazara/Core/InputStream.cpp @@ -45,5 +45,8 @@ NzString NzInputStream::GetLine(unsigned int lineSize) } } + if (m_streamOptions & nzStreamOption_Text && !EndOfStream() && line.EndsWith('\r')) + line.Resize(-1); + return line; } diff --git a/src/Nazara/Core/Stream.cpp b/src/Nazara/Core/Stream.cpp new file mode 100644 index 000000000..37cb56e2f --- /dev/null +++ b/src/Nazara/Core/Stream.cpp @@ -0,0 +1,18 @@ +// Copyright (C) 2012 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 + +#include +#include + +NzStream::~NzStream() = default; + +unsigned int NzStream::GetStreamOptions() const +{ + return m_streamOptions; +} + +void NzStream::SetStreamOptions(unsigned int options) +{ + m_streamOptions = options; +}