public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: sstream
@ 2000-03-24 16:08 Benjamin Kosnik
  2000-03-25  4:28 ` sstream Gerald Pfeifer
  0 siblings, 1 reply; 15+ messages in thread
From: Benjamin Kosnik @ 2000-03-24 16:08 UTC (permalink / raw)
  To: gcc, jbuck, pfeifer

> > Also, what mechanisms will v3 provide to allow syncing between stdio
> > and iostreams on platforms such as *BSD that don't use libio in their C
> > library?

Solaris doesn't use libio in its C library, and libstdc++-v3 supports
Solaris quite well. On these platforms we build a skeletal libio, and
use it, much like the current libstdc++-v2.

Does that answer your question?

> I didn't find anything about that on the libstdc++ web page and noticed
> that none of the BSDs is on the build matrix. Hopefully this doesn't mean
> we'll run into troubles on these platforms?

I'm interested in testing on BSD. Which one, in particular? I don't
have access to a BSD box, so that has kind of limited my testing.

-benjamin

^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: sstream
@ 2000-02-16 10:20 Benjamin Kosnik
  2000-02-16 10:31 ` sstream Joe Buck
  0 siblings, 1 reply; 15+ messages in thread
From: Benjamin Kosnik @ 2000-02-16 10:20 UTC (permalink / raw)
  To: gcc, magfr56

> I got so tired of not being able to use stringstreams that I wrote this. It 
> is probably not all according to the standard but it is a lot better than 
> the nothing that we have got currently. I suppose that I had been better of 
> working on libstdc++-v3 but this was faster.

v3 already has working stringstreams. Even standards-compliant
stringstreams. Perhaps you should use them?

-Benjamin

