std::streambuf::setp and std::streambuf::epptr()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christopher Pisz

    #1

    std::streambuf::setp and std::streambuf::epptr()

    I am trying to empty and reset my internal buffer in my derived sync method.

    Am I correct in assuming I can call setp( std::streambuf: :pbase(),
    std::streambuf: :pbase()); to reset the internal buffer?

    Also, I am unsure whether the pointer returned by epptr() is supposed to
    point just beyond the end of the sequence or at the last element of the
    sequence? As such, should the second argument to my setp call be
    std::streambuf: :pbase() + 1?

    Thanks. I've got a book on streams coming for Christmas by the way. Yay!
    References on the topic seem to be scarce, yet it is such a huge topic. I
    guess most people ignore it as much as they can.


  • James Kanze

    #2
    Re: std::streambuf: :setp and std::streambuf: :epptr()

    On Dec 12, 9:12 am, "Christophe r Pisz" <some...@somewh ere.netwrote:
    I am trying to empty and reset my internal buffer in my
    derived sync method.
    Am I correct in assuming I can call setp( std::streambuf: :pbase(),
    std::streambuf: :pbase()); to reset the internal buffer?
    It depends on what you want to do. If you simply want to clear
    the buffer, making sure that the next attempt to write will end
    up calling overflow() (where presumably, you'll reinitialize
    it), then setting both pointers to NULL is the simplest
    solution. If you want to initialize a new (empty) buffer, the
    first pointer should be the address of the buffer, and the
    second the address one past the end of the buffer.
    Also, I am unsure whether the pointer returned by epptr() is
    supposed to point just beyond the end of the sequence or at
    the last element of the sequence?
    One past the end. epptr() - pbase() is the length of the
    buffer.
    As such, should the second argument to my setp call be
    std::streambuf: :pbase() + 1?
    That would provide a buffer of size 1.

    --
    James Kanze (GABI Software) email:james.kan ze@gmail.com
    Conseils en informatique orientée objet/
    Beratung in objektorientier ter Datenverarbeitu ng
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

    Comment

    Working...