Jpp
software
JLang
JStringStream.hh
Go to the documentation of this file.
1
#ifndef __JLANG__JSTRINGSTREAM__
2
#define __JLANG__JSTRINGSTREAM__
3
4
#include <sstream>
5
#include <fstream>
6
7
#include "
JLang/JStreamState.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
* Wrapper class around STL stringstream class to facilitate optional loading of data from file.
21
*/
22
class
JStringStream
:
23
public
std::stringstream,
24
public
JStreamState
25
{
26
public
:
27
/**
28
* Constructor.
29
*
30
* This constructor loads all data from given input stream.
31
*
32
* \param in input stream
33
*/
34
JStringStream
(std::istream& in) :
35
std
::stringstream(),
36
JStreamState
(in, static_cast<
std
::istream&>(*this))
37
{
38
(*this) << in.rdbuf();
39
}
40
41
42
/**
43
* Load data from file with name corresponding to current contents.
44
*
45
* Note that if the file exists but is empty,
46
* the state of the stream is set to fail by C++ standard.
47
*/
48
void
load
()
49
{
50
using namespace
std
;
51
52
ifstream in(this->str().c_str());
53
54
if
(in) {
55
56
this->str(
""
);
// reset
57
58
(*this) << in.rdbuf();
// copy
59
60
in.close();
61
}
62
}
63
};
64
}
65
66
#endif
JLANG::JStreamState
This class can be used to temporarily exchange the states between streams.
Definition:
JStreamState.hh:23
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition:
JAAnetToolkit.hh:37
JStreamState.hh
JLANG::JStringStream::load
void load()
Load data from file with name corresponding to current contents.
Definition:
JStringStream.hh:48
JLANG::JStringStream::JStringStream
JStringStream(std::istream &in)
Constructor.
Definition:
JStringStream.hh:34
std
Definition:
jaanetDictionary.h:36
JLANG::JStringStream
Wrapper class around STL stringstream class to facilitate optional loading of data from file.
Definition:
JStringStream.hh:22
JLANG
Auxiliary classes and methods for language specific functionality.
Definition:
JAbstractClass.hh:10
Generated by
1.8.16