diff options
author | Christian Pointner <equinox@anytun.org> | 2007-06-17 22:25:20 +0000 |
---|---|---|
committer | Christian Pointner <equinox@anytun.org> | 2007-06-17 22:25:20 +0000 |
commit | 261c9067380c5311c98e3576540eee6015be3297 (patch) | |
tree | f384eb8edbcc4d35793071090839453bcb4418a4 /buffer.cpp | |
parent | added cypher and authalgo (diff) |
added [] - operator to Buffer
const Buffers are now possible
Diffstat (limited to 'buffer.cpp')
-rw-r--r-- | buffer.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
@@ -28,10 +28,10 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <stdexcept> #include <string> #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_; } + |