Jpp
software
JLang
JRedirectString.hh
Go to the documentation of this file.
1
#ifndef __JLANG__JREDIRECTSTRING__
2
#define __JLANG__JREDIRECTSTRING__
3
4
#include <istream>
5
#include <ostream>
6
#include <string>
7
#include <sstream>
8
9
#include "
JLang/JAbstractObjectStatus.hh
"
10
11
12
/**
13
* \author mdejong
14
*/
15
16
namespace
JLANG
{}
17
namespace
JPP
{
using namespace
JLANG
; }
18
19
namespace
JLANG
{
20
21
22
/**
23
* This class can be used to temporarily redirect an input stream to an input string.
24
* The destructor restores the internal buffer of the input stream.
25
*/
26
class
JRedirectString
:
27
public
JAbstractObjectStatus
28
{
29
public
:
30
/**
31
* Constructor.
32
* The input stream is redirected to the given input string.
33
*
34
* \param is input stream
35
* \param buffer input string
36
*/
37
JRedirectString
(std::istream& is,
const
std::string& buffer) :
38
ios
(is)
39
{
40
p
=
ios
.rdbuf(
new
std::stringbuf(buffer));
41
}
42
43
44
/**
45
* Destructor.
46
* Restore internal buffer and delete temporary buffer.
47
*/
48
~JRedirectString
()
49
{
50
delete
ios
.rdbuf(
p
);
51
}
52
53
54
/**
55
* Get status of object.
56
*
57
* \return true
58
*/
59
virtual
bool
getStatus
()
const
60
{
61
return
true
;
62
}
63
64
private
:
65
std::ios&
ios
;
66
std::streambuf*
p
;
67
};
68
}
69
70
#endif
JLANG::JRedirectString::ios
std::ios & ios
Definition:
JRedirectString.hh:65
JLANG::JAbstractObjectStatus
Interface for status of object.
Definition:
JAbstractObjectStatus.hh:19
JLANG::JRedirectString::JRedirectString
JRedirectString(std::istream &is, const std::string &buffer)
Constructor.
Definition:
JRedirectString.hh:37
JLANG::JRedirectString::p
std::streambuf * p
Definition:
JRedirectString.hh:66
JLANG::JRedirectString::~JRedirectString
~JRedirectString()
Destructor.
Definition:
JRedirectString.hh:48
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition:
JAAnetToolkit.hh:37
JLANG::JRedirectString
This class can be used to temporarily redirect an input stream to an input string.
Definition:
JRedirectString.hh:26
JAbstractObjectStatus.hh
JLANG::JRedirectString::getStatus
virtual bool getStatus() const
Get status of object.
Definition:
JRedirectString.hh:59
JLANG
Auxiliary classes and methods for language specific functionality.
Definition:
JAbstractClass.hh:10
Generated by
1.8.16