1 //===-- StreamWrapper.cpp -------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "StreamWrapper.h" 10 #include <cassert> 11 #include <fstream> 12 #include <iostream> 13 #include <memory> 14 #include <string> 15 16 namespace __llvm_libc { 17 namespace testutils { 18 19 StreamWrapper outs() { return {std::addressof(std::cout)}; } 20 21 template <typename T> StreamWrapper &StreamWrapper::operator<<(T t) { 22 assert(os); 23 std::ostream &Stream = *reinterpret_cast<std::ostream *>(os); 24 Stream << t; 25 Stream.flush(); 26 return *this; 27 } 28 29 template StreamWrapper &StreamWrapper::operator<<<void *>(void *t); 30 template StreamWrapper &StreamWrapper::operator<<<const char *>(const char *t); 31 template StreamWrapper &StreamWrapper::operator<<<char *>(char *t); 32 template StreamWrapper &StreamWrapper::operator<<<char>(char t); 33 template StreamWrapper &StreamWrapper::operator<<<short>(short t); 34 template StreamWrapper &StreamWrapper::operator<<<int>(int t); 35 template StreamWrapper &StreamWrapper::operator<<<long>(long t); 36 template StreamWrapper &StreamWrapper::operator<<<long long>(long long t); 37 template StreamWrapper & 38 StreamWrapper::operator<<<unsigned char>(unsigned char t); 39 template StreamWrapper & 40 StreamWrapper::operator<<<unsigned short>(unsigned short t); 41 template StreamWrapper &StreamWrapper::operator<<<unsigned int>(unsigned int t); 42 template StreamWrapper & 43 StreamWrapper::operator<<<unsigned long>(unsigned long t); 44 template StreamWrapper & 45 StreamWrapper::operator<<<unsigned long long>(unsigned long long t); 46 template StreamWrapper &StreamWrapper::operator<<<bool>(bool t); 47 template StreamWrapper &StreamWrapper::operator<<<std::string>(std::string t); 48 template StreamWrapper &StreamWrapper::operator<<<float>(float t); 49 template StreamWrapper &StreamWrapper::operator<<<double>(double t); 50 51 OutputFileStream::OutputFileStream(const char *FN) 52 : StreamWrapper(new std::ofstream(FN)) {} 53 54 OutputFileStream::~OutputFileStream() { 55 delete reinterpret_cast<std::ofstream *>(os); 56 } 57 58 } // namespace testutils 59 } // namespace __llvm_libc 60