Skip to content

Commit

Permalink
Feat: Inserting reverse iterators in buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
henriqueaklein committed Apr 4, 2024
1 parent abef1fd commit 72faf15
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/base/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ namespace sgns::base {
Buffer::iterator Buffer::end() {
return data_.end();
}
Buffer::reverse_iterator Buffer::rbegin() {
return data_.rbegin();
}

Buffer::reverse_iterator Buffer::rend() {
return data_.rend();
}

Buffer &Buffer::putUint8(uint8_t n) {
data_.push_back(n);
Expand Down Expand Up @@ -90,6 +97,13 @@ namespace sgns::base {
Buffer::const_iterator Buffer::end() const {
return data_.end();
}
Buffer::const_reverse_iterator Buffer::rbegin() const {
return data_.rbegin();
}

Buffer::const_reverse_iterator Buffer::rend() const {
return data_.rend();
}

const uint8_t *Buffer::data() const {
return data_.data();
Expand Down
22 changes: 22 additions & 0 deletions src/base/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace sgns::base {
public boost::equality_comparable<std::vector<uint8_t>> {
public:
using iterator = std::vector<uint8_t>::iterator;
using reverse_iterator = std::vector<uint8_t>::reverse_iterator;
using const_reverse_iterator = std::vector<uint8_t>::const_reverse_iterator;
using const_iterator = std::vector<uint8_t>::const_iterator;
using value_type = uint8_t;
// with this gsl::span can be built from Buffer
Expand Down Expand Up @@ -95,6 +97,26 @@ namespace sgns::base {
* buffer.
*/
iterator end();
/**
* @brief Iterator, which points to last of this buffer.
*/
reverse_iterator rbegin();

/**
* @brief Iterator, which points to the element previous to first in this
* buffer.
*/
reverse_iterator rend();
/**
* @brief Iterator, which points to last of this buffer.
*/
const_reverse_iterator rbegin() const;

/**
* @brief Iterator, which points to the element previous to first in this
* buffer.
*/
const_reverse_iterator rend() const;

/**
* @brief Iterator, which points to begin of this buffer.
Expand Down

0 comments on commit 72faf15

Please sign in to comment.