Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
void load()
Load data from file with name corresponding to current contents.
This class can be used to temporarily exchange the states between streams.
Definition: JStreamState.hh:23
JStringStream(std::istream &in)
Constructor.
Wrapper class around STL stringstream class to facilitate optional loading of data from file...
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:38