Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CanBuffer
- {
- public:
- enum { MAX_SIZE = 8 };
- CanBuffer(): _size(0) {}
- CanBuffer(uint8_t initial_size) { resize(initial_size); }
- CanBuffer(const CanBuffer& rhs) = default;
- CanBuffer& operator=(const CanBuffer& rhs) = default;
- void resize(uint8_t new_size)
- {
- if( new_size >= MAX_SIZE ){
- throw std::runtime_error("CanBuffer size exceeded");
- }
- _size = new_size;
- }
- void push_back(uint8_t value)
- {
- if( _size >= 8){
- throw std::runtime_error("CanBuffer size exceeded");
- }
- _buffer[_size++] = value;
- }
- uint8_t size() const { return _size; }
- uint8_t& operator[](size_t index) { return _buffer[index]; }
- uint8_t operator[](size_t index) const { return _buffer[index]; }
- uint8_t& at(size_t index) { return _buffer.at(index); }
- uint8_t at(size_t index) const { return _buffer.at(index); }
- uint8_t* data() { return _buffer.data(); }
- const uint8_t* data() const { return _buffer.data(); }
- protected:
- std::array<uint8_t, 8> _buffer;
- uint8_t _size;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement