ibytestream.h
1 #pragma once
2 
3 #include "stormancer/BuildConfig.h"
4 #include "stormancer/Streams/bytestreambuf.h"
5 #include <istream>
6 #include <vector>
7 #include <iostream>
8 
9 namespace Stormancer
10 {
11  class ibytestream : public std::basic_istream<byte>
12  {
13  public:
14 
15 #pragma region public_methods
16 
17  ibytestream();
18 
19  ibytestream(byte* data, std::streamsize dataSize);
20 
21  ibytestream(const ibytestream& other) = delete;
22 
23  ibytestream(ibytestream&& other);
24 
25  ibytestream& operator>>(char& value);
26 
27  ibytestream& operator>>(int8& value);
28 
29  ibytestream& operator>>(uint8& value);
30 
31  ibytestream& operator>>(int16& value);
32 
33  ibytestream& operator>>(uint16& value);
34 
35  ibytestream& operator>>(int32& value);
36 
37  ibytestream& operator>>(uint32& value);
38 
39  ibytestream& operator>>(int64& value);
40 
41  ibytestream& operator>>(uint64& value);
42 
43  ibytestream& operator>>(float& value);
44 
45  ibytestream& operator>>(double& value);
46 
47  ibytestream& operator>>(bool& value);
48 
49  ibytestream& operator>>(void*& value);
50 
51  ibytestream& operator>>(std::vector<byte>& bytes);
52 
53  std::vector<byte> bytes();
54 
55  byte* startPtr();
56 
57  byte* currentPtr();
58 
59  byte* endPtr();
60 
61  std::streamsize totalSize();
62 
63  std::streamsize availableSize();
64 
65  std::streamsize currentPosition();
66 
67  ibytestream& read(byte* ptr, std::streamsize size);
68 
69  ibytestream& read(char* ptr, std::streamsize size);
70 
71 #pragma endregion
72 
73  private:
74 
75 #pragma region private_methods
76 
77  template<typename T>
78  inline ibytestream& deserialize(T& value)
79  {
80  if (good())
81  {
82  read(reinterpret_cast<byte*>(&value), sizeof(T));
83  }
84  return (*this);
85  }
86 
87 #pragma endregion
88 
89 #pragma region private_members
90 
91  bytestreambuf _buffer;
92 
93 #pragma endregion
94  };
95 }
Definition: bytestreambuf.h:30
Definition: ibytestream.h:11