Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
coutCapture.h
Go to the documentation of this file.
1/*
2 * Project: xRooFit
3 * Author:
4 * Will Buttinger, RAL 2022
5 *
6 * Copyright (c) 2022, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12
14 cout_redirect(std::string &_out, size_t bufSize = 102 * 1024) : out(_out)
15 {
16 old = std::cout.rdbuf(buffer.rdbuf());
17 old2 = std::cerr.rdbuf(buffer.rdbuf());
18 old3 = stdout;
19 buffer2 = (char *)calloc(sizeof(char), bufSize);
20 fp = fmemopen(buffer2, bufSize, "w");
21 stdout = fp;
22 }
24 {
25 std::cout.rdbuf(old);
26 std::cerr.rdbuf(old2);
27 std::fclose(fp);
28 stdout = old3;
29 out = buffer.str();
30 out += buffer2;
32 }
33
34private:
35 std::streambuf *old, *old2;
36 std::stringstream buffer;
37 char *buffer2;
38 FILE *fp;
39 FILE *old3;
40 std::string &out;
41};
#define free
Definition civetweb.c:1539
#define calloc
Definition civetweb.c:1537
cout_redirect(std::string &_out, size_t bufSize=102 *1024)
Definition coutCapture.h:14
std::streambuf * old
Definition coutCapture.h:35
std::stringstream buffer
Definition coutCapture.h:36
std::string & out
Definition coutCapture.h:40
std::streambuf * old2
Definition coutCapture.h:35