Usermode/AxWin4 - Screen dimensions acquisition, speedup, window render
[tpg/acess2.git] / Usermode / Applications / axwin4_src / Common / include / serialisation.hpp
1 /*
2  * Acess2 GUI v4
3  * - By John Hodge (thePowersGang) 
4  *
5  * serialisation.hpp
6  * - Generic (de)serialisation code
7  */
8 #ifndef _SERIALISATION_H_
9 #define _SERIALISATION_H_
10
11 #include <cstdint>
12 #include <cstddef>
13 #include <exception>
14 #include <string>
15 #include <vector>
16
17 namespace AxWin {
18
19 class CDeserialiseException:
20         public ::std::exception
21 {
22 };
23
24 class CDeserialiser
25 {
26         ::std::vector<uint8_t>  m_vect;
27         size_t  m_offset;
28 public:
29         CDeserialiser():
30                 CDeserialiser(::std::vector<uint8_t>())
31         {}
32         CDeserialiser(const ::std::vector<uint8_t>& vect);
33         CDeserialiser(::std::vector<uint8_t>&& vect);
34         CDeserialiser(const CDeserialiser& x) { *this = x; };
35         CDeserialiser& operator=(const CDeserialiser& x);
36         bool    IsConsumed() const;
37         ::uint8_t       ReadU8();
38         ::uint16_t      ReadU16();
39         ::int16_t       ReadS16();
40         const ::std::vector<uint8_t>    ReadBuffer();
41         const ::std::string     ReadString();
42 private:
43         void RangeCheck(const char *Method, size_t bytes) throw(::std::out_of_range);
44 };
45
46 class CSerialiser
47 {
48         ::std::vector<uint8_t>  m_data;
49 public:
50         CSerialiser();
51         void WriteU8(::uint8_t val);
52         void WriteU16(::uint16_t val);
53         void WriteS16(::int16_t val);
54         void WriteBuffer(size_t n, const void* val);
55         void WriteString(const char* val, size_t n);
56         void WriteString(const char* val) {
57                 WriteString(val, ::std::char_traits<char>::length(val));
58         }
59         void WriteString(const ::std::string& val) {
60                 WriteString(val.data(), val.size());
61         }
62         void WriteSub(const CSerialiser& val);
63         
64         const ::std::vector<uint8_t>& Compact();
65 };
66
67 };
68
69 #endif
70

UCC git Repository :: git.ucc.asn.au