std::streambuf::setg & std::streambuf::setp success or not?

Discussion in 'C++' started by Peter Jansson, Nov 6, 2004.

  1. Dear newsgroup,

    I have implemented a class that inherits from std::streambuf (in order to
    create a stream for some specialized I/O). In the constructor, I have the
    following code (bufferSize is a previously defined const unsigned int):

    char* p1=new char[bufferSize];
    std::streambuf::setg(p1,p1,p1+bufferSize);
    char* p2=new char[bufferSize];
    std::streambuf::setp(p2,p2+bufferSize);

    Do anybody know of any way to test if setg and/or setp was successful or
    not? (They are both returning void and are not throwing any exceptions,
    according to sections 27.5.2.3.1 and 27.5.2.3.2 in the standard.) Should,
    perhaps, the postconditions be used for this?

    Regards,
    Peter Jansson
    http://www.jansson.net/
     
    Peter Jansson, Nov 6, 2004
    #1
    1. Advertising

  2. Peter Jansson

    David Rubin Guest

    Peter Jansson <> wrote in message news:<>...
    > Dear newsgroup,
    >
    > I have implemented a class that inherits from std::streambuf (in order to
    > create a stream for some specialized I/O). In the constructor, I have the
    > following code (bufferSize is a previously defined const unsigned int):
    >
    > char* p1=new char[bufferSize];
    > std::streambuf::setg(p1,p1,p1+bufferSize);
    > char* p2=new char[bufferSize];
    > std::streambuf::setp(p2,p2+bufferSize);
    >
    > Do anybody know of any way to test if setg and/or setp was successful or
    > not? (They are both returning void and are not throwing any exceptions,
    > according to sections 27.5.2.3.1 and 27.5.2.3.2 in the standard.) Should,
    > perhaps, the postconditions be used for this?


    You can check 'eback', 'egptr', 'pbase', and 'epptr'. However, I'm not
    sure that these functions can actually fail since they just assign
    pointers (hence the 'void' return value). /david
     
    David Rubin, Nov 8, 2004
    #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. john

    SETP-07 Call for papers

    john, Feb 3, 2007, in forum: Java
    Replies:
    0
    Views:
    298
  2. Johannes Barop
    Replies:
    1
    Views:
    445
    JH Trauntvein
    Dec 29, 2005
  3. Christopher Pisz
    Replies:
    2
    Views:
    606
    James Kanze
    Dec 12, 2007
  4. john
    Replies:
    0
    Views:
    348
  5. john
    Replies:
    0
    Views:
    295
Loading...

Share This Page