rogue
Loading...
Searching...
No Matches
FrameAccessor.h
Go to the documentation of this file.
1
17#ifndef __ROGUE_INTERFACES_STREAM_FRAME_ACCESSOR_H__
18#define __ROGUE_INTERFACES_STREAM_FRAME_ACCESSOR_H__
19#include "rogue/Directives.h"
20
21#include <inttypes.h>
22#include <stdint.h>
23
24#include <memory>
25
26#include "rogue/GeneralError.h"
28
29namespace rogue {
30namespace interfaces {
31namespace stream {
32
42template <typename T>
44 private:
45 // Data container
46 T* data_;
47
48 // Size value
49 uint32_t size_;
50
51 public:
60 data_ = reinterpret_cast<T*>(iter.ptr());
61 size_ = size;
62
63 if (size * sizeof(T) > iter.remBuffer())
64 throw rogue::GeneralError::create("FrameAccessor",
65 "Attempt to create a FrameAccessor over a multi-buffer range!");
66 }
67
77 T& operator[](const uint32_t offset) {
78 return data_[offset];
79 }
80
88 T& at(const uint32_t offset) {
89 if (offset >= size_)
90 throw rogue::GeneralError::create("FrameAccessor",
91 "Attempt to access element %" PRIu32 " with size %" PRIu32,
92 offset,
93 size_);
94
95 return data_[offset];
96 }
97
99 uint32_t size() {
100 return size_;
101 }
102
104 T* begin() {
105 return data_;
106 }
107
109 T* end() {
110 return data_ + size_;
111 }
112};
113} // namespace stream
114} // namespace interfaces
115} // namespace rogue
116
117#endif
static GeneralError create(std::string src, const char *fmt,...)
Creates a formatted error instance.
Typed accessor over a contiguous frame-data region.
uint32_t size()
Returns number of elements in this accessor.
T * begin()
Returns pointer to first element.
FrameAccessor(rogue::interfaces::stream::FrameIterator &iter, uint32_t size)
Creates a typed accessor at the iterator location.
T & operator[](const uint32_t offset)
Dereference by index.
T & at(const uint32_t offset)
Returns element reference at offset with bounds checking.
T * end()
Returns pointer one-past-last element.
Random-access byte iterator across a Frame payload.
uint8_t * ptr() const
Returns pointer to byte at current iterator position.
uint32_t remBuffer()
Returns remaining bytes in the current buffer span.