diff options
author | Josh Blum | 2012-11-19 19:42:14 -0800 |
---|---|---|
committer | Josh Blum | 2012-11-19 19:42:14 -0800 |
commit | 1018a24939885ca6eff6e0bf3977bbef18ae973f (patch) | |
tree | cceba77520696a004068fe96ee5e961a2e40083c | |
parent | 216b8685e7889698567cd47e8f93ec672a2e5323 (diff) | |
download | sandhi-1018a24939885ca6eff6e0bf3977bbef18ae973f.tar.gz sandhi-1018a24939885ca6eff6e0bf3977bbef18ae973f.tar.bz2 sandhi-1018a24939885ca6eff6e0bf3977bbef18ae973f.zip |
const correctness for sbuffer get()
-rw-r--r-- | include/gras/sbuffer.hpp | 12 | ||||
-rw-r--r-- | include/gras/sbuffer.ipp | 14 | ||||
-rw-r--r-- | lib/block_task.cpp | 4 | ||||
-rw-r--r-- | 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<SBufferImpl> /*! * 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<SBufferImpl> 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)); |