streambuf, yet again

Discussion in 'C++' started by Christopher Benson-Manica, Feb 26, 2004.

  1. Is there any way to prevent the streambuf from calling overflow or
    xsputn unless I specifically flush the stream?

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
    Christopher Benson-Manica, Feb 26, 2004
    #1
    1. Advertising

  2. "Christopher Benson-Manica" <> wrote in message
    news:c1lil3$508$...
    > Is there any way to prevent the streambuf from calling overflow or
    > xsputn unless I specifically flush the stream?
    >


    Its ostream that calls overflow or xsputn.

    I can't think of any reasonable way to achieve that, but I could easily be
    wrong. But I am sure it would be better to code this so that you don't much
    care when overflow or xsputn is called. Why exactly does it matter?

    Is your stream working now then? What was the problem? Before you were
    complaining that overflow wasn't being called at all, not you are
    complaining that its being called to often!

    john
    John Harrison, Feb 26, 2004
    #2
    1. Advertising

  3. John Harrison <> spoke thus:

    > I can't think of any reasonable way to achieve that, but I could easily be
    > wrong. But I am sure it would be better to code this so that you don't much
    > care when overflow or xsputn is called. Why exactly does it matter?


    Well, this is a deficiency of the class I'm trying to wrap -
    TLSFile::Write() appends a '\n' to its argument before actually
    writing to the file. So I have to code around it, convince my boss to
    change that behavior (he seemed reluctant this morning), or just
    forget wrapping the class with a stream at all.

    > Is your stream working now then? What was the problem? Before you were
    > complaining that overflow wasn't being called at all, not you are
    > complaining that its being called to often!


    Well, it kind of is. It turns out that the first time through the
    section of code in question, nothing happens. On subsequent trips
    through that section of code, however, things work as expected
    (although not as I would want - see above). Does that sound like a
    specific kind of mistake to you?

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
    Christopher Benson-Manica, Feb 26, 2004
    #3
  4. "Christopher Benson-Manica" <> wrote in message
    news:c1ljgp$55f$...
    > John Harrison <> spoke thus:
    >
    > > I can't think of any reasonable way to achieve that, but I could easily

    be
    > > wrong. But I am sure it would be better to code this so that you don't

    much
    > > care when overflow or xsputn is called. Why exactly does it matter?

    >
    > Well, this is a deficiency of the class I'm trying to wrap -
    > TLSFile::Write() appends a '\n' to its argument before actually
    > writing to the file. So I have to code around it, convince my boss to
    > change that behavior (he seemed reluctant this morning), or just
    > forget wrapping the class with a stream at all.


    Hmm awkward. And some people claim that object orientation promotes reusable
    code. I'd work on your boss if I were you.

    What you can do is create a real buffer (instead of using the unbuffered
    mode you are using now). See Josuttis for details. Then when the buffer is
    full and overflow is called you scan the characters in the buffer for
    newlines. If you find any you can call TLSFile::Write with the characters
    before the newline and just drop the newline. You won't be able to empty the
    buffer entirely, just the portion that is before the last newline, but that
    isn't a problem. If when overflow is called and the buffer is full and there
    isn't a single newline in it, then you are either going to have to output a
    spurious newline, or you are going to have to expand the buffer.

    >
    > > Is your stream working now then? What was the problem? Before you were
    > > complaining that overflow wasn't being called at all, not you are
    > > complaining that its being called to often!

    >
    > Well, it kind of is. It turns out that the first time through the
    > section of code in question, nothing happens. On subsequent trips
    > through that section of code, however, things work as expected
    > (although not as I would want - see above). Does that sound like a
    > specific kind of mistake to you?
    >


    Sorry, it doesn't.

    john
    John Harrison, Feb 26, 2004
    #4
    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. Kevin Blakeley

    Export to a Datagrid, YET AGAIN!

    Kevin Blakeley, Jun 25, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,421
    George Durzi
    Jun 25, 2003
  2. Richard Myers

    ASP.Net Worker Process Drops Out Yet Again!

    Richard Myers, Dec 2, 2004, in forum: ASP .Net
    Replies:
    11
    Views:
    1,409
    Richard Myers
    Dec 3, 2004
  3. Peter Jansson
    Replies:
    1
    Views:
    511
    David Rubin
    Nov 8, 2004
  4. Berehem
    Replies:
    4
    Views:
    553
    Lawrence Kirby
    Apr 28, 2005
  5. Christopher Pisz
    Replies:
    2
    Views:
    599
    James Kanze
    Dec 12, 2007
Loading...

Share This Page