Skip to content

Commit

Permalink
buffer: abstract raw data related methods
Browse files Browse the repository at this point in the history
Create a virtual function that returns the raw data instead of
accessing it directly, so raw buffers backed by pipes can be used as
buffer::ptrs. Make raw::is_page_aligned() virtual so it will not need
to look at the raw data for a pipe-based buffer.

Signed-off-by: Josh Durgin <[email protected]>
  • Loading branch information
jdurgin committed Nov 23, 2013
1 parent 5832e26 commit ebb261f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/common/buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ static uint32_t simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZE
raw(const raw &other);
const raw& operator=(const raw &other);

virtual char *get_data() {
return data;
}
virtual raw* clone_empty() = 0;
raw *clone() {
raw *c = clone_empty();
Expand All @@ -100,7 +103,7 @@ static uint32_t simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZE
return len;
}

bool is_page_aligned() {
virtual bool is_page_aligned() {
return ((long)data & ~CEPH_PAGE_MASK) == 0;
}
bool is_n_page_sized() {
Expand Down Expand Up @@ -375,8 +378,14 @@ static uint32_t simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZE

bool buffer::ptr::at_buffer_tail() const { return _off + _len == _raw->len; }

const char *buffer::ptr::c_str() const { assert(_raw); return _raw->data + _off; }
char *buffer::ptr::c_str() { assert(_raw); return _raw->data + _off; }
const char *buffer::ptr::c_str() const {
assert(_raw);
return _raw->get_data() + _off;
}
char *buffer::ptr::c_str() {
assert(_raw);
return _raw->get_data() + _off;
}

unsigned buffer::ptr::unused_tail_length() const
{
Expand All @@ -389,13 +398,13 @@ static uint32_t simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZE
{
assert(_raw);
assert(n < _len);
return _raw->data[_off + n];
return _raw->get_data()[_off + n];
}
char& buffer::ptr::operator[](unsigned n)
{
assert(_raw);
assert(n < _len);
return _raw->data[_off + n];
return _raw->get_data()[_off + n];
}

const char *buffer::ptr::raw_c_str() const { assert(_raw); return _raw->data; }
Expand Down

0 comments on commit ebb261f

Please sign in to comment.