TDME2 1.9.121
IntBuffer.h
Go to the documentation of this file.
1#pragma once
2
3#include <tdme/tdme.h>
6
8
9/**
10 * Integer buffer class
11 * @author Andreas Drewke
12 */
14{
15public:
16 /**
17 * Default constructor
18 */
19 IntBuffer() : Buffer(static_cast<Buffer*>(nullptr)) {
20 }
21
22 /**
23 * Public constructor
24 */
26 }
27
28 /**
29 * @return capacity
30 */
31 inline virtual int32_t getCapacity() {
32 return Buffer::getCapacity() / sizeof(int32_t);
33 }
34
35 /**
36 * @return position
37 */
38 inline virtual int32_t getPosition() {
39 return Buffer::getPosition() / sizeof(int32_t);
40 }
41
42 /**
43 * Get a value at given position
44 * @param position position
45 */
46 inline int32_t get(int32_t position) {
47 int32_t value = 0;
48 value+= ((int32_t)Buffer::get(position)) & 0xFF;
49 value+= ((int32_t)Buffer::get(position + 1) << 8) & 0xFF;
50 value+= ((int32_t)Buffer::get(position + 2) << 16) & 0xFF;
51 value+= ((int32_t)Buffer::get(position + 3) << 24) & 0xFF;
52 return value;
53 }
54
55 /**
56 * Puts a value into buffer at its current position
57 * @param value value
58 */
59 inline IntBuffer* put(int32_t value) {
60 Buffer::put((const uint8_t*)&value, sizeof(int32_t));
61 return this;
62 }
63
64};
Base class of buffers.
Definition: Buffer.h:20
Buffer * put(uint8_t value)
Put value into buffer.
Definition: Buffer.h:110
uint8_t get(int32_t position)
Definition: Buffer.h:102
virtual int32_t getPosition()
Definition: Buffer.h:84
vector< uint8_t > * buffer
Definition: Buffer.h:24
virtual int32_t getCapacity()
Definition: Buffer.h:77
Integer buffer class.
Definition: IntBuffer.h:14
IntBuffer()
Default constructor.
Definition: IntBuffer.h:19
IntBuffer * put(int32_t value)
Puts a value into buffer at its current position.
Definition: IntBuffer.h:59
IntBuffer(Buffer *buffer)
Public constructor.
Definition: IntBuffer.h:25
virtual int32_t getPosition()
Definition: IntBuffer.h:38
virtual int32_t getCapacity()
Definition: IntBuffer.h:31
int32_t get(int32_t position)
Get a value at given position.
Definition: IntBuffer.h:46