TDME2 1.9.121
FloatBuffer.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4
5#include <tdme/tdme.h>
8
9using std::array;
10
12
13/**
14 * Float buffer class
15 * @author Andreas Drewke
16 */
18{
19public:
20 /**
21 * @return capacity
22 */
23 inline virtual int32_t getCapacity() {
24 return Buffer::getCapacity() / sizeof(float);
25 }
26
27 /**
28 * @return position
29 */
30 inline virtual int32_t getPosition() {
31 return Buffer::getPosition() / sizeof(float);
32 }
33
34 /**
35 * Get a value at given position
36 * @param position position
37 * @return value at given position
38 */
39 inline float get(int32_t position) {
40 int32_t floatAsInt = 0;
41 floatAsInt+= (int32_t)Buffer::get(position);
42 floatAsInt+= (int32_t)Buffer::get(position + 1) << 8;
43 floatAsInt+= (int32_t)Buffer::get(position + 2) << 16;
44 floatAsInt+= (int32_t)Buffer::get(position + 3) << 24;
45 return *((float*)&floatAsInt);
46 }
47
48 /**
49 * Put a float value into float buffer
50 * @param value value
51 */
52 inline FloatBuffer* put(float value) {
53 Buffer::put((const uint8_t*)&value, sizeof(float));
54 return this;
55 }
56
57 /**
58 * Put float values into float buffer
59 * @param values values
60 */
61 inline FloatBuffer* put(const array<float, 2>& values) {
62 Buffer::put((const uint8_t*)values.data(), 2 * sizeof(float));
63 return this;
64 }
65
66 /**
67 * Put float values into float buffer
68 * @param values values
69 */
70 inline FloatBuffer* put(const array<float, 3>& values) {
71 Buffer::put((const uint8_t*)values.data(), 3 * sizeof(float));
72 return this;
73 }
74
75 /**
76 * Put float values into float buffer
77 * @param values values
78 */
79 inline FloatBuffer* put(const array<float, 4>& values) {
80 Buffer::put((const uint8_t*)values.data(), 4 * sizeof(float));
81 return this;
82 }
83
84 /**
85 * Put float values into float buffer
86 * @param values values
87 */
88 inline FloatBuffer* put(const array<float, 16>& values) {
89 Buffer::put((const uint8_t*)values.data(), 16 * sizeof(float));
90 return this;
91 }
92
93public:
94 /**
95 * Default constructor
96 */
97 FloatBuffer() : Buffer(static_cast<Buffer*>(nullptr)) {
98 }
99
100 /**
101 * Public constructor
102 * @param buffer buffer
103 */
105 }
106
107};
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
Float buffer class.
Definition: FloatBuffer.h:18
virtual int32_t getPosition()
Definition: FloatBuffer.h:30
FloatBuffer * put(float value)
Put a float value into float buffer.
Definition: FloatBuffer.h:52
FloatBuffer * put(const array< float, 3 > &values)
Put float values into float buffer.
Definition: FloatBuffer.h:70
virtual int32_t getCapacity()
Definition: FloatBuffer.h:23
FloatBuffer * put(const array< float, 4 > &values)
Put float values into float buffer.
Definition: FloatBuffer.h:79
FloatBuffer * put(const array< float, 16 > &values)
Put float values into float buffer.
Definition: FloatBuffer.h:88
FloatBuffer * put(const array< float, 2 > &values)
Put float values into float buffer.
Definition: FloatBuffer.h:61
FloatBuffer()
Default constructor.
Definition: FloatBuffer.h:97
FloatBuffer(Buffer *buffer)
Public constructor.
Definition: FloatBuffer.h:104
float get(int32_t position)
Get a value at given position.
Definition: FloatBuffer.h:39