Jpp 21.0.0
the software that should make you happy
Loading...
Searching...
No Matches
JLANG::JStringStream Class Reference

Wrapper class around STL stringstream class to facilitate optional loading of data from file. More...

#include <JStringStream.hh>

Inheritance diagram for JLANG::JStringStream:
JLANG::JStreamState

Public Member Functions

 JStringStream (std::istream &in)
 Constructor.
 
void load ()
 Load data from file with name corresponding to current contents.
 

Private Attributes

std::ios & __from
 
std::ios & __to
 

Detailed Description

Wrapper class around STL stringstream class to facilitate optional loading of data from file.

Definition at line 23 of file JStringStream.hh.

Constructor & Destructor Documentation

◆ JStringStream()

JLANG::JStringStream::JStringStream ( std::istream & in)
inline

Constructor.

This constructor loads all data from given input stream.

Parameters
ininput stream

Definition at line 35 of file JStringStream.hh.

35 :
36 std::stringstream(),
37 JStreamState(in, static_cast<std::istream&>(*this))
38 {
39 using namespace std;
40
41 istream::sentry sentry(in); // skips white spaces
42
43 if (sentry) {
44
45 static_cast<stringstream&>(*this) << in.rdbuf(); // copy
46
47 error_code error;
48
49 if (filesystem::is_regular_file(this->str(), error)) {
50 this->load();
51 }
52 }
53 }
JStreamState(std::ostream &from, std::ostream &to)
Constructor.
void load()
Load data from file with name corresponding to current contents.

Member Function Documentation

◆ load()

void JLANG::JStringStream::load ( )
inline

Load data from file with name corresponding to current contents.

Note that if the file exists but is empty, the state of the stream is set to fail by C++ standard.

Definition at line 62 of file JStringStream.hh.

63 {
64 using namespace std;
65
66 ifstream in(this->str().c_str());
67
68 if (in) {
69
70 this->str(""); // reset
71
72 static_cast<stringstream&>(*this) << in.rdbuf(); // copy
73
74 in.close();
75 }
76 }

Member Data Documentation

◆ __from

std::ios& JLANG::JStreamState::__from
privateinherited

Definition at line 67 of file JStreamState.hh.

◆ __to

std::ios& JLANG::JStreamState::__to
privateinherited

Definition at line 68 of file JStreamState.hh.


The documentation for this class was generated from the following file: