Jpp
software
JLang
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
7
#include "
JLang/JAbstractObjectStatus.hh
"
8
9
10
/**
11
* \author mdejong
12
*/
13
14
namespace
JLANG
{}
15
namespace
JPP
{
using namespace
JLANG
; }
16
17
namespace
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
*/
24
class
JRedirectStream
:
25
public
JAbstractObjectStatus
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
*/
66
~JRedirectStream
()
67
{
68
ios
.rdbuf(
p
);
69
}
70
71
72
/**
73
* Get status of object.
74
*
75
* \return true
76
*/
77
virtual
bool
getStatus
()
const
78
{
79
return
true
;
80
}
81
82
private
:
83
std::ios&
ios
;
84
std::streambuf*
p
;
85
};
86
}
87
88
#endif
JLANG::JAbstractObjectStatus
Interface for status of object.
Definition:
JAbstractObjectStatus.hh:19
JLANG::JRedirectStream::JRedirectStream
JRedirectStream(std::istream &from, std::istream &to)
Constructor.
Definition:
JRedirectStream.hh:52
JLANG::JRedirectStream::~JRedirectStream
~JRedirectStream()
Destructor.
Definition:
JRedirectStream.hh:66
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition:
JAAnetToolkit.hh:37
JAbstractObjectStatus.hh
JLANG::JRedirectStream::ios
std::ios & ios
Definition:
JRedirectStream.hh:83
JLANG::JRedirectStream
This class can be used to temporarily redirect one output (input) stream to another output (input) st...
Definition:
JRedirectStream.hh:24
JLANG::JRedirectStream::JRedirectStream
JRedirectStream(std::ostream &from, std::ostream &to)
Constructor.
Definition:
JRedirectStream.hh:35
JLANG
Auxiliary classes and methods for language specific functionality.
Definition:
JAbstractClass.hh:10
JLANG::JRedirectStream::getStatus
virtual bool getStatus() const
Get status of object.
Definition:
JRedirectStream.hh:77
JLANG::JRedirectStream::p
std::streambuf * p
Definition:
JRedirectStream.hh:84
Generated by
1.8.16