llvm.org GIT mirror llvm / 78a2812
Add raw_stream adaptors that write into an std::string and SmallVector/SmallString. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55265 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
2 changed file(s) with 66 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
2121
2222 namespace llvm {
2323 class format_object_base;
24 template
25 class SmallVectorImpl;
2426
2527 /// raw_ostream - This class implements an extremely fast bulk output stream
2628 /// that can *only* output to a stream. It does not support seeking, reopening,
191193
192194
193195 //===----------------------------------------------------------------------===//
194 // Bridge Output Streams
196 // Output Stream Adaptors
195197 //===----------------------------------------------------------------------===//
196198
197199 /// raw_os_ostream - A raw_ostream that writes to an std::ostream. This is a
207209 /// buffer to empty.
208210 virtual void flush_impl();
209211 };
212
213 /// raw_string_ostream - A raw_ostream that writes to an std::string. This is a
214 /// simple adaptor class.
215 class raw_string_ostream : public raw_ostream {
216 std::string &OS;
217 public:
218 raw_string_ostream(std::string &O) : OS(O) {}
219 ~raw_string_ostream();
220
221 /// flush_impl - The is the piece of the class that is implemented by
222 /// subclasses. This outputs the currently buffered data and resets the
223 /// buffer to empty.
224 virtual void flush_impl();
225 };
226
227 /// raw_svector_ostream - A raw_ostream that writes to an SmallVector or
228 /// SmallString. This is a simple adaptor class.
229 class raw_svector_ostream : public raw_ostream {
230 SmallVectorImpl &OS;
231 public:
232 raw_svector_ostream(SmallVectorImpl &O) : OS(O) {}
233 ~raw_svector_ostream();
234
235 /// flush_impl - The is the piece of the class that is implemented by
236 /// subclasses. This outputs the currently buffered data and resets the
237 /// buffer to empty.
238 virtual void flush_impl();
239 };
210240
211241 } // end llvm namespace
212242
267267 OS.write(OutBufStart, OutBufCur-OutBufStart);
268268 HandleFlush();
269269 }
270
271 //===----------------------------------------------------------------------===//
272 // raw_string_ostream
273 //===----------------------------------------------------------------------===//
274
275 raw_string_ostream::~raw_string_ostream() {
276 flush();
277 }
278
279 /// flush_impl - The is the piece of the class that is implemented by
280 /// subclasses. This outputs the currently buffered data and resets the
281 /// buffer to empty.
282 void raw_string_ostream::flush_impl() {
283 if (OutBufCur-OutBufStart)
284 OS.append(OutBufStart, OutBufCur-OutBufStart);
285 HandleFlush();
286 }
287
288 //===----------------------------------------------------------------------===//
289 // raw_svector_ostream
290 //===----------------------------------------------------------------------===//
291
292 raw_svector_ostream::~raw_svector_ostream() {
293 flush();
294 }
295
296 /// flush_impl - The is the piece of the class that is implemented by
297 /// subclasses. This outputs the currently buffered data and resets the
298 /// buffer to empty.
299 void raw_svector_ostream::flush_impl() {
300 if (OutBufCur-OutBufStart)
301 OS.append(OutBufStart, OutBufCur);
302 HandleFlush();
303 }
304