Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Stream.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_STREAM_HPP
8 #define NAZARA_STREAM_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <Nazara/Core/Endianness.hpp>
12 #include <Nazara/Core/Enums.hpp>
13 
14 namespace Nz
15 {
16  class ByteArray;
17  class String; //< Do not include String.hpp in this file
18 
19  class NAZARA_CORE_API Stream
20  {
21  public:
22  Stream(const Stream&) = default;
23  Stream(Stream&&) = default;
24  virtual ~Stream();
25 
26  virtual bool EndOfStream() const = 0;
27 
28  inline void EnableTextMode(bool textMode);
29 
30  inline void Flush();
31 
32  virtual UInt64 GetCursorPos() const = 0;
33  virtual String GetDirectory() const;
34  virtual String GetPath() const;
35  inline OpenModeFlags GetOpenMode() const;
36  inline StreamOptionFlags GetStreamOptions() const;
37 
38  virtual UInt64 GetSize() const = 0;
39 
40  inline std::size_t Read(void* buffer, std::size_t size);
41  virtual String ReadLine(unsigned int lineSize = 0);
42 
43  inline bool IsReadable() const;
44  inline bool IsSequential() const;
45  inline bool IsTextModeEnabled() const;
46  inline bool IsWritable() const;
47 
48  virtual bool SetCursorPos(UInt64 offset) = 0;
49 
50  bool Write(const ByteArray& byteArray);
51  bool Write(const String& string);
52  inline std::size_t Write(const void* buffer, std::size_t size);
53 
54  Stream& operator=(const Stream&) = default;
55  Stream& operator=(Stream&&) = default;
56 
57  protected:
58  inline Stream(StreamOptionFlags streamOptions = StreamOption_None, OpenModeFlags openMode = OpenMode_NotOpen);
59 
60  virtual void FlushStream() = 0;
61  virtual std::size_t ReadBlock(void* buffer, std::size_t size) = 0;
62  virtual std::size_t WriteBlock(const void* buffer, std::size_t size) = 0;
63 
64  OpenModeFlags m_openMode;
65  StreamOptionFlags m_streamOptions;
66  };
67 }
68 
69 #include <Nazara/Core/Stream.inl>
70 
71 #endif // NAZARA_STREAM_HPP
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Core class that represents a string.
Definition: String.hpp:22
Core class that represents an array of bytes.
Definition: ByteArray.hpp:18
Core class that represents a stream.
Definition: Stream.hpp:19