remove unused code

This commit is contained in:
Andrew Morris
2024-10-11 13:38:01 +11:00
parent 5130f5196f
commit 04afaa6bc9
2 changed files with 0 additions and 136 deletions

View File

@@ -1,78 +0,0 @@
#include "Buffer.hpp"
#include <cstring> // For memcpy
// Constructor takes ownership of the allocated data
Buffer::Buffer(uint8_t* data, int length) : data(data), length(length) {}
// Destructor frees the allocated memory
Buffer::~Buffer() {
free(data);
}
// Move constructor transfers ownership of resources
Buffer::Buffer(Buffer&& other) noexcept : data(other.data), length(other.length) {
other.data = nullptr;
other.length = 0;
}
// Subscript operators for accessing elements
uint8_t& Buffer::operator[](int index) {
return data[index];
}
const uint8_t& Buffer::operator[](int index) const {
return data[index];
}
// Begin and end iterators for range-based loops and STL compatibility
uint8_t* Buffer::begin() { return data; }
uint8_t* Buffer::end() { return data + length; }
const uint8_t* Buffer::begin() const { return data; }
const uint8_t* Buffer::end() const { return data + length; }
// Getters for data and length
uint8_t* Buffer::getData() { return data; }
const uint8_t* Buffer::getData() const { return data; }
int Buffer::getLength() const { return length; }
// Size method to return the number of elements
int Buffer::size() const { return length; }
// Empty method to check if the buffer is empty
bool Buffer::empty() const { return length == 0; }
// Front method to access the first element
uint8_t& Buffer::front() {
if (empty()) throw std::out_of_range("Buffer is empty");
return data[0];
}
const uint8_t& Buffer::front() const {
if (empty()) throw std::out_of_range("Buffer is empty");
return data[0];
}
// Back method to access the last element
uint8_t& Buffer::back() {
if (empty()) throw std::out_of_range("Buffer is empty");
return data[length - 1];
}
const uint8_t& Buffer::back() const {
if (empty()) throw std::out_of_range("Buffer is empty");
return data[length - 1];
}
// Method to create an explicit copy of the buffer
Buffer Buffer::copy() const {
// Allocate new memory and copy the data
uint8_t* newData = static_cast<uint8_t*>(malloc(length));
if (!newData) {
throw std::bad_alloc();
}
std::memcpy(newData, data, length);
// Return a new Buffer instance with the copied data
return Buffer(newData, length);
}

View File

@@ -1,58 +0,0 @@
#ifndef BUFFER_HPP
#define BUFFER_HPP
#include <cstdint>
#include <cstdlib>
#include <stdexcept>
class Buffer {
public:
// Constructor takes ownership of the allocated data
Buffer(uint8_t* data, int length);
// Destructor
~Buffer();
// Move constructor
Buffer(Buffer&& other) noexcept;
// Deleted copy constructor and assignment operator to prevent copying
Buffer(const Buffer& other) = delete;
Buffer& operator=(const Buffer& other) = delete;
// Subscript operators for accessing elements
uint8_t& operator[](int index);
const uint8_t& operator[](int index) const;
// Begin and end iterators for range-based loops and STL compatibility
uint8_t* begin();
uint8_t* end();
const uint8_t* begin() const;
const uint8_t* end() const;
// Getters for data and length
uint8_t* getData();
const uint8_t* getData() const;
int getLength() const;
// Size method to return the number of elements
int size() const;
// Empty method to check if the buffer is empty
bool empty() const;
// Front and back methods to access the first and last elements
uint8_t& front();
const uint8_t& front() const;
uint8_t& back();
const uint8_t& back() const;
// Method to create an explicit copy of the buffer
Buffer copy() const;
private:
uint8_t* data;
int length;
};
#endif // BUFFER_HPP