Skip to content
Snippets Groups Projects
Verified Commit 0e6994b2 authored by Benny Baumann's avatar Benny Baumann
Browse files

chg: Split ioqueue into header+impl

parent 01ba45c8
No related branches found
No related tags found
No related merge requests found
#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
...@@ -13,29 +13,17 @@ namespace rmrf::net { ...@@ -13,29 +13,17 @@ namespace rmrf::net {
size_t offset; size_t offset;
std::vector<uint8_t> data; std::vector<uint8_t> data;
public: public:
iorecord() : offset{}, data{} {} iorecord();
iorecord(const void *buf, size_t size) : iorecord(const void *buf, size_t size);
offset{0}, data((const uint8_t *)buf, (const uint8_t *)buf + size) { iorecord(const iorecord &other);
// Nothing special to do here ... iorecord(iorecord &&other);
};
iorecord(iorecord&& other) :
offset(other.offset), data(std::forward<iorecord>(other.data)) {
// Nothing special to do here ...
};
public: public:
size_t size() const { size_t size() const;
return this->data.size() - this->offset; bool empty() const;
} void *ptr() const;
bool empty() const {
return !this->size();
}
void *ptr() const {
return (void*)(this->data.data() + this->offset);
}
void advance(size_t amount) { void advance(size_t amount);
this->offset += std::min(amount, this->size());
}
}; };
class ioqueue { class ioqueue {
...@@ -43,41 +31,18 @@ namespace rmrf::net { ...@@ -43,41 +31,18 @@ namespace rmrf::net {
std::deque<iorecord> queue; std::deque<iorecord> queue;
public: public:
bool empty() const { ioqueue();
return this->queue.empty(); ~ioqueue();
}
void push_back(const iorecord& data) { bool empty() const;
if(!data.empty()) {
this->queue.push_back(data);
}
}
void push_back(iorecord &&data) {
if (!data.empty()) {
this->queue.emplace_back(std::forward(data));
}
}
void push_front(const iorecord &data) { void push_back(const iorecord& data);
if (!data.empty()) { void push_back(iorecord &&data);
this->queue.push_front(data);
}
}
void push_front(iorecord &&data) {
if (!data.empty()) {
this->queue.emplace_front(std::forward(data));
}
}
iorecord pop_front() { void push_front(const iorecord &data);
if(this->empty()) { void push_front(iorecord &&data);
return iorecord{};
}
iorecord result = this->queue.front(); iorecord pop_front();
this->queue.pop_front();
return result;
}
}; };
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment