Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

dsStrstream.h

Go to the documentation of this file.
00001 /*
00002  * $Id: dsStrstream.h,v 1.7 2003/09/02 11:31:22 dsamersoff Exp $
00003  */
00004 #ifndef dsStrstream_h
00005 #define dsStrstream_h
00006 
00007 #include <iostream>
00008 #include <stdlib.h>
00009 #include <string.h>
00010 #include <limits.h>
00011 
00069 /*
00070  * Stream config 
00071  */
00072 
00073 // #define _DS_ENABLE_AUTOFREEZE     
00074 // #define _DS_USE_SGI_SEEK_ROUTINE 
00075 #define _DS_AUTOTERMINATE 
00076 
00077 #define _DS_ADAPTIVE_INCREMENT  
00078 #define _DS_SEGMENT_SIZE        64
00079 
00080 
00081 
00082 #define _DS_IO_FROZEN    0x1
00083 #define _DS_IO_STATIC    0x2
00084 #define _DS_IO_CONSTANT  0x4
00085 
00086 #define _DS_IO_EOF    -1
00087 #define _DS_IO_NOT_EOF 0
00088 
00089 #define _DS_IO_NOTMOVABLE (_DS_IO_FROZEN | _DS_IO_STATIC | _DS_IO_CONSTANT)
00090 
00091 /*
00092 typedef streamoff streamoff;
00093 typedef streampos streampos;
00094 typedef streamsize streamsize;
00095 */
00096 
00097 typedef void *(*p_alloc)(size_t);
00098 typedef void (*p_free)(void *);
00099 
00100 class dsStrstreambuf : public std::streambuf 
00101 {
00102     long  _flags;
00103     p_alloc _palloc;
00104     p_free  _pfree;
00105 
00106     size_t _seg_size;
00107     int _overflow_cnt;
00108     
00109     char *_pbeg, *_gnext;
00110     std::streampos _pos_n;
00111 
00112 
00113     std::streampos _seekoff_p(std::streamoff off, std::ios::seekdir dir);
00114     std::streampos _seekoff_g(std::streamoff off, std::ios::seekdir dir);
00115 
00116 public:
00117 
00118     explicit  dsStrstreambuf(size_t initial_size = _DS_SEGMENT_SIZE);
00119               dsStrstreambuf( const dsStrstreambuf* src );
00120               dsStrstreambuf( p_alloc cust_alloc, p_free cust_free );
00121               dsStrstreambuf(char *gnext, std::streampos n, char *pbeg );
00122               dsStrstreambuf(const char *gnext, std::streampos n );
00123 
00124 
00125     virtual ~dsStrstreambuf();
00126 
00127     int frozen();
00128     void freeze(bool n = true);
00129 
00130     size_t pcount();
00131     char *str();
00132 
00133     int overflow(int ch);
00134     int underflow();
00135     int pbackfail(int c);
00136 
00137     std::streampos seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode);
00138     std::streampos seekpos(std::streamoff off, std::ios::openmode mode){ return seekoff(off, std::ios::beg, mode); }
00139 
00140    /* Extensions */
00141     void setseg(size_t new_size = _DS_SEGMENT_SIZE);
00142     void clear();
00143 
00144 };
00145 
00146 class dsStrstream :  public std::iostream
00147 {  
00148    dsStrstreambuf* _sb;
00149    
00150   public:
00151     dsStrstream();
00152     dsStrstream(const dsStrstream& s );
00153     dsStrstream(char *s, int n, std::ios::openmode mode = std::ios::out | std::ios::in);
00154     virtual ~dsStrstream();
00155 
00156     dsStrstreambuf *rdbuf() const;
00157 
00158     size_t pcount(); 
00159     char *str(); 
00160          
00161     void freeze(bool n = true);
00162 
00163     void clear();
00164 };  
00165 
00166 
00167 #ifdef USE_DMS_IOSTREAMS
00168 
00169 class dsiStrstream : public std::istream
00170 {
00171    dsStrstreambuf* _sb;
00172 
00173   public:
00174     explicit dsiStrstream(char* s);
00175     explicit dsiStrstream(const char* s);
00176              dsiStrstream(const dsiStrstream& s );
00177              dsiStrstream(char* s, std::streampos n);
00178              dsiStrstream(const char* s, std::streampos n);
00179     virtual ~dsiStrstream();
00180 
00181     dsStrstreambuf* rdbuf() const;
00182     char* str();            
00183 
00184     void clear();
00185 };
00186 
00187   // Class ostrstream
00188 class dsoStrstream : public std::ostream
00189 {
00190    dsStrstreambuf* _sb;
00191 
00192   public:
00193     dsoStrstream();
00194     dsoStrstream(const dsoStrstream& s );
00195     dsoStrstream(char * s, int n, std::ios::openmode = std::ios::out);
00196     virtual ~dsoStrstream();
00197 
00198     dsStrstreambuf* rdbuf() const;
00199 
00200     void freeze(bool n = true);
00201 
00202     char* str();
00203     size_t pcount();      
00204 
00205     void clear();
00206 };
00207 #endif
00208 
00209 
00210 #endif

Generated on Mon May 16 18:26:58 2005 for libdms4 by doxygen1.3-rc2