home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / stlport / stl / _strstream.h < prev    next >
C/C++ Source or Header  |  2001-03-15  |  4KB  |  142 lines

  1.  
  2. #ifndef _STLP_INTERNAL_STREAMBUF
  3. #include <stl/_streambuf.h>
  4. #endif
  5. #ifndef _STLP_ISTREAM
  6. #include <istream>              // Includes <ostream>, <ios>, <iosfwd>
  7. #endif
  8. #ifndef _STLP_STRING_H
  9. #include <stl/_string.h>
  10. #endif
  11.  
  12. _STLP_BEGIN_NAMESPACE
  13.  
  14. #ifndef _STLP_USE_NAMESPACES
  15. # define strstream _STLP_strstream 
  16. # define ostrstream _STLP_ostrstream
  17. # define istrstream _STLP_istrstream
  18. # define strstreambuf _STLP_strstreambuf
  19. #endif
  20.  
  21. //----------------------------------------------------------------------
  22. // Class strstreambuf, a streambuf class that manages an array of char.
  23. // Note that this class is not a template.
  24.  
  25. class _STLP_CLASS_DECLSPEC strstreambuf : public basic_streambuf<char, char_traits<char> >
  26. {
  27. public:                         // Types.
  28.   typedef char_traits<char>              _Traits;
  29.   typedef basic_streambuf<char, char_traits<char> > _Base;
  30.   typedef void* (*__alloc_fn)(size_t);
  31.   typedef void (*__free_fn)(void*);
  32. public:                         // Constructor, destructor
  33.  
  34.   explicit strstreambuf(streamsize _Initial_capacity = 0);
  35.  
  36.   strstreambuf(__alloc_fn, __free_fn);
  37.  
  38.   strstreambuf(char* __get, streamsize __n, char* __put = 0);
  39.   strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0);
  40.   strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0);
  41.  
  42.   strstreambuf(const char* __get, streamsize __n);
  43.   strstreambuf(const signed char* __get, streamsize __n);
  44.   strstreambuf(const unsigned char* __get, streamsize __n);
  45.  
  46.   virtual ~strstreambuf();
  47.  
  48. public:                         // strstreambuf operations.
  49.   void freeze(bool = true);
  50.   char* str();
  51.   int pcount() const;
  52.  
  53. protected:                      // Overridden virtual member functions.
  54.   virtual int_type overflow(int_type __c  = _Traits::eof());
  55.   virtual int_type pbackfail(int_type __c = _Traits::eof());
  56.   virtual int_type underflow();
  57.   virtual _Base* setbuf(char* __buf, streamsize __n);
  58.   virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
  59.                            ios_base::openmode __mode 
  60.                                       = ios_base::in | ios_base::out);
  61.   virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode 
  62.                                       = ios_base::in | ios_base::out);
  63.  
  64. private:                        // Helper functions.
  65.   // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
  66.   char* _M_alloc(size_t);
  67.   void  _M_free(char*);
  68.  
  69.   // Helper function used in constructors.
  70.   void _M_setup(char* __get, char* __put, streamsize __n);
  71. private:                        // Data members.
  72.   __alloc_fn _M_alloc_fun;
  73.   __free_fn  _M_free_fun;
  74.   bool _M_dynamic  : 1;
  75.   bool _M_frozen   : 1;
  76.   bool _M_constant : 1;
  77. };
  78.  
  79. //----------------------------------------------------------------------
  80. // Class istrstream, an istream that manages a strstreambuf.
  81.  
  82. class _STLP_CLASS_DECLSPEC istrstream : public basic_istream<char, char_traits<char> >
  83. {
  84. public:
  85.   explicit istrstream(char*);
  86.   explicit istrstream(const char*);
  87.   istrstream(char* , streamsize);
  88.   istrstream(const char*, streamsize);
  89.   virtual ~istrstream();
  90.   
  91.   strstreambuf* rdbuf() const;
  92.   char* str();
  93.  
  94. private:
  95.   strstreambuf _M_buf;
  96. };
  97.  
  98. //----------------------------------------------------------------------
  99. // Class ostrstream
  100.  
  101. class _STLP_CLASS_DECLSPEC ostrstream : public basic_ostream<char, char_traits<char> >
  102. {
  103. public:
  104.   ostrstream();
  105.   ostrstream(char*, int, ios_base::openmode = ios_base::out);
  106.   virtual ~ostrstream();
  107.  
  108.   strstreambuf* rdbuf() const;
  109.   void freeze(bool = true);
  110.   char* str();
  111.   int pcount() const;
  112.  
  113. private:
  114.   strstreambuf _M_buf;
  115. };
  116.  
  117. //----------------------------------------------------------------------
  118. // Class strstream
  119.  
  120. class _STLP_CLASS_DECLSPEC strstream : public basic_iostream<char, char_traits<char> >
  121. {
  122. public:
  123.   typedef char                        char_type;
  124.   typedef char_traits<char>::int_type int_type;
  125.   typedef char_traits<char>::pos_type pos_type;
  126.   typedef char_traits<char>::off_type off_type;
  127.  
  128.   strstream();
  129.   strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out);
  130.   virtual ~strstream();
  131.  
  132.   strstreambuf* rdbuf() const;
  133.   void freeze(bool = true);
  134.   int pcount() const;
  135.   char* str();
  136.  
  137. private:
  138.   strstreambuf _M_buf;
  139. };
  140.  
  141. _STLP_END_NAMESPACE
  142.