_strstream.h

00001 
00002 #ifndef _STLP_INTERNAL_STREAMBUF
00003 #include <stl/_streambuf.h>
00004 #endif
00005 #ifndef _STLP_ISTREAM
00006 #include <istream>              // Includes <ostream>, <ios>, <iosfwd>
00007 #endif
00008 #ifndef _STLP_STRING_H
00009 #include <stl/_string.h>
00010 #endif
00011 
00012 _STLP_BEGIN_NAMESPACE
00013 
00014 #ifndef _STLP_USE_NAMESPACES
00015 # define strstream _STLP_strstream 
00016 # define ostrstream _STLP_ostrstream
00017 # define istrstream _STLP_istrstream
00018 # define strstreambuf _STLP_strstreambuf
00019 #endif
00020 
00021 //----------------------------------------------------------------------
00022 // Class strstreambuf, a streambuf class that manages an array of char.
00023 // Note that this class is not a template.
00024 
00025 class _STLP_CLASS_DECLSPEC strstreambuf : public basic_streambuf<char, char_traits<char> >
00026 {
00027 public:                         // Types.
00028   typedef char_traits<char>              _Traits;
00029   typedef basic_streambuf<char, char_traits<char> > _Base;
00030   typedef void* (*__alloc_fn)(size_t);
00031   typedef void (*__free_fn)(void*);
00032 public:                         // Constructor, destructor
00033 
00034   explicit strstreambuf(streamsize _Initial_capacity = 0);
00035 
00036   strstreambuf(__alloc_fn, __free_fn);
00037 
00038   strstreambuf(char* __get, streamsize __n, char* __put = 0);
00039   strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0);
00040   strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0);
00041 
00042   strstreambuf(const char* __get, streamsize __n);
00043   strstreambuf(const signed char* __get, streamsize __n);
00044   strstreambuf(const unsigned char* __get, streamsize __n);
00045 
00046   virtual ~strstreambuf();
00047 
00048 public:                         // strstreambuf operations.
00049   void freeze(bool = true);
00050   char* str();
00051   int pcount() const;
00052 
00053 protected:                      // Overridden virtual member functions.
00054   virtual int_type overflow(int_type __c  = _Traits::eof());
00055   virtual int_type pbackfail(int_type __c = _Traits::eof());
00056   virtual int_type underflow();
00057   virtual _Base* setbuf(char* __buf, streamsize __n);
00058   virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
00059                            ios_base::openmode __mode 
00060                                       = ios_base::in | ios_base::out);
00061   virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode 
00062                                       = ios_base::in | ios_base::out);
00063 
00064 private:                        // Helper functions.
00065   // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
00066   char* _M_alloc(size_t);
00067   void  _M_free(char*);
00068 
00069   // Helper function used in constructors.
00070   void _M_setup(char* __get, char* __put, streamsize __n);
00071 private:                        // Data members.
00072   __alloc_fn _M_alloc_fun;
00073   __free_fn  _M_free_fun;
00074   bool _M_dynamic  : 1;
00075   bool _M_frozen   : 1;
00076   bool _M_constant : 1;
00077 };
00078 
00079 //----------------------------------------------------------------------
00080 // Class istrstream, an istream that manages a strstreambuf.
00081 
00082 class _STLP_CLASS_DECLSPEC istrstream : public basic_istream<char, char_traits<char> >
00083 {
00084 public:
00085   explicit istrstream(char*);
00086   explicit istrstream(const char*);
00087   istrstream(char* , streamsize);
00088   istrstream(const char*, streamsize);
00089   virtual ~istrstream();
00090   
00091   strstreambuf* rdbuf() const;
00092   char* str();
00093 
00094 private:
00095   strstreambuf _M_buf;
00096 };
00097 
00098 //----------------------------------------------------------------------
00099 // Class ostrstream
00100 
00101 class _STLP_CLASS_DECLSPEC ostrstream : public basic_ostream<char, char_traits<char> >
00102 {
00103 public:
00104   ostrstream();
00105   ostrstream(char*, int, ios_base::openmode = ios_base::out);
00106   virtual ~ostrstream();
00107 
00108   strstreambuf* rdbuf() const;
00109   void freeze(bool = true);
00110   char* str();
00111   int pcount() const;
00112 
00113 private:
00114   strstreambuf _M_buf;
00115 };
00116 
00117 //----------------------------------------------------------------------
00118 // Class strstream
00119 
00120 class _STLP_CLASS_DECLSPEC strstream : public basic_iostream<char, char_traits<char> >
00121 {
00122 public:
00123   typedef char                        char_type;
00124   typedef char_traits<char>::int_type int_type;
00125   typedef char_traits<char>::pos_type pos_type;
00126   typedef char_traits<char>::off_type off_type;
00127 
00128   strstream();
00129   strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out);
00130   virtual ~strstream();
00131 
00132   strstreambuf* rdbuf() const;
00133   void freeze(bool = true);
00134   int pcount() const;
00135   char* str();
00136 
00137 private:
00138   strstreambuf _M_buf;
00139 };
00140 
00141 _STLP_END_NAMESPACE

Generated on Mon Jun 5 10:20:47 2006 for Intelligence.kdevelop by  doxygen 1.4.6