streamable.h
867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef ION_DEVICE_USB_STREAMABLE_H
#define ION_DEVICE_USB_STREAMABLE_H
#include <stdint.h>
#include <stddef.h>
namespace Ion {
namespace USB {
namespace Device {
class Streamable {
public:
uint16_t copy(void * target, size_t maxSize) const;
protected:
class Channel {
public:
Channel(void * pointer, size_t maxSize) :
m_pointer(pointer),
m_sizeLeft(maxSize)
{
}
template<typename T>
void push(T data) {
if (m_sizeLeft >= sizeof(T)) {
T * typedPointer = static_cast<T *>(m_pointer);
*typedPointer++ = data; // Actually push the data
m_pointer = static_cast<void *>(typedPointer);
m_sizeLeft -= sizeof(T);
}
}
size_t sizeLeft() { return m_sizeLeft; }
private:
void * m_pointer;
size_t m_sizeLeft;
};
virtual void push(Channel * c) const = 0;
};
}
}
}
#endif