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

P

Peter Jansson

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/
 
D

David Rubin

Peter Jansson said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top