Utilities  1
Collection of utility classes and functions used by my C++ applications.
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Friends Macros
binaryreader.h
Go to the documentation of this file.
1 #ifndef BINERYREADER_H
2 #define BINERYREADER_H
3 
4 #include "../application/global.h"
5 #include "../conversion/types.h"
6 #include "../conversion/binaryconversion.h"
7 
8 #include <vector>
9 #include <string>
10 #include <istream>
11 
12 namespace IoUtilities
13 {
15  {
16 
17  public:
19  BinaryReader(const BinaryReader &other);
20  BinaryReader & operator=(const BinaryReader & rhs) = delete;
21  ~BinaryReader();
22 
23  const std::istream *stream() const;
24  std::istream *stream();
25  void setStream(std::istream *stream, bool giveOwnership = false);
26  bool hasOwnership() const;
27  void giveOwnership();
28  void detatchOwnership();
29  ConversionUtilities::ByteOrder byteOrder() const;
30  void setByteOrder(ConversionUtilities::ByteOrder value);
31  bool fail() const;
32  bool eof() const;
33  bool canRead() const;
34  std::istream::pos_type readStreamsize();
35  void read(char *buffer, std::streamsize length);
36  void read(byte *buffer, std::streamsize length);
37  void read(std::vector<char> &buffer, std::streamsize length);
38  int16 readInt16();
39  uint16 readUInt16();
40  int32 readInt24();
41  uint32 readUInt24();
42  int32 readInt32();
43  uint32 readUInt32();
44  int64 readInt64();
45  uint64 readUInt64();
46  float32 readFloat32();
47  float64 readFloat64();
48  char readChar();
49  byte readByte();
50  bool readBool();
51  std::string readLengthPrefixedString();
52  std::string readString(size_t length);
53  std::string readTerminatedString(byte termination = 0);
54  std::string readTerminatedString(size_t maxBytesToRead, byte termination = 0);
55  std::string readMultibyteTerminatedString(uint16 termination = 0);
56  std::string readMultibyteTerminatedString(size_t maxBytesToRead, uint16 termination = 0);
57  uint32 readSynchsafeUInt32();
58  uint32 readCrc32(size_t length);
59  static uint32 *crc32Table();
60 
61  private:
62  std::istream *m_stream;
63  bool m_ownership;
64  std::istream::pos_type m_streamsize;
66 
67  };
68 }
69 
70 #endif // BINERYREADER_H
ByteOrder
Specifies the byte order/endianness.
std::int64_t int64
signed 64-bit integer
Definition: types.h:29
Reads primitive data types from a std::istream using a specified ConversionUtilities::ByteOrder.
Definition: binaryreader.h:14
#define LIB_EXPORT
This macro marks a symbol for shared library export.
Definition: global.h:50
std::uint64_t uint64
unsigned 64-bit integer
Definition: types.h:49
Contains utility classes helping to read and write streams.
std::uint32_t uint32
unsigned 32-bit integer
Definition: types.h:44
std::int32_t int32
signed 32-bit integer
Definition: types.h:24
std::uint8_t byte
unsigned byte
Definition: types.h:14
std::int16_t int16
signed 16-bit integer
Definition: types.h:19
std::uint16_t uint16
unsigned 16-bit integer
Definition: types.h:39