ENH: added OStringStream reset method (closes #534)

- resets the output buffer completely - implementing what rewind was
  likely meant to have accomplished for many use cases.

STYLE: OSHA1stream reset() for symmetry. Deprecate rewind().
This commit is contained in:
Mark Olesen
2017-07-17 18:32:42 +02:00
parent 86ef9e86dc
commit b4b50a3aa8
7 changed files with 47 additions and 15 deletions

View File

@ -52,9 +52,11 @@ int main(int argc, char *argv[])
Info<< "overwrite with short string:" << nl Info<< "overwrite with short string:" << nl
<< os.str() << endl; << os.str() << endl;
// os.reset(); os.reset();
// Info<< "after reset:" << nl os << "%%%% reset";
// << os.str() << endl;
Info<< "after reset:" << nl
<< os.str() << endl;
Info<< "End\n" << endl; Info<< "End\n" << endl;

View File

@ -47,8 +47,24 @@ int main(int argc, char *argv[])
IOWarningInFunction(dict) << "warning 3" << endl; IOWarningInFunction(dict) << "warning 3" << endl;
FatalErrorInFunction << "error 1" << endl; FatalErrorInFunction
FatalErrorInFunction << "error 2" << exit(FatalError); << "This is an error from 1" << nl
<< "Explanation to follow:" << endl;
FatalErrorInFunction
<< "Error 2"
<< exit(FatalError);
}
catch (Foam::error& fErr)
{
Serr<< "Caught Foam error " << fErr << nl << endl;
}
try
{
FatalErrorInFunction
<< "Error# 3"
<< exit(FatalError);
} }
catch (Foam::error& fErr) catch (Foam::error& fErr)
{ {

View File

@ -96,7 +96,7 @@ int main(int argc, char * argv[])
os << str; os << str;
Info<< os.digest() << endl; Info<< os.digest() << endl;
os.rewind(); os.reset();
os << "The quick brown fox jumps over the lazy dog"; os << "The quick brown fox jumps over the lazy dog";
Info<< os.digest() << endl; Info<< os.digest() << endl;
} }

View File

@ -223,6 +223,13 @@ public:
// Member Functions // Member Functions
//- Reset the output buffer and rewind the stream
void reset()
{
this->str(""); // No other way to reset the end
this->rewind();
}
//- Rewind the output stream //- Rewind the output stream
void rewind() void rewind()
{ {

View File

@ -226,7 +226,7 @@ public:
// Access // Access
//- Return SHA1::Digest for the data processed until now //- Return SHA1::Digest for the data processed until now
Foam::SHA1Digest digest() SHA1Digest digest()
{ {
return sha1().digest(); return sha1().digest();
} }
@ -235,6 +235,13 @@ public:
// Edit // Edit
//- Clear the SHA1 calculation //- Clear the SHA1 calculation
void reset()
{
sha1().clear();
}
//- Clear the SHA1 calculation
// \deprecated use reset instead (deprecated Jul 2017)
void rewind() void rewind()
{ {
sha1().clear(); sha1().clear();

View File

@ -193,8 +193,8 @@ void Foam::IOerror::exit(const int)
// Make a copy of the error to throw // Make a copy of the error to throw
IOerror errorException(*this); IOerror errorException(*this);
// Rewind the message buffer for the next error message // Reset the message buffer for the next error message
messageStreamPtr_->rewind(); messageStreamPtr_->reset();
throw errorException; throw errorException;
} }
@ -238,8 +238,8 @@ void Foam::IOerror::abort()
// Make a copy of the error to throw // Make a copy of the error to throw
IOerror errorException(*this); IOerror errorException(*this);
// Rewind the message buffer for the next error message // Reset the message buffer for the next error message
messageStreamPtr_->rewind(); messageStreamPtr_->reset();
throw errorException; throw errorException;
} }

View File

@ -188,8 +188,8 @@ void Foam::error::exit(const int errNo)
// Make a copy of the error to throw // Make a copy of the error to throw
error errorException(*this); error errorException(*this);
// Rewind the message buffer for the next error message // Reset the message buffer for the next error message
messageStreamPtr_->rewind(); messageStreamPtr_->reset();
throw errorException; throw errorException;
} }
@ -233,8 +233,8 @@ void Foam::error::abort()
// Make a copy of the error to throw // Make a copy of the error to throw
error errorException(*this); error errorException(*this);
// Rewind the message buffer for the next error message // Reset the message buffer for the next error message
messageStreamPtr_->rewind(); messageStreamPtr_->reset();
throw errorException; throw errorException;
} }