home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / strstrea.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  6.6 KB  |  231 lines

  1. #ifndef __STRSTREA_H
  2. #define __STRSTREA_H
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. // -*- C++ -*-
  5. /***************************************************************************
  6.  *
  7.  * strstream - Declarations for the Standard Library string stream classes
  8.  *
  9.  ***************************************************************************
  10.  *
  11.  * Copyright (c) 1994-1999 Rogue Wave Software, Inc.  All Rights Reserved.
  12.  *
  13.  * This computer software is owned by Rogue Wave Software, Inc. and is
  14.  * protected by U.S. copyright laws and other laws and by international
  15.  * treaties.  This computer software is furnished by Rogue Wave Software,
  16.  * Inc. pursuant to a written license agreement and may be used, copied,
  17.  * transmitted, and stored only in accordance with the terms of such
  18.  * license and with the inclusion of the above copyright notice.  This
  19.  * computer software or any other copies thereof may not be provided or
  20.  * otherwise made available to any other person.
  21.  *
  22.  * U.S. Government Restricted Rights.  This computer software is provided
  23.  * with Restricted Rights.  Use, duplication, or disclosure by the
  24.  * Government is subject to restrictions as set forth in subparagraph (c)
  25.  * (1) (ii) of The Rights in Technical Data and Computer Software clause
  26.  * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
  27.  * Commercial Computer Software รป Restricted Rights at 48 CFR 52.227-19,
  28.  * as applicable.  Manufacturer is Rogue Wave Software, Inc., 5500
  29.  * Flatiron Parkway, Boulder, Colorado 80301 USA.
  30.  *
  31.  **************************************************************************/
  32.  
  33. #ifndef __STD_STRSTREAM__
  34. #define __STD_STRSTREAM__
  35.  
  36. #include <streambuf>
  37. #include <istream>
  38. #include <ostream>
  39.  
  40. #ifndef _RWSTD_NO_NAMESPACE 
  41. namespace std {
  42. #endif
  43.   
  44.  
  45.   class _RWSTDExport strstreambuf
  46. #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  47.     : public basic_streambuf<char>
  48. #else
  49.     : public basic_streambuf<char, char_traits<char> >
  50. #endif // _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES 
  51.   {
  52.  
  53.   public:
  54.     //
  55.     // Types:
  56.     //
  57.     typedef char                         char_type;
  58.     typedef char_traits<char>            traits;
  59.     typedef traits::int_type             int_type;
  60.     typedef traits::pos_type             pos_type;
  61.     typedef traits::off_type             off_type;
  62.   
  63.     _EXPLICIT strstreambuf(streamsize alsize = 0);
  64.     strstreambuf(void *(*palloc)(size_t), void (*pfree)(void *));
  65.     strstreambuf(char *gnext, streamsize n, char *pbeg = 0);
  66.  
  67.     strstreambuf(unsigned char *gnext, streamsize n,
  68.                  unsigned char *pbeg = 0);
  69.     strstreambuf(signed char *gnext, streamsize n,
  70.                  signed char *pbeg = 0);
  71.  
  72.     strstreambuf(const char *gnext, streamsize n);
  73.     strstreambuf(const unsigned char *gnext, streamsize n);
  74.     strstreambuf(const signed char *gnext, streamsize n);
  75.     virtual ~strstreambuf();
  76.  
  77.     void freeze(bool f = true);
  78.     char *str();
  79.     int pcount() const;
  80.  
  81.   protected:
  82.     virtual int_type overflow(int_type c = traits::eof());
  83.     virtual int_type pbackfail(int_type c = traits::eof());
  84.     virtual int_type underflow();
  85.  
  86.     virtual pos_type seekoff(off_type, ios_base::seekdir way,
  87.                              ios_base::openmode which =
  88.                              ios_base::in | ios_base::out);
  89.  
  90.     virtual pos_type seekpos(pos_type sp, ios_base::openmode which =
  91.                              ios_base::in | ios_base::out);
  92.  
  93.     virtual streambuf* setbuf(char *s, streamsize n);
  94.     virtual streamsize xsputn(const char_type *s, streamsize n);
  95.  
  96.   private:
  97.     typedef long strstate;
  98.  
  99.     enum str_state {
  100.       allocated      = 0x01,
  101.       constant       = 0x02,
  102.       dynamic        = 0x04,
  103.       frozen         = 0x08
  104.     };
  105.  
  106.     int doallocate();
  107.   
  108.     strstate       __strmode;
  109.     streamsize     __alsize;
  110.     char          *__data;
  111.     streamsize     __end_pos;
  112.  
  113.     void           *(*__palloc)(size_t);
  114.     void           (*__pfree)(void *);
  115.   };
  116.  
  117.   class _RWSTDExport istrstream
  118. #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  119.     : public basic_istream<char>
  120. #else
  121.     : public basic_istream<char, char_traits<char> >
  122. #endif
  123.   {
  124.  
  125.   public:
  126.     //
  127.     // Types:
  128.     //
  129.     typedef char                         char_type;
  130.     typedef char_traits<char>            traits;
  131.     typedef traits::int_type             int_type;
  132.     typedef traits::pos_type             pos_type;
  133.     typedef traits::off_type             off_type;
  134.   
  135.     _EXPLICIT istrstream(const char *s);
  136.     istrstream(const char *s, streamsize n);
  137.     _EXPLICIT istrstream(char *s);
  138.     istrstream(char *s, streamsize n);
  139.  
  140.     virtual ~istrstream();
  141.  
  142.     strstreambuf *rdbuf() const;
  143.     char *str();
  144.   protected:
  145.  
  146.   private:
  147.     strstreambuf              __sb;
  148.   };
  149.   class _RWSTDExport ostrstream
  150. #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  151.     : public basic_ostream<char>
  152. #else
  153.     : public basic_ostream<char, char_traits<char> >
  154. #endif
  155.   {
  156.  
  157.   public:
  158.     //
  159.     // Types:
  160.     //
  161.     typedef char                               char_type;
  162.     typedef char_traits<char>                  traits;
  163.     typedef traits::int_type                   int_type;
  164.     typedef traits::pos_type                   pos_type;
  165.     typedef traits::off_type                   off_type;
  166.   
  167.     ostrstream();
  168.     ostrstream(char *s, int n,
  169.                ios_base::openmode = ios_base::out);
  170.     
  171.     virtual ~ostrstream();
  172.     strstreambuf *rdbuf() const;
  173.     void freeze(bool freezefl = true);
  174.     char *str();
  175.     int pcount() const;
  176.  
  177.   protected:
  178.  
  179.   private:
  180.     strstreambuf        __sb;
  181.   };
  182. /*
  183.  *  Class strstream
  184.  */
  185.  
  186.   class _RWSTDExport strstream
  187. #ifndef _RWSTD_NO_DEFAULT_TEMPLATES
  188.     : public basic_iostream<char>
  189. #else
  190.     : public basic_iostream<char, char_traits<char> >
  191. #endif
  192.   {
  193.  
  194.   public:
  195.     //
  196.     // Types:
  197.     //
  198.     typedef char                         char_type;
  199.     typedef char_traits<char>            traits;
  200.     typedef traits::int_type             int_type;
  201.     typedef traits::pos_type             pos_type;
  202.     typedef traits::off_type             off_type;
  203.   
  204.     strstream();
  205.     strstream(char *s, int n,
  206.               ios_base::openmode = ios_base::out | ios_base::in);
  207.  
  208.     void freeze(bool freezefl = true);
  209.     int pcount() const;
  210.  
  211.     virtual ~strstream();
  212.     strstreambuf *rdbuf() const;
  213.  
  214.     char *str();
  215.   protected:
  216.  
  217.   private:
  218.     strstreambuf          __sb;
  219.   };
  220. #ifndef _RWSTD_NO_NAMESPACE
  221. }
  222. #endif
  223.  
  224. #endif //__STD_STRSTREAM__ 
  225. #ifndef __USING_STD_NAMES__
  226.   using namespace std;
  227. #endif
  228.  
  229. #pragma option pop
  230. #endif /* __STRSTREA_H */
  231.