00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef NEWNET_BUFFER_H
00021 #define NEWNET_BUFFER_H
00022
00023 #include "nnobject.h"
00024 #include <sys/types.h>
00025 #include <assert.h>
00026
00027 namespace NewNet
00028 {
00030
00032 class Buffer : public NewNet::Object
00033 {
00034 public:
00036
00037 Buffer() : m_Ptr(0), m_Pos(0), m_Count(0), m_Left(0)
00038 {
00039 }
00040
00042
00043 Buffer(const Buffer & that) : m_Ptr(0), m_Pos(0), m_Count(0), m_Left(0)
00044 {
00045 append(that.data(), that.count());
00046 }
00047
00049
00050 Buffer & operator=(const Buffer & that)
00051 {
00052 m_Left += m_Pos + m_Count;
00053 m_Pos = m_Count = 0;
00054 append(that.data(), that.count());
00055 return *this;
00056 }
00057
00059
00060 ~Buffer();
00061
00063
00064 unsigned char * data()
00065 {
00066 return m_Ptr + m_Pos;
00067 }
00068
00070
00071 const unsigned char * data() const
00072 {
00073 return m_Ptr + m_Pos;
00074 }
00075
00077
00079 size_t count() const
00080 {
00081 return m_Count;
00082 }
00083
00085
00086 bool empty() const
00087 {
00088 return m_Count == 0;
00089 }
00090
00092
00096 void seek(size_t n)
00097 {
00098 assert(n <= m_Count);
00099 m_Pos += n;
00100 m_Count -= n;
00101 }
00102
00104
00107 void append(const unsigned char * data, size_t n);
00108
00109 private:
00110 unsigned char * m_Ptr;
00111 size_t m_Pos, m_Count, m_Left;
00112 };
00113 }
00114
00115 #endif // NEWNET_BUFFER_H