Added NzStream and stream options
Former-commit-id: d2c69b12f34fffff4d412111e7af7cc4dbb638a8
This commit is contained in:
parent
aaca9349fd
commit
07e949404c
|
|
@ -27,4 +27,11 @@ enum nzErrorType
|
||||||
nzErrorType_Max = nzErrorType_Warning
|
nzErrorType_Max = nzErrorType_Warning
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum nzStreamOptionFlags
|
||||||
|
{
|
||||||
|
nzStreamOption_None = 0x0,
|
||||||
|
|
||||||
|
nzStreamOption_Text = 0x1
|
||||||
|
};
|
||||||
|
|
||||||
#endif // NAZARA_ENUMS_CORE_HPP
|
#endif // NAZARA_ENUMS_CORE_HPP
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,6 @@ class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable
|
||||||
NzString GetFileName() const;
|
NzString GetFileName() const;
|
||||||
time_t GetLastAccessTime() const;
|
time_t GetLastAccessTime() const;
|
||||||
time_t GetLastWriteTime() const;
|
time_t GetLastWriteTime() const;
|
||||||
NzString GetLine(unsigned int lineSize = 0) override;
|
|
||||||
nzUInt64 GetSize() const;
|
nzUInt64 GetSize() const;
|
||||||
|
|
||||||
bool IsOpen() const;
|
bool IsOpen() const;
|
||||||
|
|
|
||||||
|
|
@ -8,23 +8,21 @@
|
||||||
#define NAZARA_INPUTSTREAM_HPP
|
#define NAZARA_INPUTSTREAM_HPP
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Core/Stream.hpp>
|
||||||
|
|
||||||
class NzString;
|
class NzString;
|
||||||
|
|
||||||
class NzInputStream
|
class NAZARA_API NzInputStream : public NzStream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~NzInputStream();
|
virtual ~NzInputStream();
|
||||||
|
|
||||||
virtual bool EndOfStream() const = 0;
|
virtual bool EndOfStream() const = 0;
|
||||||
|
|
||||||
virtual nzUInt64 GetCursorPos() const = 0;
|
|
||||||
virtual NzString GetLine(unsigned int lineSize = 0);
|
virtual NzString GetLine(unsigned int lineSize = 0);
|
||||||
virtual nzUInt64 GetSize() const = 0;
|
virtual nzUInt64 GetSize() const = 0;
|
||||||
|
|
||||||
virtual std::size_t Read(void* buffer, std::size_t size) = 0;
|
virtual std::size_t Read(void* buffer, std::size_t size) = 0;
|
||||||
|
|
||||||
virtual bool SetCursorPos(nzUInt64 offset) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NAZARA_INPUTSTREAM_HPP
|
#endif // NAZARA_INPUTSTREAM_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 <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Core/Enums.hpp>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
@ -193,31 +193,6 @@ time_t NzFile::GetLastWriteTime() const
|
||||||
return GetLastWriteTime(m_filePath);
|
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
|
nzUInt64 NzFile::GetSize() const
|
||||||
{
|
{
|
||||||
NazaraLock(m_mutex)
|
NazaraLock(m_mutex)
|
||||||
|
|
@ -272,7 +247,7 @@ std::size_t NzFile::Read(void* buffer, std::size_t typeSize, unsigned int count)
|
||||||
if (byteRead == 0)
|
if (byteRead == 0)
|
||||||
return 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;
|
unsigned int typeCount = byteRead/typeSize;
|
||||||
for (unsigned int i = 0; i < typeCount; ++i)
|
for (unsigned int i = 0; i < typeCount; ++i)
|
||||||
|
|
@ -323,6 +298,9 @@ bool NzFile::Open(unsigned long openMode)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_openMode & Text)
|
||||||
|
m_streamOptions &= nzStreamOption_Text;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -410,6 +388,9 @@ bool NzFile::SetOpenMode(unsigned int openMode)
|
||||||
delete m_impl;
|
delete m_impl;
|
||||||
|
|
||||||
m_impl = impl;
|
m_impl = impl;
|
||||||
|
|
||||||
|
if (m_openMode & Text)
|
||||||
|
m_streamOptions &= nzStreamOption_Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_openMode = openMode;
|
m_openMode = openMode;
|
||||||
|
|
@ -423,7 +404,7 @@ bool NzFile::Write(const NzString& string)
|
||||||
|
|
||||||
NzString temp(string);
|
NzString temp(string);
|
||||||
|
|
||||||
if (m_openMode & Text)
|
if (m_streamOptions & nzStreamOption_Text)
|
||||||
{
|
{
|
||||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
#if defined(NAZARA_PLATFORM_WINDOWS)
|
||||||
temp.Replace("\n", "\r\n");
|
temp.Replace("\n", "\r\n");
|
||||||
|
|
|
||||||
|
|
@ -45,5 +45,8 @@ NzString NzInputStream::GetLine(unsigned int lineSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_streamOptions & nzStreamOption_Text && !EndOfStream() && line.EndsWith('\r'))
|
||||||
|
line.Resize(-1);
|
||||||
|
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 <Nazara/Core/Stream.hpp>
|
||||||
|
#include <Nazara/Core/Debug.hpp>
|
||||||
|
|
||||||
|
NzStream::~NzStream() = default;
|
||||||
|
|
||||||
|
unsigned int NzStream::GetStreamOptions() const
|
||||||
|
{
|
||||||
|
return m_streamOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NzStream::SetStreamOptions(unsigned int options)
|
||||||
|
{
|
||||||
|
m_streamOptions = options;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue