rogue
Loading...
Searching...
No Matches
FrameIterator.h
Go to the documentation of this file.
1
17#ifndef __ROGUE_INTERFACES_STREAM_FRAME_ITERATOR_H__
18#define __ROGUE_INTERFACES_STREAM_FRAME_ITERATOR_H__
19#include "rogue/Directives.h"
20
21#include <stdint.h>
22
23#include <cstring>
24#include <memory>
25#include <vector>
26
27namespace rogue {
28namespace interfaces {
29namespace stream {
30
31class Frame;
32class Buffer;
33
45class FrameIterator : public std::iterator<std::random_access_iterator_tag, uint8_t> {
46 friend class Frame;
47
48 private:
49 // Creator
50 FrameIterator(std::shared_ptr<rogue::interfaces::stream::Frame> frame, bool write, bool end);
51
52 // write flag
53 bool write_;
54
55 // Associated frame
56 std::shared_ptr<rogue::interfaces::stream::Frame> frame_;
57
58 // Frame position
59 int32_t framePos_;
60
61 // Frame size
62 int32_t frameSize_;
63
64 // current buffer
65 std::vector<std::shared_ptr<rogue::interfaces::stream::Buffer> >::iterator buff_;
66
67 // Buffer position
68 int32_t buffBeg_;
69
70 // Buffer size
71 int32_t buffEnd_;
72
73 // Current buffer iterator
74 uint8_t* data_;
75
76 // increment position
77 inline void increment(int32_t diff);
78
79 // decrement position
80 inline void decrement(int32_t diff);
81
82 public:
85
93
108
118 uint32_t remBuffer();
119
129 uint8_t& operator*() const;
130
131 // uint8_t * operator ->() const;
132
137 uint8_t* ptr() const;
138
145 uint8_t operator[](const uint32_t offset) const;
146
157
169
180
192
204
216
228
240
252
264
275
286
297 int32_t operator-(const rogue::interfaces::stream::FrameIterator& other) const;
298
309
320};
321
337static inline void toFrame(rogue::interfaces::stream::FrameIterator& iter, uint32_t size, void* src) {
338 uint8_t* ptr = reinterpret_cast<uint8_t*>(src);
339 uint32_t csize;
340
341 do {
342 csize = (size > iter.remBuffer()) ? iter.remBuffer() : size;
343 std::memcpy(iter.ptr(), ptr, csize);
344 ptr += csize;
345 iter += csize;
346 size -= csize;
347 } while (size > 0 && csize > 0);
348}
349
365static inline void fromFrame(rogue::interfaces::stream::FrameIterator& iter, uint32_t size, void* dst) {
366 uint8_t* ptr = reinterpret_cast<uint8_t*>(dst);
367 uint32_t csize;
368
369 do {
370 csize = (size > iter.remBuffer()) ? iter.remBuffer() : size;
371 std::memcpy(ptr, iter.ptr(), csize);
372 ptr += csize;
373 iter += csize;
374 size -= csize;
375 } while (size > 0 && csize > 0);
376}
377
394 uint32_t size,
396 uint32_t csize;
397
398 do {
399 csize = (size > srcIter.remBuffer()) ? srcIter.remBuffer() : size;
400 csize = (csize > dstIter.remBuffer()) ? dstIter.remBuffer() : csize;
401 std::memcpy(dstIter.ptr(), srcIter.ptr(), csize);
402 srcIter += csize;
403 dstIter += csize;
404 size -= csize;
405 } while (size > 0 && csize > 0);
406}
407} // namespace stream
408} // namespace interfaces
409} // namespace rogue
410
411#endif
Random-access byte iterator across a Frame payload.
rogue::interfaces::stream::FrameIterator operator+(const int32_t add) const
Returns a new iterator offset forward by add.
rogue::interfaces::stream::FrameIterator & operator+=(const int32_t add)
In-place increments iterator by add.
uint8_t * ptr() const
Returns pointer to byte at current iterator position.
bool operator<(const rogue::interfaces::stream::FrameIterator &other) const
Returns whether this iterator is before another iterator.
uint8_t operator[](const uint32_t offset) const
Returns byte value at relative offset from current position.
bool operator!=(const rogue::interfaces::stream::FrameIterator &other) const
Compares two iterators for inequality.
bool operator>(const rogue::interfaces::stream::FrameIterator &other) const
Returns whether this iterator is after another iterator.
rogue::interfaces::stream::FrameIterator endBuffer()
Returns iterator marking the end of the current buffer segment.
uint8_t & operator*() const
Dereferences iterator to current byte.
const rogue::interfaces::stream::FrameIterator operator=(const rogue::interfaces::stream::FrameIterator &rhs)
Copy-assigns iterator state.
bool operator<=(const rogue::interfaces::stream::FrameIterator &other) const
Returns whether this iterator is before or equal to another iterator.
bool operator==(const rogue::interfaces::stream::FrameIterator &other) const
Compares two iterators for equality.
const rogue::interfaces::stream::FrameIterator & operator--()
Prefix-decrements iterator by one byte.
bool operator>=(const rogue::interfaces::stream::FrameIterator &other) const
Returns whether this iterator is after or equal to another iterator.
FrameIterator()
Constructs an empty iterator for later assignment.
rogue::interfaces::stream::FrameIterator & operator-=(const int32_t sub)
In-place decrements iterator by sub.
const rogue::interfaces::stream::FrameIterator & operator++()
Prefix-increments iterator by one byte.
rogue::interfaces::stream::FrameIterator operator-(const int32_t sub) const
Returns a new iterator offset backward by sub.
uint32_t remBuffer()
Returns remaining bytes in the current buffer span.
Container for one stream frame payload and metadata.
Definition Frame.h:56
static void fromFrame(rogue::interfaces::stream::FrameIterator &iter, uint32_t size, void *dst)
Copies bytes from a frame iterator to a destination pointer.
static void copyFrame(rogue::interfaces::stream::FrameIterator &srcIter, uint32_t size, rogue::interfaces::stream::FrameIterator &dstIter)
Copies bytes between frame iterators.
static void toFrame(rogue::interfaces::stream::FrameIterator &iter, uint32_t size, void *src)
Copies bytes from a source pointer into a frame iterator.