summaryrefslogtreecommitdiff
path: root/buffer.cpp
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2007-06-17 22:25:20 +0000
committerChristian Pointner <equinox@anytun.org>2007-06-17 22:25:20 +0000
commit261c9067380c5311c98e3576540eee6015be3297 (patch)
treef384eb8edbcc4d35793071090839453bcb4418a4 /buffer.cpp
parentadded cypher and authalgo (diff)
added [] - operator to Buffer
const Buffers are now possible
Diffstat (limited to 'buffer.cpp')
-rw-r--r--buffer.cpp21
1 files changed, 19 insertions, 2 deletions
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 <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_;
}
+