Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
File.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Engine - Core module"
3 // For conditions of distribution and use, see copyright notice in Config.hpp
4 
5 #pragma once
6 
7 #ifndef NAZARA_FILE_HPP
8 #define NAZARA_FILE_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <Nazara/Core/ByteArray.hpp>
12 #include <Nazara/Core/Endianness.hpp>
13 #include <Nazara/Core/MovablePtr.hpp>
14 #include <Nazara/Core/Stream.hpp>
15 #include <Nazara/Core/String.hpp>
16 
17 #if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_FILE
18  #include <Nazara/Core/ThreadSafety.hpp>
19 #else
20  #include <Nazara/Core/ThreadSafetyOff.hpp>
21 #endif
22 
23 #include <ctime>
24 
25 namespace Nz
26 {
27  class FileImpl;
28 
29  class NAZARA_CORE_API File : public Stream
30  {
31  public:
32  File();
33  File(const String& filePath);
34  File(const String& filePath, OpenModeFlags openMode);
35  File(const File&) = delete;
36  File(File&& file) noexcept = default;
37  ~File();
38 
39  bool Copy(const String& newFilePath);
40  void Close();
41 
42  bool Delete();
43 
44  bool EndOfFile() const;
45  bool EndOfStream() const override;
46 
47  bool Exists() const;
48 
49  time_t GetCreationTime() const;
50  UInt64 GetCursorPos() const override;
51  String GetDirectory() const override;
52  String GetFileName() const;
53  time_t GetLastAccessTime() const;
54  time_t GetLastWriteTime() const;
55  String GetPath() const override;
56  UInt64 GetSize() const override;
57 
58  bool IsOpen() const;
59 
60  bool Open(OpenModeFlags openMode = OpenMode_NotOpen);
61  bool Open(const String& filePath, OpenModeFlags openMode = OpenMode_NotOpen);
62 
63  bool Rename(const String& newFilePath);
64 
65  bool SetCursorPos(CursorPosition pos, Int64 offset = 0);
66  bool SetCursorPos(UInt64 offset) override;
67  bool SetFile(const String& filePath);
68  bool SetSize(UInt64 size);
69 
70  File& operator=(const String& filePath);
71  File& operator=(const File&) = delete;
72  File& operator=(File&& file) noexcept = default;
73 
74  static String AbsolutePath(const String& filePath);
75  static inline ByteArray ComputeHash(HashType hash, const String& filePath);
76  static inline ByteArray ComputeHash(AbstractHash* hash, const String& filePath);
77  static bool Copy(const String& sourcePath, const String& targetPath);
78  static bool Delete(const String& filePath);
79  static bool Exists(const String& filePath);
80  static time_t GetCreationTime(const String& filePath);
81  static String GetDirectory(const String& filePath);
82  static time_t GetLastAccessTime(const String& filePath);
83  static time_t GetLastWriteTime(const String& filePath);
84  static UInt64 GetSize(const String& filePath);
85  static bool IsAbsolute(const String& filePath);
86  static String NormalizePath(const String& filePath);
87  static String NormalizeSeparators(const String& filePath);
88  static bool Rename(const String& sourcePath, const String& targetPath);
89 
90  private:
91  NazaraMutexAttrib(m_mutex, mutable)
92 
93  void FlushStream() override;
94  std::size_t ReadBlock(void* buffer, std::size_t size) override;
95  std::size_t WriteBlock(const void* buffer, std::size_t size) override;
96 
97  String m_filePath;
98  MovablePtr<FileImpl> m_impl;
99  };
100 
101  NAZARA_CORE_API bool HashAppend(AbstractHash* hash, const File& originalFile);
102 }
103 
104 #include <Nazara/Core/File.inl>
105 
106 #endif // NAZARA_FILE_HPP
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
ByteArray ComputeHash(HashType hash, const T &v)
Computes the hash of a hashable object.
Definition: Algorithm.inl:98
Core class that represents the behaviour of the hash classes.
Definition: AbstractHash.hpp:18
Core class that represents a string.
Definition: String.hpp:22
Core class that represents a file.
Definition: File.hpp:29
Core class that represents an array of bytes.
Definition: ByteArray.hpp:18
Core class that represents a stream.
Definition: Stream.hpp:19