VOX
A little voxel engine
Loading...
Searching...
No Matches
RLE_TEST.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4
5template <typename T>
7{
8public:
9 typedef std::pair<T, uint16_t> RLEPair;
10
12 {
13
14 };
15
16 static size_t sizeOfPair()
17 {
18 return sizeof(RLEPair);
19 }
20
21 void compressData(const T * data, const size_t & size)
22 {
23 m_data.clear();
24 m_data.push_back(std::make_pair(data[0], 1));
25 for(size_t i = 1; i < size; ++i)
26 {
27 if(data[i] == m_data.back().first && m_data.back().second < std::numeric_limits<uint16_t>::max())
28 m_data.back().second++;
29 else
30 m_data.push_back(std::make_pair(data[i], 1));
31 }
32 }
33
34 void setContent(const void * data, const size_t & size)
35 {
36 m_data.clear();
37 m_data.insert(m_data.begin(), (RLEPair*)data, (RLEPair*)data + size / sizeof(RLEPair));
38 }
39
40 std::vector<T> getData() const
41 {
42 std::vector<T> ret;
43 for (auto [value, count] : m_data)
44 {
45 for(size_t j = 0; j < count; ++j)
46 ret.push_back(value);
47 }
48
49 return ret;
50 }
51
52 void resize(size_t new_raw_size)
53 {
54 m_data.resize(new_raw_size / sizeof(RLEPair));
55 }
56
57 std::size_t getSize() const
58 {
59 return m_data.size();
60 }
61
67 std::size_t getRawSize() const
68 {
69 return m_data.size() * sizeof(RLEPair);
70 }
71
72 const std::vector<RLEPair> & getRaw() const
73 {
74 return m_data;
75 }
76
77 std::vector<RLEPair> & getRaw()
78 {
79 return m_data;
80 }
81private:
82 std::vector<RLEPair> m_data;
83};
Definition: RLE_TEST.hpp:7
void resize(size_t new_raw_size)
Definition: RLE_TEST.hpp:52
std::pair< T, uint16_t > RLEPair
Definition: RLE_TEST.hpp:9
std::vector< RLEPair > & getRaw()
Definition: RLE_TEST.hpp:77
void compressData(const T *data, const size_t &size)
Definition: RLE_TEST.hpp:21
std::size_t getRawSize() const
Get the size in bytes of the underlying compressed data.
Definition: RLE_TEST.hpp:67
RLE_TEST()
Definition: RLE_TEST.hpp:11
std::size_t getSize() const
Definition: RLE_TEST.hpp:57
const std::vector< RLEPair > & getRaw() const
Definition: RLE_TEST.hpp:72
static size_t sizeOfPair()
Definition: RLE_TEST.hpp:16
std::vector< T > getData() const
Definition: RLE_TEST.hpp:40
void setContent(const void *data, const size_t &size)
Definition: RLE_TEST.hpp:34