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
<< os.str() << endl;
// os.reset();
// Info<< "after reset:" << nl
// << os.str() << endl;
os.reset();
os << "%%%% reset";
Info<< "after reset:" << nl
<< os.str() << endl;
Info<< "End\n" << endl;

View File

@ -47,8 +47,24 @@ int main(int argc, char *argv[])
IOWarningInFunction(dict) << "warning 3" << endl;
FatalErrorInFunction << "error 1" << endl;
FatalErrorInFunction << "error 2" << exit(FatalError);
FatalErrorInFunction
<< "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)
{

View File

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

View File

@ -223,6 +223,13 @@ public:
// 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
void rewind()
{

View File

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

View File

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

View File

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