gramods
Loading...
Searching...
No Matches
ScopedOStreamRedirect.hh
1
7#ifndef GRAMODS_CORE_SCOPEDOSTREAMREDIRECT
8#define GRAMODS_CORE_SCOPEDOSTREAMREDIRECT
9
10#include <gmCore/config.hh>
11
12BEGIN_NAMESPACE_GMCORE;
13
19
20public:
21
26 ScopedOStreamRedirect(std::ostream & inOriginal, std::ostream & inRedirect) :
27 mOriginal(inOriginal),
28 mOldBuffer(inOriginal.rdbuf(inRedirect.rdbuf())) {}
29
34 mOriginal.rdbuf(mOldBuffer);
35 }
36
38
39 ScopedOStreamRedirect& operator=(const ScopedOStreamRedirect&) = delete;
40
41private:
42
43 std::ostream & mOriginal;
44 std::streambuf * mOldBuffer;
45};
46
47END_NAMESPACE_GMCORE;
48
49#endif
Utility for temporary redirection of an ostream, for example to temporarily change the target of std:...
Definition ScopedOStreamRedirect.hh:18
ScopedOStreamRedirect(std::ostream &inOriginal, std::ostream &inRedirect)
Sets up an object that, until destroyed, redirects the first argument to the target of the second arg...
Definition ScopedOStreamRedirect.hh:26
~ScopedOStreamRedirect()
Sets back the original target of the redirected ostream.
Definition ScopedOStreamRedirect.hh:33