log4cplus
1.1.0
|
00001 // -*- C++ -*- 00002 // Module: Log4CPLUS 00003 // File: socketbuffer.h 00004 // Created: 5/2003 00005 // Author: Tad E. Smith 00006 // 00007 // 00008 // Copyright 2003-2010 Tad E. Smith 00009 // 00010 // Licensed under the Apache License, Version 2.0 (the "License"); 00011 // you may not use this file except in compliance with the License. 00012 // You may obtain a copy of the License at 00013 // 00014 // http://www.apache.org/licenses/LICENSE-2.0 00015 // 00016 // Unless required by applicable law or agreed to in writing, software 00017 // distributed under the License is distributed on an "AS IS" BASIS, 00018 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 // See the License for the specific language governing permissions and 00020 // limitations under the License. 00021 00024 #ifndef LOG4CPLUS_HELPERS_SOCKET_BUFFER_HEADER_ 00025 #define LOG4CPLUS_HELPERS_SOCKET_BUFFER_HEADER_ 00026 00027 #include <log4cplus/config.hxx> 00028 00029 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 00030 #pragma once 00031 #endif 00032 00033 #include <log4cplus/tstring.h> 00034 00035 00036 namespace log4cplus { 00037 namespace helpers { 00038 00042 class LOG4CPLUS_EXPORT SocketBuffer 00043 { 00044 public: 00045 explicit SocketBuffer(std::size_t max); 00046 virtual ~SocketBuffer(); 00047 00048 char *getBuffer() const { return buffer; } 00049 std::size_t getMaxSize() const { return maxsize; } 00050 std::size_t getSize() const { return size; } 00051 void setSize(std::size_t s) { size = s; } 00052 std::size_t getPos() const { return pos; } 00053 00054 unsigned char readByte(); 00055 unsigned short readShort(); 00056 unsigned int readInt(); 00057 tstring readString(unsigned char sizeOfChar); 00058 00059 void appendByte(unsigned char val); 00060 void appendShort(unsigned short val); 00061 void appendInt(unsigned int val); 00062 void appendString(const tstring& str); 00063 void appendBuffer(const SocketBuffer& buffer); 00064 00065 private: 00066 // Data 00067 std::size_t maxsize; 00068 std::size_t size; 00069 std::size_t pos; 00070 char *buffer; 00071 00072 SocketBuffer(SocketBuffer const & rhs); 00073 SocketBuffer& operator= (SocketBuffer const& rhs); 00074 }; 00075 00076 } // end namespace helpers 00077 } // end namespace log4cplus 00078 00079 #endif // LOG4CPLUS_HELPERS_SOCKET_HEADER_