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