Commit af5f8576 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: add reset() method to IStringStream

- for convenience and symmetry with OStringStream

STYLE: void return value for stream rewind() methods

- this makes it easier to design bidirectional streams
parent 74f667a8
......@@ -36,20 +36,22 @@ using namespace Foam;
int main(int argc, char *argv[])
{
IStringStream testStream(Foam::string("1002 sfsd sdfsd"));
IStringStream testStream(Foam::string(" 1002 abcd defg;"));
label i(readLabel(testStream));
Info<< i << endl;
Info<< "label=" << i << nl;
word bla(testStream);
word bla2(testStream);
word w1(testStream);
word w2(testStream);
Info<< bla << tab << bla2 << endl;
Info<< "word=" << w1 << nl;
Info<< "word=" << w2 << nl;
wordList wl(IStringStream("(hello1")());
testStream.reset("(hello1)");
Info<< wl << endl;
wordList wl(testStream);
Info<< wl << nl;
Info<< "\nEnd\n" << endl;
......
......@@ -167,7 +167,7 @@ const std::istream& Foam::IFstream::stdStream() const
}
Foam::Istream& Foam::IFstream::rewind()
void Foam::IFstream::rewind()
{
lineNumber_ = 1; // Reset line number
......@@ -195,8 +195,6 @@ Foam::Istream& Foam::IFstream::rewind()
{
ISstream::rewind();
}
return *this;
}
......
......@@ -130,7 +130,7 @@ public:
virtual const std::istream& stdStream() const;
//- Rewind the stream so that it may be read again
virtual Istream& rewind();
virtual void rewind();
// Print
......
......@@ -131,8 +131,8 @@ public:
//- Read binary block
virtual Istream& read(char*, std::streamsize) = 0;
//- Rewind and return the stream so that it may be read again
virtual Istream& rewind() = 0;
//- Rewind the stream so that it may be read again
virtual void rewind() = 0;
// Read List punctuation tokens
......
......@@ -329,10 +329,9 @@ Foam::Istream& Foam::UIPstream::read(char* data, std::streamsize count)
}
Foam::Istream& Foam::UIPstream::rewind()
void Foam::UIPstream::rewind()
{
externalBufPosition_ = 0;
return *this;
}
......
......@@ -171,8 +171,8 @@ public:
//- Read binary block with 8-byte alignment.
Istream& read(char* data, const std::streamsize count);
//- Rewind and return the stream so that it may be read again
Istream& rewind();
//- Rewind the stream so that it may be read again
void rewind();
// Edit
......
......@@ -798,7 +798,7 @@ Foam::Istream& Foam::ISstream::read(char* buf, std::streamsize count)
}
Foam::Istream& Foam::ISstream::rewind()
void Foam::ISstream::rewind()
{
lineNumber_ = 1; // Reset line number
......@@ -807,8 +807,6 @@ Foam::Istream& Foam::ISstream::rewind()
// pubseekpos() rather than seekg() so that it works with gzstream
stdStream().rdbuf()->pubseekpos(0, std::ios_base::in);
return *this;
}
......
......@@ -82,7 +82,7 @@ public:
// Constructors
//- Construct as wrapper around istream
//- Construct as wrapper around std::istream
inline ISstream
(
std::istream& is,
......@@ -163,8 +163,8 @@ public:
//- Read binary block
virtual Istream& read(char* buf, std::streamsize count);
//- Rewind and return the stream so that it may be read again
virtual Istream& rewind();
//- Rewind the stream so that it may be read again
virtual void rewind();
// Stream state functions
......
......@@ -69,7 +69,7 @@ public:
// Constructors
//- Construct and set stream status
//- Construct as wrapper around std::ostream and set stream status
OSstream
(
std::ostream& os,
......
......@@ -171,6 +171,13 @@ public:
//- Print description to Ostream
void print(Ostream& os) const;
//- Reset the input buffer and rewind the stream
void reset(const std::string& s)
{
this->str(s);
this->rewind();
}
// Member operators
......
......@@ -154,7 +154,7 @@ Foam::Istream& Foam::ITstream::read(char*, std::streamsize)
}
Foam::Istream& Foam::ITstream::rewind()
void Foam::ITstream::rewind()
{
tokenIndex_ = 0;
......@@ -164,8 +164,6 @@ Foam::Istream& Foam::ITstream::rewind()
}
setGood();
return *this;
}
......
......@@ -188,8 +188,8 @@ public:
//- Read binary block
virtual Istream& read(char*, std::streamsize);
//- Rewind and return the stream so that it may be read again
virtual Istream& rewind();
//- Rewind the stream so that it may be read again
virtual void rewind();
// Edit
......
......@@ -126,11 +126,10 @@ public:
return *this;
}
//- Rewind and return the stream so that it may be read again
virtual Istream& rewind()
//- Rewind the stream so that it may be read again
virtual void rewind()
{
NotImplemented;
return *this;
}
//- Return flags of stream
......
......@@ -127,8 +127,8 @@ public:
return *this;
}
//- Rewind and return the stream so that it may be read again
virtual Istream& rewind()
//- Rewind the stream so that it may be read again
virtual void rewind()
{
NotImplemented;
return *this;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment