diff --git a/src/net/ioqueue.cpp b/src/net/ioqueue.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f01262f42986da1ae6dbde7124e98f436e7fa5fa --- /dev/null +++ b/src/net/ioqueue.cpp @@ -0,0 +1,79 @@ +#include "net/ioqueue.hpp" + +namespace rmrf::net { + +iorecord::iorecord() : offset{}, data{} {} + +iorecord::iorecord(const void *buf, size_t size) : + offset{0}, data((const uint8_t *)buf, (const uint8_t *)buf + size) { + // Nothing special to do here ... +} +iorecord::iorecord(const iorecord &other) : offset{other.offset}, data{other.data} { + // NOP +} + +iorecord::iorecord(iorecord &&other) : + offset(other.offset), data(std::forward<std::vector<uint8_t>>(other.data)) { + // Nothing special to do here ... +} + +size_t iorecord::size() const { + return this->data.size() - this->offset; +} + +bool iorecord::empty() const { + return !this->size(); +} +void *iorecord::ptr() const { + return (void *)(this->data.data() + this->offset); +} + +void iorecord::advance(size_t amount) { + this->offset += std::min(amount, this->size()); +} + +ioqueue::ioqueue() : queue{} { + // NOP +} + +ioqueue::~ioqueue() { + // NOP +} + +bool ioqueue::empty() const { + return this->queue.empty(); +} + +void ioqueue::push_back(const iorecord &data) { + if (!data.empty()) { + this->queue.push_back(data); + } +} +void ioqueue::push_back(iorecord &&data) { + if (!data.empty()) { + this->queue.emplace_back(std::forward<iorecord>(data)); + } +} + +void ioqueue::push_front(const iorecord &data) { + if (!data.empty()) { + this->queue.push_front(data); + } +} +void ioqueue::push_front(iorecord &&data) { + if (!data.empty()) { + this->queue.emplace_front(std::forward<iorecord>(data)); + } +} + +iorecord ioqueue::pop_front() { + if (this->empty()) { + return iorecord{}; + } + + iorecord result = this->queue.front(); + this->queue.pop_front(); + return result; +} + +} // namespace rmrf::net diff --git a/src/net/ioqueue.hpp b/src/net/ioqueue.hpp index f93674176db7b6ee02b6869be0d51c8938fb0b99..b97ef9f58be8b317a6ff4d597ef60b8050c9d0f1 100644 --- a/src/net/ioqueue.hpp +++ b/src/net/ioqueue.hpp @@ -13,29 +13,17 @@ namespace rmrf::net { size_t offset; std::vector<uint8_t> data; public: - iorecord() : offset{}, data{} {} - iorecord(const void *buf, size_t size) : - offset{0}, data((const uint8_t *)buf, (const uint8_t *)buf + size) { - // Nothing special to do here ... - }; - iorecord(iorecord&& other) : - offset(other.offset), data(std::forward<iorecord>(other.data)) { - // Nothing special to do here ... - }; + iorecord(); + iorecord(const void *buf, size_t size); + iorecord(const iorecord &other); + iorecord(iorecord &&other); + public: - size_t size() const { - return this->data.size() - this->offset; - } - bool empty() const { - return !this->size(); - } - void *ptr() const { - return (void*)(this->data.data() + this->offset); - } + size_t size() const; + bool empty() const; + void *ptr() const; - void advance(size_t amount) { - this->offset += std::min(amount, this->size()); - } + void advance(size_t amount); }; class ioqueue { @@ -43,41 +31,18 @@ namespace rmrf::net { std::deque<iorecord> queue; public: - bool empty() const { - return this->queue.empty(); - } + ioqueue(); + ~ioqueue(); - void push_back(const iorecord& data) { - if(!data.empty()) { - this->queue.push_back(data); - } - } - void push_back(iorecord &&data) { - if (!data.empty()) { - this->queue.emplace_back(std::forward(data)); - } - } + bool empty() const; - void push_front(const iorecord &data) { - if (!data.empty()) { - this->queue.push_front(data); - } - } - void push_front(iorecord &&data) { - if (!data.empty()) { - this->queue.emplace_front(std::forward(data)); - } - } + void push_back(const iorecord& data); + void push_back(iorecord &&data); - iorecord pop_front() { - if(this->empty()) { - return iorecord{}; - } + void push_front(const iorecord &data); + void push_front(iorecord &&data); - iorecord result = this->queue.front(); - this->queue.pop_front(); - return result; - } + iorecord pop_front(); }; }