^ permalink raw reply	[flat|nested] 15+ messages in thread
* sstream
@ 2000-02-15 15:13 Magnus Fromreide
  2000-02-15 23:37 ` sstream Martin v. Loewis
  0 siblings, 1 reply; 15+ messages in thread
From: Magnus Fromreide @ 2000-02-15 15:13 UTC (permalink / raw)
  To: gcc

[-- Attachment #1: Type: text/plain, Size: 595 bytes --]

I got so tired of not being able to use stringstreams that I wrote this. It 
is probably not all according to the standard but it is a lot better than 
the nothing that we have got currently. I suppose that I had been better of 
working on libstdc++-v3 but this was faster.
I will write a copyright assignment and send as well if you wish to use the 
code.
It is in any case covered by GPL since it is derived from one of the other 
iostream headers but I suspect it is needed anyhow.
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

[-- Attachment #2: sstream --]
[-- Type: text/x-c++, Size: 4794 bytes --]

/* This is part of libio/iostream, providing -*- C++ -*- input/output.
Copyright (C) 2000 Free Software Foundation

This file is part of the GNU IO Library.  This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this library; see the file COPYING.  If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */

/* Written by Magnus Fromreide (magfr@lysator.liu.se). */

#ifndef __SSTREAM
#define __SSTREAM

#include <string>
#include <iostream.h>
#include <streambuf.h>

namespace std
{
  class stringstreambuf : public streambuf
  {
    std::string		buf;
    ios::open_mode	mode;
  protected:
    inline virtual int sync();
    inline virtual int overflow(int = EOF);
    inline virtual int underflow();
  public:
    stringstreambuf(int m=ios::in|ios::out) :
      buf(), mode(static_cast<ios::open_mode>(m))
    { }
	
    stringstreambuf(const std::string &s, int m=ios::in|ios::out) :
      buf(s), mode(static_cast<ios::open_mode>(m))
    { }
	
    _IO_ssize_t pcount() { return buf.size(); }
    std::string str() { sync(); return buf; };
    void str(const std::string& s)
    {
      pbump(pbase() - pptr());
      gbump(egptr() - gptr());
      buf = s;
    }
  };

  class stringstreambase : virtual public ios {
  protected:
    stringstreambuf __my_sb;
  public:
    std::string str() const
    { return dynamic_cast<stringstreambuf*>(_strbuf)->str(); }
    void str(const std::string& s)
    { return dynamic_cast<stringstreambuf*>(_strbuf)->str(s); }
	
    stringstreambuf* rdbuf() { return &__my_sb; }
  protected:
    stringstreambase(int m) :
      __my_sb(m)
    { init (&__my_sb); }
	
    stringstreambase(const std::string& s, int m) :
      __my_sb(s, m)
    { init (&__my_sb); }
  };
    
  class istringstream : public stringstreambase, public istream {
  public:
    istringstream(std::string& s) :
      stringstreambase(s, ios::in)
    { }
    void str(const std::string& s)
    { return dynamic_cast<stringstreambuf*>(_strbuf)->str(s); }	
  };
    
  class ostringstream : public stringstreambase, public ostream {
  public:
    ostringstream(int m=ios::out) :
      stringstreambase(m)
    { }
	
    ostringstream(const std::string& s, int m=ios::out) :
      stringstreambase(s, m)
    { }

    std::string str() const
    { return dynamic_cast<stringstreambuf*>(_strbuf)->str(); }
  };
    
  class stringstream : public stringstreambase, public iostream {
  public:
    stringstream(int m=ios::in|ios::out) :
      stringstreambase(m)
    { }
    stringstream(const std::string &s, int m=ios::in|ios::out) :
      stringstreambase(s, m)
    { }
	
    std::string str() const
    { return dynamic_cast<stringstreambuf*>(_strbuf)->str(); }
    void str(const std::string& s)
    { return dynamic_cast<stringstreambuf*>(_strbuf)->str(s); }
	
    _IO_ssize_t pcount()
    { return dynamic_cast<stringstreambuf*>(_strbuf)->pcount(); }
  };
}

inline int std::stringstreambuf::sync()
{
  if((mode & ios::out) == 0)
    return EOF;
  std::string::size_type oldSize = buf.size();
  std::string::size_type  n = pptr() - pbase();
  if(n)
    {
      buf.append(pbase(), pptr());
      if(buf.size() - oldSize != n)
	return EOF;
    }
  return 0;
}

inline int std::stringstreambuf::overflow(int ch)
{
  if((mode & ios::out) == 0)
    return EOF;
  streamsize n = pptr() - pbase();

  if(n && sync())
    return EOF;
  if(ch != EOF)
    {
      char cbuf[1];
      std::string::size_type oldSize = buf.size();
	
      cbuf[0] = ch;
      buf.append(cbuf, 1);
      if(buf.size() - oldSize != 1)
	return EOF;
    }
  pbump(-n);
  return 0;
}

inline int std::stringstreambuf::underflow()
{
  if((mode & ios::in) == 0)
    return EOF;
  std::string::size_type n = egptr() - eback();
  std::string::size_type s;
    
  if(buf.size() < n)
    s = buf.copy(egptr() - buf.size(), buf.size());
  else
    s = buf.copy(eback(), n);
  gbump(egptr() - gptr() - s);
  return 0;
}

#endif /*!__STRSTREAM_H*/

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2000-03-25 17:34 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-24 16:08 sstream Benjamin Kosnik
2000-03-25  4:28 ` sstream Gerald Pfeifer
2000-03-25 14:20   ` sstream Marc Espie
2000-03-25 17:34     ` sstream Joe Buck
  -- strict thread matches above, loose matches on Subject: below --
2000-02-16 10:20 sstream Benjamin Kosnik
2000-02-16 10:31 ` sstream Joe Buck
2000-02-21  0:22   ` sstream Jeffrey A Law
2000-02-21  0:48     ` sstream Martin v. Loewis
2000-02-21  9:19       ` sstream Joe Buck
2000-02-21 13:54         ` sstream Benjamin Scherrey
2000-02-21  9:33     ` sstream Joe Buck
2000-03-24 12:56       ` sstream Gerald Pfeifer
2000-03-24 13:15         ` sstream Joe Buck
2000-02-15 15:13 sstream Magnus Fromreide
2000-02-15 23:37 ` sstream Martin v. Loewis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).