llvm.org GIT mirror llvm / 32e1eef
split raw_os_ostream out to its own header and implementation file. This means that raw_ostream no longer has to #include <iosfwd>. Nothing in llvm should use raw_os_ostream.h, but llvm-gcc and some unit tests do. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79886 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
6 changed file(s) with 74 addition(s) and 35 deletion(s). Raw diff Collapse all Expand all
0 //===- raw_os_ostream.h - std::ostream adaptor for raw_ostream --*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the raw_os_ostream class.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_SUPPORT_RAW_OS_OSTREAM_H
14 #define LLVM_SUPPORT_RAW_OS_OSTREAM_H
15
16 #include "llvm/Support/raw_ostream.h"
17 #include
18
19 namespace llvm {
20
21 /// raw_os_ostream - A raw_ostream that writes to an std::ostream. This is a
22 /// simple adaptor class. It does not check for output errors; clients should
23 /// use the underlying stream to detect errors.
24 class raw_os_ostream : public raw_ostream {
25 std::ostream &OS;
26
27 /// write_impl - See raw_ostream::write_impl.
28 virtual void write_impl(const char *Ptr, size_t Size);
29
30 /// current_pos - Return the current position within the stream, not
31 /// counting the bytes currently in the buffer.
32 virtual uint64_t current_pos();
33
34 public:
35 raw_os_ostream(std::ostream &O) : OS(O) {}
36 ~raw_os_ostream();
37 };
38
39 } // end llvm namespace
40
41 #endif
1414 #define LLVM_SUPPORT_RAW_OSTREAM_H
1515
1616 #include "llvm/ADT/StringRef.h"
17 #include
1817
1918 namespace llvm {
2019 class format_object_base;
406405 // Output Stream Adaptors
407406 //===----------------------------------------------------------------------===//
408407
409 /// raw_os_ostream - A raw_ostream that writes to an std::ostream. This is a
410 /// simple adaptor class. It does not check for output errors; clients should
411 /// use the underlying stream to detect errors.
412 class raw_os_ostream : public raw_ostream {
413 std::ostream &OS;
414
415 /// write_impl - See raw_ostream::write_impl.
416 virtual void write_impl(const char *Ptr, size_t Size);
417
418 /// current_pos - Return the current position within the stream, not
419 /// counting the bytes currently in the buffer.
420 virtual uint64_t current_pos();
421
422 public:
423 raw_os_ostream(std::ostream &O) : OS(O) {}
424 ~raw_os_ostream();
425 };
426
427408 /// raw_string_ostream - A raw_ostream that writes to an std::string. This is a
428409 /// simple adaptor class. This class does not encounter output errors.
429410 class raw_string_ostream : public raw_ostream {
0 //===--- raw_os_ostream.cpp - Implement the raw_os_ostream class ----------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This implements support adapting raw_ostream to std::ostream.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/Support/raw_os_ostream.h"
14 #include
15 using namespace llvm;
16
17 //===----------------------------------------------------------------------===//
18 // raw_os_ostream
19 //===----------------------------------------------------------------------===//
20
21 raw_os_ostream::~raw_os_ostream() {
22 flush();
23 }
24
25 void raw_os_ostream::write_impl(const char *Ptr, size_t Size) {
26 OS.write(Ptr, Size);
27 }
28
29 uint64_t raw_os_ostream::current_pos() { return OS.tellp(); }
1919 #include "llvm/Support/Compiler.h"
2020 #include "llvm/Support/ErrorHandling.h"
2121 #include "llvm/ADT/StringExtras.h"
22 #include
2322 #include
2423 #include
2524
484483 return S;
485484 }
486485
487 //===----------------------------------------------------------------------===//
488 // raw_os_ostream
489 //===----------------------------------------------------------------------===//
490
491 raw_os_ostream::~raw_os_ostream() {
492 flush();
493 }
494
495 void raw_os_ostream::write_impl(const char *Ptr, size_t Size) {
496 OS.write(Ptr, Size);
497 }
498
499 uint64_t raw_os_ostream::current_pos() { return OS.tellp(); }
500486
501487 //===----------------------------------------------------------------------===//
502488 // raw_string_ostream
77 //===----------------------------------------------------------------------===//
88
99 #include
10 #include "llvm/Support/raw_ostream.h"
10 #include "llvm/Support/raw_os_ostream.h"
1111 #include "gtest/gtest.h"
1212 #include "llvm/ADT/APInt.h"
1313 #include "llvm/ADT/SmallString.h"
77 //===----------------------------------------------------------------------===//
88
99 #include "llvm/Support/ConstantRange.h"
10 #include "llvm/Support/raw_ostream.h"
10 #include "llvm/Support/raw_os_ostream.h"
1111
1212 #include "gtest/gtest.h"
1313