Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
ByteStream.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_BYTESTREAM_HPP
8 #define NAZARA_BYTESTREAM_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <Nazara/Core/SerializationContext.hpp>
12 #include <memory>
13 
14 namespace Nz
15 {
16  class ByteArray;
17  class Stream;
18 
19  class NAZARA_CORE_API ByteStream
20  {
21  public:
22  inline ByteStream(Stream* stream = nullptr);
23  ByteStream(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
24  ByteStream(void* ptr, Nz::UInt64 size);
25  ByteStream(const void* ptr, Nz::UInt64 size);
26  ByteStream(const ByteStream&) = delete;
27  inline ByteStream(ByteStream&& stream);
28  virtual ~ByteStream();
29 
30  inline Endianness GetDataEndianness() const;
31  inline Nz::UInt64 GetSize() const;
32  inline Stream* GetStream() const;
33 
34  inline bool FlushBits();
35 
36  inline std::size_t Read(void* ptr, std::size_t size);
37 
38  inline void SetDataEndianness(Endianness endiannes);
39  inline void SetStream(Stream* stream);
40  void SetStream(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
41  void SetStream(void* ptr, Nz::UInt64 size);
42  void SetStream(const void* ptr, Nz::UInt64 size);
43 
44  inline void Write(const void* data, std::size_t size);
45 
46  template<typename T>
47  ByteStream& operator>>(T& value);
48 
49  template<typename T>
50  ByteStream& operator<<(const T& value);
51 
52  ByteStream& operator=(const ByteStream&) = delete;
53  inline ByteStream& operator=(ByteStream&&);
54 
55  private:
56  virtual void OnEmptyStream();
57 
58  std::unique_ptr<Stream> m_ownedStream;
59  SerializationContext m_context;
60  };
61 }
62 
63 #include <Nazara/Core/ByteStream.inl>
64 
65 #endif // NAZARA_BYTESTREAM_HPP
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
std::istream & operator>>(std::istream &is, String &str)
Inputs the stream into the string.
Definition: String.cpp:5458
Core class that represents a stream of bytes.
Definition: ByteStream.hpp:19
Structure containing a serialization/unserialization context states.
Definition: SerializationContext.hpp:18
Core class that represents an array of bytes.
Definition: ByteArray.hpp:18
Core class that represents a stream.
Definition: Stream.hpp:19