Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JRedirectStream.hh
Go to the documentation of this file.
1#ifndef __JLANG__JREDIRECTSTREAM__
2#define __JLANG__JREDIRECTSTREAM__
3
4#include <istream>
5#include <ostream>
6
8
9
10/**
11 * \author mdejong
12 */
13
14namespace JLANG {}
15namespace JPP { using namespace JLANG; }
16
17namespace JLANG {
18
19
20 /**
21 * This class can be used to temporarily redirect one output (input) stream to another output (input) stream.
22 * The destructor restores the internal buffer of the first output (input) stream.
23 */
26 {
27 public:
28 /**
29 * Constructor.
30 * The output stream from is redirected to output stream to.
31 *
32 * \param from output stream
33 * \param to output stream
34 */
35 JRedirectStream(std::ostream& from,
36 std::ostream& to) :
37 ios(from)
38 {
39 p = ios.rdbuf();
40
41 ios.rdbuf(to.rdbuf());
42 }
43
44
45 /**
46 * Constructor.
47 * The input stream from is redirected to input stream to.
48 *
49 * \param from input stream
50 * \param to input stream
51 */
52 JRedirectStream(std::istream& from,
53 std::istream& to) :
54 ios(from)
55 {
56 p = ios.rdbuf();
57
58 ios.rdbuf(to.rdbuf());
59 }
60
61
62 /**
63 * Destructor.
64 * Restore internal buffer.
65 */
67 {
68 ios.rdbuf(p);
69 }
70
71
72 /**
73 * Get status of object.
74 *
75 * \return true
76 */
77 virtual bool getStatus() const override
78 {
79 return true;
80 }
81
82 private:
83 std::ios& ios;
84 std::streambuf* p;
85
90 };
91}
92
93#endif
This class can be used to temporarily redirect one output (input) stream to another output (input) st...
JRedirectStream(std::ostream &from, std::ostream &to)
Constructor.
JRedirectStream & operator=(const JRedirectStream &)
JRedirectStream(std::istream &from, std::istream &to)
Constructor.
JRedirectStream & operator=(JRedirectStream &&)
virtual bool getStatus() const override
Get status of object.
JRedirectStream(const JRedirectStream &)
JRedirectStream(JRedirectStream &&)
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Interface for status of object.