ByteOutBuffer.cc

Go to the documentation of this file.
00001 // $Id: ByteOutBuffer.cc 192 2006-06-15 08:00:53Z bingmann $
00002 
00003 #include "ByteOutBuffer.h"
00004 #include "AnyType.h"
00005 
00006 #include <stdlib.h>
00007 #include <string.h>
00008 
00009 namespace VGServer {
00010 
00011 void ByteOutBuffer::appendBytes(const void *indata, size_t inlen)
00012 {
00013     if (buff.size() + inlen > buff.buffsize()) buff.grow(buff.size() + inlen);
00014 
00015     memcpy(buff.data() + buff.size(), indata, inlen);
00016     buff.set_size(buff.size() + inlen);
00017 }
00018 
00019 void ByteOutBuffer::appendAnyType(const class AnyType &v)
00020 {
00021     switch(v.getType())
00022     {
00023     case ATTRTYPE_INVALID: assert(0); return;
00024 
00025     case ATTRTYPE_BOOL:
00026         // this is a special case: bit values are stored within the
00027         // default bitfield, this must be handeled differently.
00028         assert(0);
00029         return;
00030 
00031     case ATTRTYPE_CHAR:
00032         append<char>(v.getInteger());
00033         return;
00034 
00035     case ATTRTYPE_SHORT:
00036         append<short>(v.getInteger());
00037         return;
00038 
00039     case ATTRTYPE_INTEGER:
00040         append<int>(v.getInteger());
00041         return;
00042 
00043     case ATTRTYPE_LONG:
00044         append<long long>(v.getLong());
00045         return;
00046 
00047     case ATTRTYPE_BYTE:
00048         append<unsigned char>(v.getInteger());
00049         return;
00050 
00051     case ATTRTYPE_WORD:
00052         append<unsigned short>(v.getInteger());
00053         return;
00054 
00055     case ATTRTYPE_DWORD:
00056         append<unsigned int>(v.getInteger());
00057         return;
00058 
00059     case ATTRTYPE_QWORD:
00060         append<unsigned long long>(v.getUnsignedLong());
00061         return;
00062 
00063     case ATTRTYPE_FLOAT:
00064         append<float>(static_cast<float>(v.getDouble()));
00065         return;
00066 
00067     case ATTRTYPE_DOUBLE:
00068         append<double>(v.getDouble());
00069         return;
00070 
00071     case ATTRTYPE_STRING:
00072     {
00073         std::string sout = v.getString();
00074         append<unsigned char>(static_cast<unsigned char>(sout.size()));
00075         appendString(sout);
00076         return;
00077     }
00078     case ATTRTYPE_LONGSTRING:
00079     {
00080         std::string sout = v.getString();
00081         append<unsigned int>(static_cast<unsigned int>(sout.size()));
00082         appendString(sout);
00083         return;
00084     }
00085     }
00086     assert(0);
00087 }
00088 
00089 } // namespace VGServer

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