aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Catania <niko@google.com>2010-02-03 15:43:36 -0800
committerNicolas Catania <niko@google.com>2010-02-03 15:43:36 -0800
commite5b7af0c3c5af401b46d34987cbd8a65f45454de (patch)
tree459d4e0ccd997fabdbf656a1a5c9632e41732261
parentd1e702c1f745428a7bc53cbbd80b0c283ca52de1 (diff)
downloadastl-e5b7af0c3c5af401b46d34987cbd8a65f45454de.tar.gz
Added support for endl ends and flush.
-rw-r--r--include/ostream20
-rw-r--r--src/ostream.cpp7
-rw-r--r--tests/test_iostream.cpp7
3 files changed, 34 insertions, 0 deletions
diff --git a/include/ostream b/include/ostream
index ec2817e..35ff8dc 100644
--- a/include/ostream
+++ b/include/ostream
@@ -73,8 +73,28 @@ class ostream: public basic_ios
}
ostream& operator<<(const char_type *str);
+
+ /**
+ * Tries to insert a char.
+ */
+ ostream& put(char_type c);
};
+/**
+ * Flushes the output stream.
+ */
+inline ostream& flush(ostream& os) { return os.flush(); }
+
+/**
+ * Write a newline and flush the stream.
+ */
+inline ostream& endl(ostream& os) { return flush(os.put('\n')); }
+
+/**
+ * Write a null character into the output sequence.
+ */
+inline ostream& ends(ostream& os) { return os.put(char()); }
+
} // namespace std
#endif
diff --git a/src/ostream.cpp b/src/ostream.cpp
index d3efafd..fff02ef 100644
--- a/src/ostream.cpp
+++ b/src/ostream.cpp
@@ -44,6 +44,13 @@ ostream& ostream::operator<<(const char_type *str) {
return *this;
}
+ostream& ostream::put(char_type c) {
+ if (this->rdbuf()) {
+ this->rdbuf()->sputn(&c, 1);
+ }
+ return *this;
+}
+
ostream& ostream::flush() {
if (this->rdbuf()) {
// TODO: if pubsync returns -1 should mark this stream as
diff --git a/tests/test_iostream.cpp b/tests/test_iostream.cpp
index 3477fc6..a3437a2 100644
--- a/tests/test_iostream.cpp
+++ b/tests/test_iostream.cpp
@@ -71,11 +71,18 @@ bool testCoutCerr() {
return true;
}
+bool testManip() {
+ std::cout << "line 1" << std::endl
+ << " a nul char |" << std::ends << std::flush << "| in line 2.";
+ return true;
+}
+
} // namespace android
int main(int argc, char **argv){
FAIL_UNLESS(testStaticInit);
FAIL_UNLESS(testOstream);
FAIL_UNLESS(testCoutCerr);
+ FAIL_UNLESS(testManip);
return kPassed;
}