Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ 3.0r4 - <b>buffering - class streambuf</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Buffering - Class streambuf

   The streambuf class is an abstraction of a buffer.  It usually acts as an
   intermediary between a consumer of characters and some ultimate source,
   or between a producer of characters and some ultimate destination. A
   streambuf can be thought of as having a get pointer, which points at a
   position from which the next character can be got, or before which a
   character may be put back, and a put pointer at which position the next
   character to be put may be placed.

   A streambuf will actually be of some finite size, probably unrelated to
   the size of the ultimate source or sink of characters. A part of the
   abstraction therefore enables it to replenish itself from the ultimate
   source when there are no remaining characters in its get area
   (underflow), or to move characters to the ultimate destination when its
   put area is full (overflow). These operations are transparent to the user
   of a streambuf, and will operate differently for derivatives of streambuf

   which are specialized for some particular combination of ultimate source
   and destination.

   The concept of get and put pointers extends to the provision of functions
   to reposition these pointers. Such repositioning should be though of as
   relative to the total contents of the ultimate source and the ultimate
   destination.

   The public interface of the base class streambuf is as follows:

   #ifndef EOF
   const int EOF = -1;
   #endif

   #define seek_dir relative_to

   class streambuf {
   public:
       enum relative_to { beg, cur, end };
       enum open_mode { in, out, ate, app, trunc, nocreate,

   noreplace };

   // Constructors, destructor
       streambuf();
       streambuf(char *memory, int length);
       virtual ~streambuf();

   // Status functions
       int in_avail() const;
       int out_waiting() const;

   // Take or examine characters from the get area
       int sgetc();
       int sbumpc();
       void stossc()
       int snextc();
       int sgetn(char *buffer, int count);

   // Place characters in the put area
       int sputc(int c);

       int sputn(const char *string, int length);

   // Return a character to the get area
       int sputbackc(char c);

   // Make the streambuf consistent with the ultimate
   // source and destination
       virtual int sync();

   // Position the get and put pointers
       virtual streampos  seekpos(streampos position, int
   which=ios::in|ios::out);
       virtual streampos seekoff(streampos offset, relative_to
   pos, int which=ios::in|ios::out);

   // Offer an area of memory for use as a buffer
       virtual streambuf *setbuf(char *memory, int length);
   };

   All functions described here require the inclusion of iostream.hpp or
   some header file that itself includes iostream.hpp.





Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson