Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
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
10
11
12/**
13 * \author mdejong
14 */
15
16namespace JLANG {}
17namespace JPP { using namespace JLANG; }
18
19namespace 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 */
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 */
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 override
60 {
61 return true;
62 }
63
64 private:
65 std::ios& ios;
66 std::streambuf* p;
67
72 };
73}
74
75#endif
This class can be used to temporarily redirect an input stream to an input string.
JRedirectString(std::istream &is, const std::string &buffer)
Constructor.
virtual bool getStatus() const override
Get status of object.
JRedirectString(JRedirectString &&)
JRedirectString(const JRedirectString &)
JRedirectString & operator=(const JRedirectString &)
JRedirectString & operator=(JRedirectString &&)
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.