From 261c9067380c5311c98e3576540eee6015be3297 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 17 Jun 2007 22:25:20 +0000 Subject: added [] - operator to Buffer const Buffers are now possible --- buffer.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'buffer.cpp') diff --git a/buffer.cpp b/buffer.cpp index 676deae..b1029a6 100644 --- a/buffer.cpp +++ b/buffer.cpp @@ -28,10 +28,10 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include #include #include "datatypes.h" - #include "buffer.h" Buffer::Buffer() : buf_(0), length_(0) @@ -115,7 +115,24 @@ u_int8_t* Buffer::getBuf() return buf_; } -Buffer::operator u_int8_t*( ) +u_int8_t& Buffer::operator[](u_int32_t index) +{ + if(index >= length_) + throw std::out_of_range("buffer::operator[]"); + + return buf_[index]; +} + +u_int8_t const& Buffer::operator[](u_int32_t index) const +{ + if(index >= length_) + throw std::out_of_range("buffer::operator[] const"); + + return buf_[index]; +} + +Buffer::operator u_int8_t*() // just for write/read tun { return buf_; } + -- cgit v1.2.3