Custom output stream

Discussion in 'C++' started by Derek, Aug 28, 2006.

  1. Derek

    Derek Guest

    >From reading countless posts here I seem to get the impression that to
    roll your own output stream class, the minimum you would likely needed
    to do would be to override the overflow() method, as it is apparently
    the default action of sync() is to call overflow(EOF).

    In my own testing under Linux with g++, it appears that it is the
    sync() method that needs to be overridden, as it does not appear to
    default to calling overflow(EOF)... but overflow() certainly appears to
    default in calling sync() when it needs more room.

    Is this a "bug" with g++, or have I been mistaken in my intepretation
    of the general consensus here?
     
    Derek, Aug 28, 2006
    #1
    1. Advertising

  2. Derek

    Bo Persson Guest

    "Derek" <> skrev i meddelandet
    news:...
    > >From reading countless posts here I seem to get the impression that
    > >to

    > roll your own output stream class, the minimum you would likely
    > needed
    > to do would be to override the overflow() method, as it is
    > apparently
    > the default action of sync() is to call overflow(EOF).


    That is for basic_filebuf, but not for basic_streambuf. The filebuf is
    possibly buffered, so it might need a sync() to force the buffer out
    (to disk perhaps?).

    Other streams might not be buffered.

    >
    > In my own testing under Linux with g++, it appears that it is the
    > sync() method that needs to be overridden, as it does not appear to
    > default to calling overflow(EOF)... but overflow() certainly appears
    > to
    > default in calling sync() when it needs more room.


    At what level are you overriding?

    In basic_streambuf, the default sync() does nothing, and overflow()
    returns eof immediately. You must override whatever virtual functions
    you need, to implement your special stream buffer. Exactly which ones
    depends on what you are interfacing to.

    >
    > Is this a "bug" with g++, or have I been mistaken in my
    > intepretation
    > of the general consensus here?
    >


    Not really.


    Bo Persson
     
    Bo Persson, Aug 28, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rasmusson, Lars
    Replies:
    1
    Views:
    776
    popov
    Apr 30, 2004
  2. Replies:
    9
    Views:
    665
    Alex Buell
    Apr 27, 2006
  3. Alexander Korsunsky

    get stream mode flags from an opened stream

    Alexander Korsunsky, Feb 17, 2007, in forum: C++
    Replies:
    1
    Views:
    468
    John Harrison
    Feb 17, 2007
  4. dolphin
    Replies:
    6
    Views:
    581
    Thomas Fritsch
    Mar 18, 2007
  5. Kashif Ur Rehman
    Replies:
    2
    Views:
    888
    Tom Hawtin
    May 17, 2007
Loading...

Share This Page