Added InputStream::EndOfStream()

Former-commit-id: d8618fbb677a73cb6890d913af66adb22e6c2a39
This commit is contained in:
Jérôme Leclercq 2012-09-21 12:07:13 +02:00
parent f9443e37d4
commit 2ea37a1877
3 changed files with 952 additions and 944 deletions

View File

@ -1,123 +1,124 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once #pragma once
#ifndef NAZARA_FILE_HPP #ifndef NAZARA_FILE_HPP
#define NAZARA_FILE_HPP #define NAZARA_FILE_HPP
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Directory.hpp> #include <Nazara/Core/Directory.hpp>
#include <Nazara/Core/Endianness.hpp> #include <Nazara/Core/Endianness.hpp>
#include <Nazara/Core/Hashable.hpp> #include <Nazara/Core/Hashable.hpp>
#include <Nazara/Core/HashDigest.hpp> #include <Nazara/Core/HashDigest.hpp>
#include <Nazara/Core/InputStream.hpp> #include <Nazara/Core/InputStream.hpp>
#include <Nazara/Core/NonCopyable.hpp> #include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_FILE #if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_FILE
#include <Nazara/Core/ThreadSafety.hpp> #include <Nazara/Core/ThreadSafety.hpp>
#else #else
#include <Nazara/Core/ThreadSafetyOff.hpp> #include <Nazara/Core/ThreadSafetyOff.hpp>
#endif #endif
class NzFileImpl; class NzFileImpl;
class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable
{ {
public: public:
enum CursorPosition enum CursorPosition
{ {
AtBegin, // Début du fichier AtBegin, // Début du fichier
AtCurrent, // Position du pointeur AtCurrent, // Position du pointeur
AtEnd // Fin du fichier AtEnd // Fin du fichier
}; };
enum OpenMode enum OpenMode
{ {
Current = 0x00, // Utilise le mode d'ouverture actuel Current = 0x00, // Utilise le mode d'ouverture actuel
Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin
Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert
ReadOnly = 0x04, // Ouvre uniquement en lecture ReadOnly = 0x04, // Ouvre uniquement en lecture
ReadWrite = 0x08, // Ouvre en lecture/écriture ReadWrite = 0x08, // Ouvre en lecture/écriture
Text = 0x10, // Ouvre en mode texte Text = 0x10, // Ouvre en mode texte
Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe
WriteOnly = 0x40 // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas WriteOnly = 0x40 // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas
}; };
NzFile(); NzFile();
NzFile(const NzString& filePath); NzFile(const NzString& filePath);
NzFile(const NzString& filePath, unsigned long openMode); NzFile(const NzString& filePath, unsigned long openMode);
NzFile(NzFile&& file) noexcept; NzFile(NzFile&& file) noexcept;
~NzFile(); ~NzFile();
bool Copy(const NzString& newFilePath); bool Copy(const NzString& newFilePath);
void Close(); void Close();
bool Delete(); bool Delete();
bool EndOfFile() const; bool EndOfFile() const;
bool EndOfStream() const;
bool Exists() const;
bool Exists() const;
void Flush();
void Flush();
time_t GetCreationTime() const;
nzUInt64 GetCursorPos() const; time_t GetCreationTime() const;
NzString GetDirectoryPath() const; nzUInt64 GetCursorPos() const;
NzString GetFilePath() const; NzString GetDirectoryPath() const;
NzString GetFileName() const; NzString GetFilePath() const;
time_t GetLastAccessTime() const; NzString GetFileName() const;
time_t GetLastWriteTime() const; time_t GetLastAccessTime() const;
NzString GetLine(unsigned int lineSize = 0); time_t GetLastWriteTime() const;
nzUInt64 GetSize() const; NzString GetLine(unsigned int lineSize = 0);
nzUInt64 GetSize() const;
bool IsOpen() const;
bool IsOpen() const;
bool Open(unsigned long openMode = Current);
bool Open(unsigned long openMode = Current);
std::size_t Read(void* buffer, std::size_t size);
std::size_t Read(void* buffer, std::size_t typeSize, unsigned int count); std::size_t Read(void* buffer, std::size_t size);
bool Rename(const NzString& newFilePath); std::size_t Read(void* buffer, std::size_t typeSize, unsigned int count);
bool Rename(const NzString& newFilePath);
bool SetCursorPos(CursorPosition pos, nzInt64 offset = 0);
bool SetCursorPos(nzUInt64 offset); bool SetCursorPos(CursorPosition pos, nzInt64 offset = 0);
void SetEndianness(nzEndianness endianness); bool SetCursorPos(nzUInt64 offset);
bool SetFile(const NzString& filePath); void SetEndianness(nzEndianness endianness);
bool SetOpenMode(unsigned int openMode); bool SetFile(const NzString& filePath);
bool SetOpenMode(unsigned int openMode);
bool Write(const NzString& string);
std::size_t Write(const void* buffer, std::size_t typeSize, unsigned int count); bool Write(const NzString& string);
std::size_t Write(const void* buffer, std::size_t typeSize, unsigned int count);
NzFile& operator=(const NzString& filePath);
NzFile& operator=(NzFile&& file) noexcept; NzFile& operator=(const NzString& filePath);
NzFile& operator=(NzFile&& file) noexcept;
static NzString AbsolutePath(const NzString& filePath);
static bool Copy(const NzString& sourcePath, const NzString& targetPath); static NzString AbsolutePath(const NzString& filePath);
static bool Delete(const NzString& filePath); static bool Copy(const NzString& sourcePath, const NzString& targetPath);
static bool Exists(const NzString& filePath); static bool Delete(const NzString& filePath);
static time_t GetCreationTime(const NzString& filePath); static bool Exists(const NzString& filePath);
static time_t GetLastAccessTime(const NzString& filePath); static time_t GetCreationTime(const NzString& filePath);
static time_t GetLastWriteTime(const NzString& filePath); static time_t GetLastAccessTime(const NzString& filePath);
static NzHashDigest GetHash(const NzString& filePath, nzHash hash); static time_t GetLastWriteTime(const NzString& filePath);
static NzHashDigest GetHash(const NzString& filePath, NzHashImpl* hash); static NzHashDigest GetHash(const NzString& filePath, nzHash hash);
static nzUInt64 GetSize(const NzString& filePath); static NzHashDigest GetHash(const NzString& filePath, NzHashImpl* hash);
static bool IsAbsolute(const NzString& path); static nzUInt64 GetSize(const NzString& filePath);
static NzString NormalizePath(const NzString& filePath); static bool IsAbsolute(const NzString& path);
static NzString NormalizeSeparators(const NzString& filePath); static NzString NormalizePath(const NzString& filePath);
static bool Rename(const NzString& sourcePath, const NzString& targetPath); static NzString NormalizeSeparators(const NzString& filePath);
static bool Rename(const NzString& sourcePath, const NzString& targetPath);
private:
bool FillHash(NzHashImpl* hash) const; private:
bool FillHash(NzHashImpl* hash) const;
NazaraMutexAttrib(m_mutex, mutable)
NazaraMutexAttrib(m_mutex, mutable)
nzEndianness m_endianness;
NzString m_filePath; nzEndianness m_endianness;
NzFileImpl* m_impl; NzString m_filePath;
unsigned int m_openMode; NzFileImpl* m_impl;
}; unsigned int m_openMode;
};
#endif // NAZARA_FILE_HPP
#endif // NAZARA_FILE_HPP

View File

@ -1,25 +1,27 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once #pragma once
#ifndef NAZARA_INPUTSTREAM_HPP #ifndef NAZARA_INPUTSTREAM_HPP
#define NAZARA_INPUTSTREAM_HPP #define NAZARA_INPUTSTREAM_HPP
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
class NzInputStream class NzInputStream
{ {
public: public:
virtual ~NzInputStream(); virtual ~NzInputStream();
virtual nzUInt64 GetCursorPos() const = 0; virtual bool EndOfStream() const = 0;
virtual nzUInt64 GetSize() const = 0;
virtual nzUInt64 GetCursorPos() const = 0;
virtual std::size_t Read(void* buffer, std::size_t size) = 0; virtual nzUInt64 GetSize() const = 0;
virtual bool SetCursorPos(nzUInt64 offset) = 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

File diff suppressed because it is too large Load Diff