TDME2  1.9.200
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 {
15 public:
16  /**
17  * Default constructor
18  */
19  IntBuffer() : Buffer() {
20  }
21 
22  /**
23  * Public constructor
24  */
25  inline IntBuffer(Buffer* buffer) : Buffer() {
26  this->ownsBuffer = false;
27  this->buffer = buffer->buffer;
28  }
29 
30  /**
31  * @return capacity
32  */
33  inline virtual int64_t getCapacity() {
34  return Buffer::getCapacity() / sizeof(uint32_t);
35  }
36 
37  /**
38  * @return position
39  */
40  inline virtual int64_t getPosition() {
41  return Buffer::getPosition() / sizeof(uint32_t);
42  }
43 
44  /**
45  * Get a value at given position
46  * @param position position
47  */
48  inline uint32_t get(int64_t position) {
49  uint32_t value = 0;
50  value+= ((uint32_t)Buffer::get(position)) & 0xFF;
51  value+= ((uint32_t)Buffer::get(position + 1) << 8) & 0xFF;
52  value+= ((uint32_t)Buffer::get(position + 2) << 16) & 0xFF;
53  value+= ((uint32_t)Buffer::get(position + 3) << 24) & 0xFF;
54  return value;
55  }
56 
57  /**
58  * Puts a value into buffer at its current position
59  * @param value value
60  */
61  inline IntBuffer* put(uint32_t value) {
62  Buffer::put((const uint8_t*)&value, sizeof(uint32_t));
63  return this;
64  }
65 
66 };
Base class of buffers.
Definition: Buffer.h:21
uint8_t get(int64_t position) const
Definition: Buffer.h:107
vector< uint8_t > * buffer
Definition: Buffer.h:30
Buffer * put(uint8_t value)
Put value into buffer.
Definition: Buffer.h:115
virtual int64_t getCapacity() const
Definition: Buffer.h:82
virtual int64_t getPosition() const
Definition: Buffer.h:89
Integer buffer class.
Definition: IntBuffer.h:14
IntBuffer()
Default constructor.
Definition: IntBuffer.h:19
virtual int64_t getCapacity()
Definition: IntBuffer.h:33
IntBuffer(Buffer *buffer)
Public constructor.
Definition: IntBuffer.h:25
virtual int64_t getPosition()
Definition: IntBuffer.h:40
IntBuffer * put(uint32_t value)
Puts a value into buffer at its current position.
Definition: IntBuffer.h:61
uint32_t get(int64_t position)
Get a value at given position.
Definition: IntBuffer.h:48