Control Surface main
MIDI Control Surface library for Arduino
BufferPuller.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <AH/STL/vector> // std::vector
4#include <Settings/NamespaceSettings.hpp>
5
7
12template <class T = uint8_t>
14 public:
15 BufferPuller_(const T *buffer, size_t length)
16 : buffer(buffer), end(buffer + length) {}
17
22 bool pull(T &output) {
23 if (buffer != end) {
24 output = *buffer++;
25 return true;
26 }
27 return false;
28 }
29
30 private:
31 const T *buffer;
32 const T *const end;
33};
34
35template <class T>
36BufferPuller_<T> BufferPuller(const T *buffer, size_t length) {
37 return {buffer, length};
38}
39template <class T>
40BufferPuller_<T> BufferPuller(const std::vector<T> &buffer) {
41 return {buffer.data(), buffer.size()};
42}
43template <class T, size_t N>
44BufferPuller_<T> BufferPuller(const T (&buffer)[N]) {
45 return {buffer, N};
46}
47
BufferPuller_< T > BufferPuller(const T *buffer, size_t length)
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Helper to pull bytes or other objects out of a buffer.
BufferPuller_(const T *buffer, size_t length)
const T *const end
bool pull(T &output)
Pull a value out of the buffer.
const T * buffer