SDL Window Engine  20200905
swe_streambuf.h
1 /***************************************************************************
2  * Copyright (C) 2017 by SWE team <sdl.window.engine@gmail.com> *
3  * *
4  * Part of the SWE: SDL Window Engine: *
5  * https://github.com/AndreyBarmaley/sdl-window-engine *
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 
23 #ifndef _SWE_STREAMBUF_
24 #define _SWE_STREAMBUF_
25 
26 #include "swe_serialize.h"
27 
29 namespace SWE
30 {
31 
32  class StreamBufRO : public StreamBase
33  {
34  void putBE64(u64) override {}
35  void putLE64(u64) override {}
36  void putBE32(u32) override {}
37  void putLE32(u32) override {}
38  void putBE16(u16) override {}
39  void putLE16(u16) override {}
40 
41  void put(const char*, size_t) override {}
42  void put8(char) override {}
43 
44  StreamBufRO(const StreamBufRO &) {}
45  StreamBufRO & operator=(const StreamBufRO &) { return *this; }
46 
47  protected:
48  StreamRWops sr;
49 
50  public:
51  StreamBufRO() {}
52  StreamBufRO(const BinaryBuf &);
53  StreamBufRO(const u8*, size_t);
54 
55  virtual void setBuf(const u8*, size_t);
56  virtual void setBuf(const BinaryBuf &);
57 
58  size_t lastg(void) const;
59  size_t tellg(void) const;
60  bool seekg(size_t pos, int whence = RW_SEEK_SET) const;
61  bool skipg(size_t len) const;
62 
63  size_t tell(void) const override { return tellg(); }
64  bool skip(size_t len) const override { return skipg(len); }
65  bool seek(int offset, int whence = RW_SEEK_SET) const override { return seekg(offset, whence); }
66 
67  int getBE16(void) const override;
68  int getLE16(void) const override;
69  int getBE32(void) const override;
70  int getLE32(void) const override;
71  s64 getBE64(void) const override;
72  s64 getLE64(void) const override;
73 
74  int get8(void) const override;
75  BinaryBuf get(size_t = 0 /* all data */) const override;
76  };
77 
78  class StreamBufRW : public StreamBufRO
79  {
80  size_t tell(void) const override { return 0; }
81  bool skip(size_t len) const override { return false; }
82  bool seek(int offset, int whence = RW_SEEK_SET) const override { return false; }
83 
84  protected:
85  BinaryBuf buf;
86  StreamRWops sw;
87 
88  bool resize(size_t);
89 
90  public:
91  StreamBufRW();
92  StreamBufRW(const StreamBufRW &);
93  StreamBufRW(const BinaryBuf &);
94  StreamBufRW(const u8*, size_t);
95  StreamBufRW(BinaryBuf &&) noexcept;
96 
97  StreamBufRW & operator=(const StreamBufRW &);
98 
99  void setBuf(const u8*, size_t) override;
100  void setBuf(const BinaryBuf &) override;
101 
102  size_t lastp(void) const;
103  size_t tellp(void) const;
104  bool seekp(size_t pos, int whence = RW_SEEK_SET) const;
105  bool skipp(size_t len) const;
106 
107  const u8* data(void) const;
108  size_t size(void) const;
109 
110  void putBE64(u64) override;
111  void putLE64(u64) override;
112  void putBE32(u32) override;
113  void putLE32(u32) override;
114  void putBE16(u16) override;
115  void putLE16(u16) override;
116 
117  void put(const char*, size_t) override;
118  void put8(char) override;
119  };
120 
121  class StreamBuf : public StreamBufRW
122  {
123  public:
124  StreamBuf() {}
125  StreamBuf(const BinaryBuf & bb) : StreamBufRW(bb) {}
126  StreamBuf(const u8* data, size_t size) : StreamBufRW(data, size) {}
127  };
128 
129  class ZStreamBuf : public StreamBuf
130  {
131  public:
132  bool read(const std::string &, size_t offset = 0);
133  bool write(const std::string &, bool append = false) const;
134  };
135 
136 } // SWE
137 #endif
пространство SWE.
Definition: swe_binarybuf.cpp:30
Definition: swe_streambuf.h:32
Definition: swe_serialize.h:225
Definition: swe_streambuf.h:129
класс бинарного массива
Definition: swe_binarybuf.h:35
Definition: swe_streambuf.h:78
Definition: swe_streambuf.h:121
Definition: swe_serialize.h:44