home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kiobuffer.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  3.9 KB  |  145 lines

  1. /*  -*- C++ -*-
  2.  *  Copyright (C) 2003 Thiago Macieira <thiago.macieira@kdemail.net>
  3.  *
  4.  *
  5.  *  Permission is hereby granted, free of charge, to any person obtaining
  6.  *  a copy of this software and associated documentation files (the
  7.  *  "Software"), to deal in the Software without restriction, including
  8.  *  without limitation the rights to use, copy, modify, merge, publish,
  9.  *  distribute, sublicense, and/or sell copies of the Software, and to
  10.  *  permit persons to whom the Software is furnished to do so, subject to
  11.  *  the following conditions:
  12.  *
  13.  *  The above copyright notice and this permission notice shall be included 
  14.  *  in all copies or substantial portions of the Software.
  15.  *
  16.  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17.  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18.  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19.  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20.  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21.  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22.  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23.  */
  24.  
  25. #ifndef KIOBUFFER_H
  26. #define KIOBUFFER_H
  27.  
  28. #include <qcstring.h>
  29.  
  30. #include <kdelibs_export.h>
  31.  
  32. class QIODevice;
  33.  
  34. /**
  35.  * @class KIOBufferBase kiobuffer.h kiobuffer.h
  36.  * @brief base for I/O buffer implementation
  37.  *
  38.  * This class declares the base methods to interface with an I/O buffer.
  39.  * Most applications will not need to access this class directly, since
  40.  * it is all handled by @ref KNetwork::KBufferedSocket and other buffering
  41.  * classes.
  42.  *
  43.  * @author Thiago Macieira <thiago.macieira@kdemail.net>
  44.  */
  45. class KIOBufferBase
  46. {
  47. public:
  48.   /**
  49.    * Default constructor. Does nothing.
  50.    */
  51.   KIOBufferBase()
  52.   { }
  53.  
  54.   /**
  55.    * Copy constructor. Does nothing here.
  56.    */
  57.   KIOBufferBase(const KIOBufferBase& )
  58.   { }
  59.  
  60.   /**
  61.    * Virtual destructor. Does nothing.
  62.    */
  63.   virtual ~KIOBufferBase()
  64.   { }
  65.  
  66.   /**
  67.    * Assignment operator. Does nothing.
  68.    */
  69.   KIOBufferBase& operator=(const KIOBufferBase& )
  70.   { return *this; }
  71.  
  72.   /**
  73.    * Returns true if a line can be read from the buffer.
  74.    */
  75.   virtual bool canReadLine() const = 0;
  76.  
  77.   /**
  78.    * Reads a line from the buffer and discards it.
  79.    */
  80.   virtual QCString readLine() = 0;
  81.  
  82.   /**
  83.    * Returns the number of bytes in the buffer. Note that this is not
  84.    * the size of the buffer.
  85.    *
  86.    * @sa size
  87.    */
  88.   virtual Q_LONG length() const = 0;
  89.  
  90.   /**
  91.    * Returns true if the buffer is empty of data.
  92.    */
  93.   inline bool isEmpty() const
  94.   { return length() == 0; }
  95.  
  96.   /**
  97.    * Retrieves the buffer size. The value of -1 indicates that
  98.    * the buffer has no defined upper limit.
  99.    *
  100.    * @sa length for the length of the data stored
  101.    */
  102.   virtual Q_LONG size() const = 0;
  103.  
  104.   /**
  105.    * Returns true if the buffer is full (i.e., cannot receive more data)
  106.    */
  107.   inline bool isFull() const
  108.   { return size() != -1 && size() == length(); }
  109.  
  110.   /**
  111.    * Sets the size of the buffer, if allowed.
  112.    *
  113.    * @param size    the maximum size, use -1 for unlimited.
  114.    * @returns true on success, false if an error occurred.
  115.    * @note if the new size is less than length(), the buffer will be truncated
  116.    */
  117.   virtual bool setSize(Q_LONG size) = 0;
  118.  
  119.   /**
  120.    * Adds data to the end of the buffer.
  121.    *
  122.    * @param data    the data to be added
  123.    * @param len        the data length, in bytes
  124.    * @returns the number of bytes added to the end of the buffer.
  125.    */
  126.   virtual Q_LONG feedBuffer(const char *data, Q_LONG len) = 0;
  127.  
  128.   /**
  129.    * Consumes data from the beginning of the buffer.
  130.    *
  131.    * @param data    where to copy the data to
  132.    * @param maxlen    the maximum length to copy, in bytes
  133.    * @param discard    if true, the bytes copied will be discarded
  134.    * @returns the number of bytes copied from the buffer
  135.    */
  136.   virtual Q_LONG consumeBuffer(char *data, Q_LONG maxlen, bool discard = true) = 0;
  137.  
  138.   /**
  139.    * Clears the buffer.
  140.    */
  141.   virtual void clear() = 0;
  142. };
  143.  
  144. #endif
  145.