mFrame
載入中...
搜尋中...
無符合項目
ByteBuffer.h
1
8#ifndef MFRAME_C76BAF3F_EE1F_46A3_A050_9CD1057055E5
9#define MFRAME_C76BAF3F_EE1F_46A3_A050_9CD1057055E5
10
11/* ***************************************************************************************
12 * Include
13 */
14
15//----------------------------------------------------------------------------------------
16
17//----------------------------------------------------------------------------------------
18#include "./../io/Buffer.h"
19#include "./../lang/Memory.h"
20#include "./../lang/Strings.h"
21
22/* ***************************************************************************************
23 * Namespace
24 */
25namespace mframe::io {
26 class ByteBuffer;
27} // namespace mframe::io
28
29/* ***************************************************************************************
30 * Class/Interface/Struct
31 */
35 public mframe::io::Buffer {
36 /* *************************************************************************************
37 * Variable
38 */
39 protected:
41 int vPosition;
42 int vMark;
43 int vLimit;
44 bool vUnlock;
45 /* *************************************************************************************
46 * Abstract Method
47 */
48
49 /* *************************************************************************************
50 * Construct Method
51 */
52 public:
59
65 ByteBuffer(int length);
66
71 virtual ~ByteBuffer(void) override;
72
73 /* *************************************************************************************
74 * Operator Method
75 */
76 public:
83 inline ByteBuffer& operator<<(char c) {
84 this->putByte(c);
85 return *this;
86 }
87
94 inline ByteBuffer& operator<<(short s) {
95 this->putShort(s);
96 return *this;
97 }
98
105 inline ByteBuffer& operator<<(int v) {
106 this->putInt(v);
107 return *this;
108 }
109
116 inline ByteBuffer& operator<<(const char* string) {
117 this->put(string);
118 return *this;
119 }
120
128 this->put(string);
129 return *this;
130 }
131
138 inline int operator=(int v) {
139 this->position(v);
140 return this->position();
141 }
142
148 inline void operator+=(int shift) {
149 this->position(this->position() + shift);
150 }
151
157 inline void operator-=(int shift) {
158 this->position(this->position() - shift);
159 }
160
166 inline uint32 operator++(void) {
167 this->position(this->position() + 1);
168 return static_cast<uint32>(this->position());
169 }
170
176 inline uint32 operator--(void) {
177 this->position(this->position() - 1);
178 return static_cast<uint32>(this->position());
179 }
180
186 inline uint32 operator++(int) {
187 uint32 result = static_cast<uint32>(this->position());
188 this->position(this->position() + 1);
189 return result;
190 }
191
197 inline uint32 operator--(int) {
198 uint32 result = static_cast<uint32>(this->position());
199 this->position(this->position() - 1);
200 return result;
201 }
202
203 /* *************************************************************************************
204 * Public Method <Override> - mframe::lang::Flushable
205 */
206 public:
207 virtual void flush(void) override;
208
209 /* *************************************************************************************
210 * Public Method <Override> - mframe::io::Buffer
211 */
212 public:
213 virtual mframe::lang::Readable& getReadable(void) override;
214
215 virtual mframe::lang::Appendable& getAppendable(void) override;
216
217 /* *************************************************************************************
218 * Public Method <Override> - mframe::lang::Readable
219 */
220 public:
221 virtual inline int avariable(void) const override {
222 return (this->vLimit - this->vPosition);
223 }
224
225 virtual int pollByte(char& result) override;
226
227 virtual int poll(mframe::lang::Appendable& appendable) override;
228
229 virtual int poll(void* pointer, int length) override;
230
231 virtual int skip(int length) override;
232
233 virtual void lock(bool enable) override;
234
235 /* *************************************************************************************
236 * Public Method <Override> - mframe::lang::Appendable
237 */
238 public:
239 virtual int remaining(void) const override;
240
241 virtual int putByte(const char result) override;
242
243 virtual int put(mframe::lang::Readable& readBuffer) override;
244
245 virtual int put(const void* buffer, int bufferSize) override;
246
247 /* *************************************************************************************
248 * Public Method
249 */
250 public:
256 inline int limit(void) const {
257 return this->vLimit;
258 }
259
265 inline int capacity(void) const {
266 return this->vMemory.length();
267 }
268
274 inline int position(void) const {
275 return this->vPosition;
276 }
277
283 inline ByteBuffer& reset(void) {
284 this->position(this->vMark);
285 return *this;
286 }
287
293 inline ByteBuffer& mark(void) {
294 this->vMark = vPosition;
295 return *this;
296 }
297
303 inline ByteBuffer& rewind(void) {
304 this->vPosition = 0;
305 this->vMark = 0;
306 return *this;
307 }
308
316 inline bool pollByte(uint8& result) {
317 return this->pollByte(reinterpret_cast<char&>(result));
318 }
319
327 inline bool pollShort(uint16& result) {
328 return this->pollShort(reinterpret_cast<short&>(result));
329 }
330
338 inline bool pollInt(uint32& result) {
339 return this->pollInt(reinterpret_cast<int&>(result));
340 }
341
348 return this->vMemory;
349 }
350
358 bool limit(int newLimit);
359
367 bool position(int newPosition);
368
373 void flip(void);
374
380 void move(int position);
381
389 bool put(const char* string);
390
398 bool put(const mframe::lang::Strings& string);
399
407 int putFormat(const char* format, ...);
408
416 int putFormat(const char* format, va_list args);
417
425 bool putShort(const short value);
426
434 bool putInt(const int value);
435
443 bool putFloat(const float value);
444
452 bool pollShort(short& result);
453
461 bool pollInt(int& result);
462
470 bool pollFloat(float& result);
471
472 /* *************************************************************************************
473 * Protected Method
474 */
475
476 /* *************************************************************************************
477 * Private Method
478 */
479
480 /* *************************************************************************************
481 * Static Variable
482 */
483
484 /* *************************************************************************************
485 * Static Method
486 */
487};
488
489/* ***************************************************************************************
490 * End of file
491 */
492
493#endif /* MFRAME_C76BAF3F_EE1F_46A3_A050_9CD1057055E5 */
Definition ByteBuffer.h:35
ByteBuffer & operator<<(short s)
Definition ByteBuffer.h:94
bool put(const mframe::lang::Strings &string)
virtual int avariable(void) const override
取得輸出緩存內剩餘多少位元組
Definition ByteBuffer.h:221
bool limit(int newLimit)
uint32 operator--(void)
Definition ByteBuffer.h:176
uint32 operator--(int)
Definition ByteBuffer.h:197
ByteBuffer & operator<<(mframe::lang::Strings &string)
Definition ByteBuffer.h:127
int capacity(void) const
Definition ByteBuffer.h:265
ByteBuffer & rewind(void)
Definition ByteBuffer.h:303
bool putInt(const int value)
ByteBuffer & operator<<(int v)
Definition ByteBuffer.h:105
mframe::lang::Memory & memory(void)
Definition ByteBuffer.h:347
virtual int put(mframe::lang::Readable &readBuffer) override
將readable內資料輸入至緩衝區。
int limit(void) const
Definition ByteBuffer.h:256
bool putFloat(const float value)
ByteBuffer(int length)
Construct a new Byte Buffer object.
int putFormat(const char *format,...)
virtual int poll(mframe::lang::Appendable &appendable) override
檢索至Appendable指定數量字節,並由此緩衝區刪除
bool pollInt(uint32 &result)
Get the Int object.
Definition ByteBuffer.h:338
bool position(int newPosition)
bool putShort(const short value)
int position(void) const
Definition ByteBuffer.h:274
void operator-=(int shift)
Definition ByteBuffer.h:157
uint32 operator++(void)
Definition ByteBuffer.h:166
bool pollByte(uint8 &result)
Get the Byte object.
Definition ByteBuffer.h:316
void move(int position)
bool pollFloat(float &result)
Get the Float object.
virtual void lock(bool enable) override
鎖定緩存,取出不移除。
bool pollInt(int &result)
Get the Int object.
ByteBuffer & mark(void)
Definition ByteBuffer.h:293
int putFormat(const char *format, va_list args)
virtual int pollByte(char &result) override
檢索一個字節,並由此緩衝區刪除
virtual int putByte(const char result) override
將字節輸入至緩衝區。
virtual void flush(void) override
void operator+=(int shift)
Definition ByteBuffer.h:148
ByteBuffer & operator<<(char c)
Definition ByteBuffer.h:83
ByteBuffer(const mframe::lang::Memory &memory)
Construct a new Byte Buffer object.
virtual ~ByteBuffer(void) override
Destroy the Byte Buffer object.
bool put(const char *string)
virtual int remaining(void) const override
取得緩衝區剩餘空閒字節數。
virtual int put(const void *buffer, int bufferSize) override
將指針內資料輸入至緩衝區。
uint32 operator++(int)
Definition ByteBuffer.h:186
ByteBuffer & reset(void)
Definition ByteBuffer.h:283
ByteBuffer & operator<<(const char *string)
Definition ByteBuffer.h:116
bool pollShort(uint16 &result)
Get the Short object.
Definition ByteBuffer.h:327
int operator=(int v)
Definition ByteBuffer.h:138
virtual int poll(void *pointer, int length) override
檢索至pointer指定數量字節,並由此緩衝區刪除
bool pollShort(short &result)
Get the Short object.
virtual int skip(int length) override
跳躍指定的字結數量,並由此緩衝區刪除。
int length(void) const
Definition Data.h:126
Definition Memory.h:29
Definition Object.h:34
Definition Strings.h:29
Definition AppendableOutputStream.h:24
Definition Buffer.h:31
可附加的 <Interface>
Definition Appendable.h:36
Definition Readable.h:31