[llvm-commits] [llvm] r55265 - in /llvm/trunk: include/llvm/Support/raw_ostream.h lib/Support/raw_ostream.cpp
Chris Lattner
sabre at nondot.org
Sat Aug 23 15:43:04 PDT 2008
Author: lattner
Date: Sat Aug 23 17:43:04 2008
New Revision: 55265
URL: http://llvm.org/viewvc/llvm-project?rev=55265&view=rev
Log:
Add raw_stream adaptors that write into an std::string and SmallVector/SmallString.
Modified:
llvm/trunk/include/llvm/Support/raw_ostream.h
llvm/trunk/lib/Support/raw_ostream.cpp
Modified: llvm/trunk/include/llvm/Support/raw_ostream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/raw_ostream.h?rev=55265&r1=55264&r2=55265&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/raw_ostream.h (original)
+++ llvm/trunk/include/llvm/Support/raw_ostream.h Sat Aug 23 17:43:04 2008
@@ -22,6 +22,8 @@
namespace llvm {
class format_object_base;
+ template <typename T>
+ class SmallVectorImpl;
/// raw_ostream - This class implements an extremely fast bulk output stream
/// that can *only* output to a stream. It does not support seeking, reopening,
@@ -192,7 +194,7 @@
//===----------------------------------------------------------------------===//
-// Bridge Output Streams
+// Output Stream Adaptors
//===----------------------------------------------------------------------===//
/// raw_os_ostream - A raw_ostream that writes to an std::ostream. This is a
@@ -208,6 +210,34 @@
/// buffer to empty.
virtual void flush_impl();
};
+
+/// raw_string_ostream - A raw_ostream that writes to an std::string. This is a
+/// simple adaptor class.
+class raw_string_ostream : public raw_ostream {
+ std::string &OS;
+public:
+ raw_string_ostream(std::string &O) : OS(O) {}
+ ~raw_string_ostream();
+
+ /// flush_impl - The is the piece of the class that is implemented by
+ /// subclasses. This outputs the currently buffered data and resets the
+ /// buffer to empty.
+ virtual void flush_impl();
+};
+
+/// raw_svector_ostream - A raw_ostream that writes to an SmallVector or
+/// SmallString. This is a simple adaptor class.
+class raw_svector_ostream : public raw_ostream {
+ SmallVectorImpl<char> &OS;
+public:
+ raw_svector_ostream(SmallVectorImpl<char> &O) : OS(O) {}
+ ~raw_svector_ostream();
+
+ /// flush_impl - The is the piece of the class that is implemented by
+ /// subclasses. This outputs the currently buffered data and resets the
+ /// buffer to empty.
+ virtual void flush_impl();
+};
} // end llvm namespace
Modified: llvm/trunk/lib/Support/raw_ostream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=55265&r1=55264&r2=55265&view=diff
==============================================================================
--- llvm/trunk/lib/Support/raw_ostream.cpp (original)
+++ llvm/trunk/lib/Support/raw_ostream.cpp Sat Aug 23 17:43:04 2008
@@ -268,3 +268,38 @@
OS.write(OutBufStart, OutBufCur-OutBufStart);
HandleFlush();
}
+
+//===----------------------------------------------------------------------===//
+// raw_string_ostream
+//===----------------------------------------------------------------------===//
+
+raw_string_ostream::~raw_string_ostream() {
+ flush();
+}
+
+/// flush_impl - The is the piece of the class that is implemented by
+/// subclasses. This outputs the currently buffered data and resets the
+/// buffer to empty.
+void raw_string_ostream::flush_impl() {
+ if (OutBufCur-OutBufStart)
+ OS.append(OutBufStart, OutBufCur-OutBufStart);
+ HandleFlush();
+}
+
+//===----------------------------------------------------------------------===//
+// raw_svector_ostream
+//===----------------------------------------------------------------------===//
+
+raw_svector_ostream::~raw_svector_ostream() {
+ flush();
+}
+
+/// flush_impl - The is the piece of the class that is implemented by
+/// subclasses. This outputs the currently buffered data and resets the
+/// buffer to empty.
+void raw_svector_ostream::flush_impl() {
+ if (OutBufCur-OutBufStart)
+ OS.append(OutBufStart, OutBufCur);
+ HandleFlush();
+}
+
More information about the llvm-commits
mailing list