00001 /* Static buffer class. 00002 * 00003 * PegSoft sockets library (c) 2007 PegSoft 00004 * Contact us at pegsoft@pegsoft.net 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program (see the file COPYING); if not, write to the 00018 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 */ 00020 00024 #ifndef SOCKETS_SBUFFER_H 00025 #define SOCKETS_SBUFFER_H 00026 00027 /*************************************************************************/ 00028 00029 #include <sockets/buffer.h> 00030 00031 /*************************************************************************/ 00032 00033 namespace sockets 00034 { 00035 00036 /*************************************************************************/ 00037 00039 00046 class SBuffer : public Buffer 00047 { 00048 public: 00050 00055 explicit SBuffer(size_t maxsize); 00057 SBuffer(SBuffer const &sb); 00059 virtual ~SBuffer(); 00061 SBuffer &operator=(SBuffer const &right); 00062 00064 virtual bool read(size_t max, 00065 char const **data, size_t *len) const; 00067 virtual bool write(char const *data, size_t len); 00069 virtual bool erase(size_t len); 00071 virtual bool clear(); 00072 00074 virtual bool empty() const { return !m_size; } 00076 virtual size_type size() const { return m_size; } 00078 virtual size_type max_size() const { return m_maxsize; } 00079 protected: 00081 virtual bool read_byte(size_type pos, char *ch) const; 00082 private: 00084 char *m_buf; 00085 00087 char const *m_first; 00089 char *m_next; 00091 char const *m_end; 00092 00094 size_t m_size; 00096 size_t m_maxsize; 00097 }; 00098 00099 /*************************************************************************/ 00100 00101 } /* namespace sockets */ 00102 00103 /*************************************************************************/ 00104 00105 #endif /* SOCKETS_SBUFFER_H */