From 1018a24939885ca6eff6e0bf3977bbef18ae973f Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 19 Nov 2012 19:42:14 -0800 Subject: const correctness for sbuffer get() --- include/gras/sbuffer.hpp | 12 ++++++++++-- include/gras/sbuffer.ipp | 14 ++++++++++++-- lib/block_task.cpp | 4 ++-- lib/gras_impl/input_buffer_queues.hpp | 2 +- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/include/gras/sbuffer.hpp b/include/gras/sbuffer.hpp index bf60026..5761625 100644 --- a/include/gras/sbuffer.hpp +++ b/include/gras/sbuffer.hpp @@ -92,7 +92,12 @@ struct GRAS_API SBuffer : boost::intrusive_ptr /*! * Get a pointer to the start of the underlying memory */ - void *get_actual_memory(void) const; + const void *get_actual_memory(void) const; + + /*! + * Get a pointer to the start of the underlying memory + */ + void *get_actual_memory(void); /*! * Get the length of the underlying memory in bytes @@ -100,7 +105,10 @@ struct GRAS_API SBuffer : boost::intrusive_ptr size_t get_actual_length(void) const; //! Get a pointer into valid memory - void *get(const ptrdiff_t delta_bytes = 0) const; + const void *get(const ptrdiff_t delta_bytes = 0) const; + + //! Get a pointer into valid memory + void *get(const ptrdiff_t delta_bytes = 0); //! The offset into valid memory in bytes size_t offset; diff --git a/include/gras/sbuffer.ipp b/include/gras/sbuffer.ipp index 233b4ce..7db390d 100644 --- a/include/gras/sbuffer.ipp +++ b/include/gras/sbuffer.ipp @@ -44,7 +44,12 @@ GRAS_FORCE_INLINE SBuffer::SBuffer(void): //NOP } -GRAS_FORCE_INLINE void *SBuffer::get_actual_memory(void) const +GRAS_FORCE_INLINE const void *SBuffer::get_actual_memory(void) const +{ + return (*this)->config.memory; +} + +GRAS_FORCE_INLINE void *SBuffer::get_actual_memory(void) { return (*this)->config.memory; } @@ -54,7 +59,12 @@ GRAS_FORCE_INLINE size_t SBuffer::get_actual_length(void) const return (*this)->config.length; } -GRAS_FORCE_INLINE void *SBuffer::get(const ptrdiff_t delta_bytes) const +GRAS_FORCE_INLINE const void *SBuffer::get(const ptrdiff_t delta_bytes) const +{ + return ((char *)(*this)->config.memory) + this->offset + delta_bytes; +} + +GRAS_FORCE_INLINE void *SBuffer::get(const ptrdiff_t delta_bytes) { return ((char *)(*this)->config.memory) + this->offset + delta_bytes; } diff --git a/lib/block_task.cpp b/lib/block_task.cpp index 52a641c..1a6c447 100644 --- a/lib/block_task.cpp +++ b/lib/block_task.cpp @@ -134,7 +134,7 @@ void BlockActor::handle_task(void) ASSERT(this->input_queues.ready(i)); //this->input_queues.accumulate(i, this->input_items_sizes[i]); const SBuffer &buff = this->input_queues.front(i); - void *mem = buff.get(); + const void *mem = buff.get(); size_t items = buff.length/this->input_items_sizes[i]; this->input_items[i].get() = mem; @@ -167,7 +167,7 @@ void BlockActor::handle_task(void) for (size_t i = 0; i < num_outputs; i++) { ASSERT(this->output_queues.ready(i)); - const SBuffer &buff = this->output_queues.front(i); + SBuffer &buff = this->output_queues.front(i); void *mem = buff.get(buff.length); const size_t bytes = buff.get_actual_length() - buff.length - buff.offset; size_t items = bytes/this->output_items_sizes[i]; diff --git a/lib/gras_impl/input_buffer_queues.hpp b/lib/gras_impl/input_buffer_queues.hpp index ae38e48..f2738ee 100644 --- a/lib/gras_impl/input_buffer_queues.hpp +++ b/lib/gras_impl/input_buffer_queues.hpp @@ -45,7 +45,7 @@ struct InputBufferQueues void update_config(const size_t i, const size_t, const size_t, const size_t); //! Call to get an input buffer for work - GRAS_FORCE_INLINE SBuffer &front(const size_t i) + GRAS_FORCE_INLINE const SBuffer &front(const size_t i) { ASSERT(this->ready(i)); -- cgit