llvm.org GIT mirror llvm / 6d53f55
Use setStream infomatted_raw_ostream's constructor, to reduce code duplication. Also, make setStream honor the old DeleteStream flag. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76075 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 11 years ago
1 changed file(s) with 9 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
7676 /// underneath it.
7777 ///
7878 formatted_raw_ostream(raw_ostream &Stream, bool Delete = false)
79 : raw_ostream(), TheStream(&Stream), DeleteStream(Delete), Column(0) {
80 // This formatted_raw_ostream inherits from raw_ostream, so it'll do its
81 // own buffering, and it doesn't need or want TheStream to do another
82 // layer of buffering underneath. Resize the buffer to what TheStream
83 // had been using, and tell TheStream not to do its own buffering.
84 TheStream->flush();
85 if (size_t BufferSize = TheStream->GetNumBytesInBuffer())
86 SetBufferSize(BufferSize);
87 TheStream->SetUnbuffered();
79 : raw_ostream(), TheStream(0), DeleteStream(false), Column(0) {
80 setStream(Stream, Delete);
8881 }
8982 explicit formatted_raw_ostream()
9083 : raw_ostream(), TheStream(0), DeleteStream(false), Column(0) {}
9588 }
9689
9790 void setStream(raw_ostream &Stream, bool Delete = false) {
91 if (DeleteStream)
92 delete TheStream;
93
9894 TheStream = &Stream;
9995 DeleteStream = Delete;
10096
101 // Avoid double-buffering, as above.
97 // This formatted_raw_ostream inherits from raw_ostream, so it'll do its
98 // own buffering, and it doesn't need or want TheStream to do another
99 // layer of buffering underneath. Resize the buffer to what TheStream
100 // had been using, and tell TheStream not to do its own buffering.
102101 TheStream->flush();
103102 if (size_t BufferSize = TheStream->GetNumBytesInBuffer())
104103 SetBufferSize(BufferSize);