Boost logo

Boost :

From: Joe Mariadassou (JMariadassou_at_[hidden])
Date: 2001-01-21 20:50:36


Dear Daryle Walker
Essentially I want to do this
//////////
  ofstream ofs("test.dat");
  MyPassThruBuffer buffer(*ofs.rdbuf);
  ostream ostr(buffer);
  ostr<<"hello World";
/////////
I would like to the string "hello world" to be transformed by
MyPassThruBuffer before it is
passed on to ofs. Without more_io I'll implement MyPassThruBuffer like this
(overriding only sync and overflow):
  class MyPassThruBuffer: public streambuf
{
  public:
 
   MyPassThruBuffer(streambuf& ostr);
  
    virtual ~MyPassThruBuffer() {
        sync();
    }

  protected:
    // flush the characters in the buffer
          // no error checking
    int flushBuffer (int const c);

    /* buffer full
     * - write c and all previous characters
     */
    virtual int_type overflow (int_type c) ;
   /* synchronize data with file/destination
     * - flush the data in the buffer
     */
    virtual int sync () ;
}
////////////////////////////
If I use more_io, I'll be doing this:
  ofstream ofs("test.dat");
  MyPassThruBuffer buffer(*ofs.rdbuf());
  ostream ostr(buffer);
  ostr<<"hello World";
//implenting MyPassThruBuffer like this
  class MyPassThruBuffer: public basic_passthrubuf
{
  public:
 
   MyPassThruBuffer(streambuf& ostr);
  virtual ~MyPassThruBuffer();
//// what members of basic_passthrubuf will I override?
};
//////////////////////
Now suppose I override only overflow and sync as before, and the client
calls xsputn. The output will landup straight into ofstream::streambuf's
xsputn which will in turn call its own version of overflow. So the data will
not pass through my filter.

Hope I am making myself clear.
regards
joe

-----Original Message-----
From: Daryle Walker [mailto:darylew_at_[hidden]]
Sent: Sunday, 21 January 2001 6:12 AM
To: boost_at_[hidden]
Subject: [boost] Re: more_io: Pass-through Stream-buffer Base Class
Where did you get the impression that every method had to be overridden?
Let me know so I can correct the code and/or docs.

As for an example, I should probably add one for version 5. (The main
problem is that I'm not an expert, so I don't know how to make good test
cases.)

-- 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk