genericopenlibs/cppstdlib/stl/stlport/stl/_streambuf.h
changeset 22 ddc455616bd6
parent 0 e4d67989cc36
child 45 4b03adbd26ca
equal deleted inserted replaced
18:47c74d1534e1 22:ddc455616bd6
    70 
    70 
    71 //public:                         // Extension: locking, for thread safety.
    71 //public:                         // Extension: locking, for thread safety.
    72 //  _STLP_mutex _M_lock;
    72 //  _STLP_mutex _M_lock;
    73 
    73 
    74 public:                         // Destructor.
    74 public:                         // Destructor.
    75   virtual ~basic_streambuf();
    75 	virtual ~basic_streambuf(){}
    76 
    76 
    77 protected:                      // The default constructor.
    77 protected:                      // The default constructor.
    78   basic_streambuf()
    78   basic_streambuf()
    79 #if defined (_STLP_MSVC) && (_STLP_MSVC < 1300) && defined (_STLP_USE_STATIC_LIB)
    79 #if defined (_STLP_MSVC) && (_STLP_MSVC < 1300) && defined (_STLP_USE_STATIC_LIB)
    80     //We make it inline to avoid unresolved symbol.
    80     //We make it inline to avoid unresolved symbol.
   120     _M_pbegin = __pbegin;
   120     _M_pbegin = __pbegin;
   121     _M_pnext  = __pbegin;
   121     _M_pnext  = __pbegin;
   122     _M_pend   = __pend;
   122     _M_pend   = __pend;
   123   }
   123   }
   124 
   124 
   125 protected:                      // Virtual buffer management functions.
   125 protected:                   // Virtual buffer management functions.                                     
   126 
   126   
   127   virtual basic_streambuf<_CharT, _Traits>* setbuf(char_type*, streamsize);
   127   
   128 
   128   
       
   129   virtual basic_streambuf<_CharT, _Traits>* setbuf(char_type*, streamsize) {
       
   130       return this; 
       
   131   }
       
   132   
   129   // Alters the stream position, using an integer offset.  In this
   133   // Alters the stream position, using an integer offset.  In this
   130   // class seekoff does nothing; subclasses are expected to override it.
   134   // class seekoff does nothing; subclasses are expected to override it.
       
   135   
   131   virtual pos_type seekoff(off_type, ios_base::seekdir,
   136   virtual pos_type seekoff(off_type, ios_base::seekdir,
   132                            ios_base::openmode = ios_base::in | ios_base::out);
   137                              ios_base::openmode = ios_base::in | ios_base::out) {
   133 
   138       return pos_type(-1); 
       
   139   }
       
   140   
   134   // Alters the stream position, using a previously obtained streampos.  In
   141   // Alters the stream position, using a previously obtained streampos.  In
   135   // this class seekpos does nothing; subclasses are expected to override it.
   142   // this class seekpos does nothing; subclasses are expected to override it.
   136   virtual pos_type
   143   virtual pos_type
   137   seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
   144     seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out) {
   138 
   145       return pos_type(-1); 
       
   146   }
       
   147   
   139   // Synchronizes (i.e. flushes) the buffer.  All subclasses are expected to
   148   // Synchronizes (i.e. flushes) the buffer.  All subclasses are expected to
   140   // override this virtual member function.
   149   // override this virtual member function.
   141   virtual int sync();
   150   virtual int sync() {
   142 
   151       return 0; 
       
   152   }                             
   143 
   153 
   144 public:                         // Buffer management.
   154 public:                         // Buffer management.
   145   basic_streambuf<_CharT, _Traits>* pubsetbuf(char_type* __s, streamsize __n)
   155   basic_streambuf<_CharT, _Traits>* pubsetbuf(char_type* __s, streamsize __n)
   146   { return this->setbuf(__s, __n); }
   156   { return this->setbuf(__s, __n); }
   147 
   157 
   153                       ios_base::openmode __mod = ios_base::in | ios_base::out)
   163                       ios_base::openmode __mod = ios_base::in | ios_base::out)
   154   { return this->seekpos(__sp, __mod); }
   164   { return this->seekpos(__sp, __mod); }
   155 
   165 
   156   int pubsync() { return this->sync(); }
   166   int pubsync() { return this->sync(); }
   157 
   167 
   158 protected:                      // Virtual get area functions, as defined in
   168 protected:            // Virtual get area functions, as defined in
   159                                 // 17.5.2.4.3 and 17.5.2.4.4 of the standard.
   169                    // 17.5.2.4.3 and 17.5.2.4.4 of the standard.     
   160   // Returns a lower bound on the number of characters that we can read,
   170   // Returns a lower bound on the number of characters that we can read,
   161   // with underflow, before reaching end of file.  (-1 is a special value:
   171   // with underflow, before reaching end of file.  (-1 is a special value:
   162   // it means that underflow will fail.)  Most subclasses should probably
   172   // it means that underflow will fail.)  Most subclasses should probably
   163   // override this virtual member function.
   173   // override this virtual member function.
   164   virtual streamsize showmanyc();
   174   
   165 
   175   virtual streamsize showmanyc() {
       
   176       return 0; 
       
   177   }
       
   178   
   166   // Reads up to __n characters.  Return value is the number of
   179   // Reads up to __n characters.  Return value is the number of
   167   // characters read.
   180   // characters read.
   168   virtual streamsize xsgetn(char_type* __s, streamsize __n);
   181   virtual streamsize xsgetn(char_type* __s, streamsize __n) {
   169 
   182       streamsize __result = 0;
       
   183       const int_type __eof = _Traits::eof();
       
   184 
       
   185       while (__result < __n) {
       
   186         if (_M_gnext < _M_gend) {
       
   187           size_t __chunk = (min) (__STATIC_CAST(size_t,_M_gend - _M_gnext),
       
   188                                   __STATIC_CAST(size_t,__n - __result));
       
   189           _Traits::copy(__s, _M_gnext, __chunk);
       
   190           __result += __chunk;
       
   191           __s += __chunk;
       
   192           _M_gnext += __chunk;
       
   193         }
       
   194         else {
       
   195           int_type __c = this->sbumpc();
       
   196           if (!_Traits::eq_int_type(__c, __eof)) {
       
   197             *__s = _Traits::to_char_type(__c);
       
   198             ++__result;
       
   199             ++__s;
       
   200           }
       
   201           else
       
   202             break;
       
   203         }
       
   204       }
       
   205 
       
   206       return __result;
       
   207   }
       
   208   
   170   // Called when there is no read position, i.e. when gptr() is null
   209   // Called when there is no read position, i.e. when gptr() is null
   171   // or when gptr() >= egptr().  Subclasses are expected to override
   210   // or when gptr() >= egptr().  Subclasses are expected to override
   172   // this virtual member function.
   211   // this virtual member function.
   173   virtual int_type underflow();
   212   virtual int_type underflow() {
   174 
   213       return _Traits::eof(); 
       
   214   }
       
   215   
   175   // Similar to underflow(), but used for unbuffered input.  Most
   216   // Similar to underflow(), but used for unbuffered input.  Most
   176   // subclasses should probably override this virtual member function.
   217   // subclasses should probably override this virtual member function.
   177   virtual int_type uflow();
   218   virtual int_type uflow() {
   178 
   219       return ( _Traits::eq_int_type(this->underflow(),_Traits::eof()) ?
       
   220                _Traits::eof() :
       
   221                _Traits::to_int_type(*_M_gnext++));
       
   222   }
       
   223   
   179   // Called when there is no putback position, i.e. when gptr() is null
   224   // Called when there is no putback position, i.e. when gptr() is null
   180   // or when gptr() == eback().  All subclasses are expected to override
   225   // or when gptr() == eback().  All subclasses are expected to override
   181   // this virtual member function.
   226   // this virtual member function.
   182   virtual int_type pbackfail(int_type = traits_type::eof());
   227   virtual int_type pbackfail(int_type = traits_type::eof()) {
   183 
   228       return _Traits::eof();                                    
   184 protected:                      // Virtual put area functions, as defined in
   229   }                                                             
   185                                 // 27.5.2.4.5 of the standard.
   230   
   186 
   231 
   187   // Writes up to __n characters.  Return value is the number of characters
   232 protected:                  // Virtual put area functions, as defined in
   188   // written.
   233                            // 27.5.2.4.5 of the standard.
   189   virtual streamsize xsputn(const char_type* __s, streamsize __n);
   234               
   190 
   235     // Writes up to __n characters.  Return value is the number of characters
   191   // Extension: writes up to __n copies of __c.  Return value is the number
   236   	// written.
       
   237 
       
   238     virtual streamsize xsputn(const char_type* __s, streamsize __n) {
       
   239       streamsize __result = 0;
       
   240       const int_type __eof = _Traits::eof();
       
   241 
       
   242       while (__result < __n) {
       
   243         if (_M_pnext < _M_pend) {
       
   244           size_t __chunk = (min) (__STATIC_CAST(size_t,_M_pend - _M_pnext),
       
   245                                __STATIC_CAST(size_t,__n - __result));
       
   246           _Traits::copy(_M_pnext, __s, __chunk);
       
   247           __result += __chunk;
       
   248           __s += __chunk;
       
   249           _M_pnext += __chunk;
       
   250         }
       
   251 
       
   252         else if (!_Traits::eq_int_type(this->overflow(_Traits::to_int_type(*__s)),
       
   253                                        __eof)) {
       
   254           ++__result;
       
   255           ++__s;
       
   256         }
       
   257         else
       
   258           break;
       
   259       }
       
   260       return __result;
       
   261   }
       
   262   
       
   263     // Extension: writes up to __n copies of __c.  Return value is the number
   192   // of characters written.
   264   // of characters written.
   193   virtual streamsize _M_xsputnc(char_type __c, streamsize __n);
   265 
   194 
   266   virtual streamsize _M_xsputnc(char_type __c, streamsize __n) {
   195   // Called when there is no write position.  All subclasses are expected to
   267       streamsize __result = 0;
       
   268       const int_type __eof = _Traits::eof();
       
   269 
       
   270       while (__result < __n) {
       
   271         if (_M_pnext < _M_pend) {
       
   272           size_t __chunk = (min) (__STATIC_CAST(size_t,_M_pend - _M_pnext),
       
   273                                __STATIC_CAST(size_t,__n - __result));
       
   274           _Traits::assign(_M_pnext, __chunk, __c);
       
   275           __result += __chunk;
       
   276           _M_pnext += __chunk;
       
   277         }
       
   278 
       
   279         else if (!_Traits::eq_int_type(this->overflow(_Traits::to_int_type(__c)),
       
   280                                        __eof))
       
   281           ++__result;
       
   282         else
       
   283           break;
       
   284       }
       
   285       return __result;
       
   286   }
       
   287   
       
   288     // Called when there is no write position.  All subclasses are expected to
   196   // override this virtual member function.
   289   // override this virtual member function.
   197   virtual int_type overflow(int_type = traits_type::eof());
   290 
       
   291   virtual int_type overflow(int_type = traits_type::eof()) {
       
   292       return _Traits::eof();                                  
       
   293   }                                                                 
       
   294   
   198 
   295 
   199 public:                         // Public members for writing characters.
   296 public:                         // Public members for writing characters.
   200   // Write a single character.
   297   // Write a single character.
   201   int_type sputc(char_type __c) {
   298   int_type sputc(char_type __c) {
   202     return ((_M_pnext < _M_pend) ? _Traits::to_int_type(*_M_pnext++ = __c)
   299     return ((_M_pnext < _M_pend) ? _Traits::to_int_type(*_M_pnext++ = __c)
   257 
   354 
   258   // This is a hook, called by pubimbue() just before pubimbue()
   355   // This is a hook, called by pubimbue() just before pubimbue()
   259   // sets the streambuf's locale to __loc.  Note that imbue should
   356   // sets the streambuf's locale to __loc.  Note that imbue should
   260   // not (and cannot, since it has no access to streambuf's private
   357   // not (and cannot, since it has no access to streambuf's private
   261   // members) set the streambuf's locale itself.
   358   // members) set the streambuf's locale itself.
   262   virtual void imbue(const locale&);
   359 
       
   360   virtual void imbue(const locale&) {}
   263 
   361 
   264 public:                         // Locale-related functions.
   362 public:                         // Locale-related functions.
   265   locale pubimbue(const locale&);
   363   locale pubimbue(const locale&);
   266   locale getloc() const { return _M_locale; }
   364   locale getloc() const { return _M_locale; }
   267 
   365