ByteOutBuffer.h

Go to the documentation of this file.
00001 // $Id: ByteOutBuffer.h 127 2006-05-13 15:30:07Z bingmann $
00002 
00003 #ifndef VGS_ByteOutBuffer_H
00004 #define VGS_ByteOutBuffer_H
00005 
00006 #include <stdlib.h>
00007 #include <assert.h>
00008 
00009 #include <utility>
00010 
00011 #include "ByteBuffer.h"
00012 
00013 namespace VGServer {
00014 
00019 class ByteOutBuffer
00020 {
00021 protected:
00023     ByteBuffer  &buff;
00024 
00025 public:
00027     inline ByteOutBuffer(ByteBuffer &_buff)
00028         : buff(_buff)
00029     {
00030     }
00031 
00033     inline ByteOutBuffer(const ByteOutBuffer &o)
00034         : buff(o.buff)
00035     {
00036     }
00037 
00039     void appendBytes(const void *data, size_t len);
00040 
00043     inline void appendByteBuffer(const ByteBuffer &bb)
00044     { appendBytes(bb.data(), bb.size()); }
00045 
00048     inline void appendString(const std::string &s)
00049     { appendBytes(s.data(), s.size()); }
00050 
00053     template <class T>
00054     inline void append(T item)
00055     {
00056         if (buff.size() + sizeof(T) > buff.buffsize()) buff.grow(buff.size() + sizeof(T));
00057 
00058         *reinterpret_cast<T*>(buff.data() + buff.size()) = item;
00059         buff.set_size(buff.size() + sizeof(T));
00060     }
00061 
00062     // *** Functions with fixed append size
00063 
00065     inline void append_8(char c)
00066     { append<char>(c); }
00067 
00069     inline void append_16(short s)
00070     { append<short>(s); }
00071 
00073     inline void append_32(int i)
00074     { append<int>(i); }
00075 
00077     inline void append_64(long long l)
00078     { append<long long>(l); }
00079 
00080     // *** Functions to append AnyTypes
00081     
00083     void appendAnyType(const class AnyType &v);
00084 };
00085 
00086 
00087 
00088 } // namespace VGServer
00089 
00090 #endif // VGS_ByteOutBuffer_H

Generated on Wed Sep 27 14:34:00 2006 for VGServer by  doxygen 1.4.7