Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
MemoryStream.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_MEMORYSTREAM_HPP
8 #define NAZARA_MEMORYSTREAM_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <Nazara/Core/Stream.hpp>
12 
13 namespace Nz
14 {
15  class ByteArray;
16 
17  class NAZARA_CORE_API MemoryStream : public Stream
18  {
19  public:
20  inline MemoryStream();
21  inline MemoryStream(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
22  MemoryStream(const MemoryStream&) = default;
23  MemoryStream(MemoryStream&&) = default;
24  ~MemoryStream() = default;
25 
26  void Clear();
27 
28  bool EndOfStream() const override;
29 
30  inline ByteArray& GetBuffer();
31  inline const ByteArray& GetBuffer() const;
32  UInt64 GetCursorPos() const override;
33  UInt64 GetSize() const override;
34 
35  void SetBuffer(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
36  bool SetCursorPos(UInt64 offset) override;
37 
38  MemoryStream& operator=(const MemoryStream&) = default;
39  MemoryStream& operator=(MemoryStream&&) = default;
40 
41  private:
42  void FlushStream() override;
43  std::size_t ReadBlock(void* buffer, std::size_t size) override;
44  std::size_t WriteBlock(const void* buffer, std::size_t size) override;
45 
46  ByteArray* m_buffer;
47  UInt64 m_pos;
48  };
49 }
50 
51 #include <Nazara/Core/MemoryStream.inl>
52 
53 #endif // NAZARA_MEMORYSTREAM_HPP
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Core class that represents an array of bytes.
Definition: ByteArray.hpp:18
Core class that represents a stream.
Definition: Stream.hpp:19
Constructs a MemoryStream object by default.
Definition: MemoryStream.hpp:17